@@ -31,7 +31,6 @@ import io.openapiprocessor.core.model.Response as ModelResponse
3131import io.openapiprocessor.core.model.parameters.Parameter as ModelParameter
3232
3333const val MULTIPART = " multipart/"
34- const val URLENCODED = " application/x-www-form-urlencoded"
3534const 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 }
0 commit comments