I'm creating a #definition in Swagger 2.0 for an OAuth JSON payload. grant_type
is required, but must be a specific value (password
).
How can I tell Swagger that the value of this property must be equal to password
?
definitions:
TokenRequest:
required:
- userId
- password
- grant_type
properties:
userId:
type: string
password:
type: string
grant_type:
# here we need to describe that it must = 'password'
Strictly speaking, you would it define it like this:
definitions:
TokenRequest:
required:
- userId
- password
- grant_type
properties:
userId:
type: string
password:
type: string
grant_type:
type: string
enum:
- password
However, you should know that Swagger 2.0 has specific section to specify security attributes for your application, including the OAuth2 password flow. You can then set it globally for your API and override it if needed per operation. Alternatively, you can just declare it per operation.
For more information on it:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With