1 year ago
#356155
lucek091
Swagger 2.0 x-www-form-urlencoded
I would like to define an endpoint using swagger 2.0 that consumes application/x-www-form-urlencoded .
The passed parameters can have different names and be of different types. How should I define this in the yaml? I am playing with this the whole day and cannot figure it out. Everything I've found in the documentation is that I have to use 'parameters' but I don't know how to resolve the random number of parameters and their names.
As an example, I would like both queries to work:
First curl:
curl --location --request POST 'https://localhost:8080/contact/123456789' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'name=random value' \
--data-urlencode 'Email=randomValue' \
--data-urlencode 'address=random' \
--data-urlencode 'surname2=123' \
--data-urlencode 'surname=random'
Second curl:
curl --location --request POST 'https://localhost:8080/contact/123456789' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'car=bmw' \
--data-urlencode 'house=small'
And invalid YAML - but I cannot figure out how to solve my issue.
paths:
/contact/{phone}:
post:
consumes:
- application/x-www-form-urlencoded
produces:
- application/json
parameters:
- in: formData
name: form_data
description: Body for submitting the contact
required: false
type: string
- in: path
name: phone
description: phone number
required: true
type: string
Could you assist me?
swagger
swagger-ui
swagger-2.0
0 Answers
Your Answer