File tree Expand file tree Collapse file tree
openapi-processor-core/src
main/kotlin/io/openapiprocessor/core
test/kotlin/io/openapiprocessor/core/converter Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -423,7 +423,8 @@ class ApiConverter(
423423 val parameters = mutableListOf<ModelParameter >()
424424 dataTypes.relRef(dataType.getName())
425425 dataType.forEach { property, propertyDataType ->
426- parameters.add(framework.createQueryParameter(UrlencodedParameter (property), propertyDataType))
426+ parameters.add(framework.createQueryParameter(UrlencodedParameter (
427+ property, dataType.constraints?.isRequired(property) == true ), propertyDataType))
427428 }
428429 return parameters
429430 }
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import io.openapiprocessor.core.openapi.Schema
1111/* *
1212 * "fake" parameter for framework-specific annotation selection
1313 */
14- class UrlencodedParameter (val parameter : String ): Parameter {
14+ class UrlencodedParameter (val parameter : String , private val required : Boolean = false ): Parameter {
1515
1616 override fun getIn (): String {
1717 return " urlencoded"
@@ -26,7 +26,7 @@ class UrlencodedParameter(val parameter: String): Parameter {
2626 }
2727
2828 override fun isRequired (): Boolean {
29- return true
29+ return required
3030 }
3131
3232 override fun isDeprecated (): Boolean {
Original file line number Diff line number Diff line change @@ -302,6 +302,52 @@ class ApiConverterRequestBodySpec: StringSpec({
302302 bar.name shouldBe " bar"
303303 }
304304
305+ " converts request body application/x-www-form-urlencoded object schema properties to rrequired/not required request parameters" {
306+ val options = parseOptions(options = """
307+ |options:
308+ | bean-validations: true
309+ """)
310+
311+ val openApi = parseApiBody("""
312+ paths:
313+ /foo:
314+ post:
315+ requestBody:
316+ required: true
317+ content:
318+ application/x-www-form-urlencoded:
319+ schema:
320+ type: object
321+ required:
322+ - foo
323+ properties:
324+ foo:
325+ type: string
326+ bar:
327+ type: boolean
328+ responses:
329+ '204':
330+ description: empty
331+ """)
332+
333+ val api = apiConverter(options).convert(openApi)
334+
335+ val itf = api.getInterfaces().first()
336+ val ep = itf.endpoints.first()
337+ val foo = ep.parameters[0 ]
338+ val bar = ep.parameters[1 ]
339+
340+ foo.dataType.getName() shouldBe " string"
341+ foo.dataType.getTypeName() shouldBe " String"
342+ foo.required.shouldBeTrue()
343+ foo.name shouldBe " foo"
344+
345+ bar.dataType.getName() shouldBe " boolean"
346+ bar.dataType.getTypeName() shouldBe " Boolean"
347+ bar.required.shouldBeFalse()
348+ bar.name shouldBe " bar"
349+ }
350+
305351 " converts request body application/x-www-form-urlencoded object to request parameter" {
306352 val options = parseOptions(mapping =
307353 """
You can’t perform that action at this time.
0 commit comments