Skip to content

Commit 2315b5c

Browse files
committed
1 parent 9f21443 commit 2315b5c

4 files changed

Lines changed: 25 additions & 15 deletions

File tree

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/converter/ApiConverter.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import io.openapiprocessor.core.model.Response as ModelResponse
3131
import io.openapiprocessor.core.model.parameters.Parameter as ModelParameter
3232

3333
const val MULTIPART = "multipart/"
34-
const val URLENCODED = "application/x-www-form-urlencoded"
3534
const val INTERFACE_DEFAULT_NAME = ""
3635

3736
/**
@@ -242,19 +241,26 @@ class ApiConverter(
242241
params.addAll(createMultipartParameter(info, mediaType.encodings, ctx.dataTypes))
243242

244243
} else if (isUrlencoded(contentType)) {
245-
params.addAll(createUrlencodedParameter(info, requestBody, ctx.dataTypes))
246-
244+
if (isBodyStyleObject(info)) {
245+
bodies.add(createRequestBody(contentType, info, requestBody, ctx.dataTypes))
246+
} else {
247+
params.addAll(createUrlencodedParameter(info, requestBody, ctx.dataTypes))
248+
}
247249
} else {
248-
bodies.add (createRequestBody (contentType, info, requestBody, ctx.dataTypes))
250+
bodies.add(createRequestBody(contentType, info, requestBody, ctx.dataTypes))
249251
}
250252
}
251253

252254
return RequestBodies(bodies, params)
253255
}
254256

257+
private fun isBodyStyleObject(info: SchemaInfo): Boolean {
258+
return getBodyStyle(info.getPath(), info.getMethod()) == BodyStyle.OBJECT
259+
}
260+
255261
private fun isMultipart(contentType: String): Boolean = contentType.startsWith(MULTIPART)
256262

257-
private fun isUrlencoded(contentType: String): Boolean = contentType.startsWith(URLENCODED)
263+
private fun isUrlencoded(contentType: String): Boolean = contentType.startsWith(APPLICATION_FORM_URLENCODED)
258264

259265
private fun collectResponses(responses: Map<HttpStatus, Response>, ctx: ApiConverterContext): Map<ModelHttpStatus, List<ModelResponse>> {
260266
val resultResponses: MutableMap<HttpStatus, List<ModelResponse>> = mutableMapOf()
@@ -412,14 +418,9 @@ class ApiConverter(
412418
}
413419

414420
val parameters = mutableListOf<ModelParameter>()
415-
val bodyStyle = getBodyStyle(info.getPath(), info.getMethod())
416-
if (bodyStyle == BodyStyle.OBJECT) {
417-
parameters.add(framework.createQueryParameter(UrlencodedRequestBody(requestBody), dataType))
418-
} else {
419-
dataTypes.relRef(dataType.getName())
420-
dataType.forEach { property, propertyDataType ->
421-
parameters.add(framework.createQueryParameter(UrlencodedParameter(property), propertyDataType))
422-
}
421+
dataTypes.relRef(dataType.getName())
422+
dataType.forEach { property, propertyDataType ->
423+
parameters.add(framework.createQueryParameter(UrlencodedParameter(property), propertyDataType))
423424
}
424425
return parameters
425426
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* Copyright 2026 https://github.com/openapi-processor/openapi-processor-base
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.core.model
7+
8+
const val APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded"

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/model/RequestBody.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import io.openapiprocessor.core.model.parameters.ParameterBase
1111
/**
1212
* Endpoint request body properties.
1313
*/
14-
class RequestBody(
14+
open class RequestBody(
1515
name: String,
1616
val contentType: String,
1717
dataType: DataType,

openapi-processor-core/src/test/kotlin/io/openapiprocessor/core/converter/ApiConverterRequestBodySpec.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ class ApiConverterRequestBodySpec: StringSpec({
335335

336336
val itf = api.getInterfaces().first()
337337
val ep = itf.endpoints.first()
338-
val body = ep.parameters[0]
338+
ep.parameters.isEmpty()
339+
val body = ep.requestBodies.first()
339340

340341
body.dataType.getTypeName() shouldBe "FooPostRequestBody"
341342
body.name shouldBe "body"

0 commit comments

Comments
 (0)