required parameters set as false aren't viewed as valid
Reaster0 opened this issue · 3 comments
hi, when i set a parameter to a route i need to set the "required" state, the issue is that the extension see as valid only a "required" field set to true, if set to false i get an error and can't visualise the openapi doc,
i need to set this field in any case because it's mandatory
thanks for you time
Hi @Reaster0 !
so what's the issue here? According to the spec, you have to set required to true for path parameters: https://spec.openapis.org/oas/v3.0.3#parameter-locations
yeah indeed the documentation is clear,
but i really don't understand the limitation here,
"required: Determines whether this parameter is mandatory. If the parameter location is "path", this property is REQUIRED and its value MUST be true. Otherwise, the property MAY be included and its default value is false."
why couldn't i have non mandatory parameters in the url?
also using swagger i can render my openapi file without issues, is it because it's based on a older revision of openapi or is because he don't follow strictly the guidelines here?
This boils down to how the parameters are used. Parameters in OpenAPI can occur in different places, take for example the query parameters - you could have an operation which looks like this:
GET /customers
Which would return some customer data. It could have a query parameter, 'count' which would specify max number of customers to return in the response.
It's easy to see how an http request would look like with and without this parameter:
GET http://server.com/customers?count=100
and GET http://server.com/customers
But the query parameters are different, say you're getting a particular page of some search results:
GET /search/{page}
If you were to make page
optional, your requests will look very different with regards of the path:
GET http://server.com/search/5
and GET http://server.com/search
And you must remember, that in OpenAPI operations reside inside of the paths, so optional path parameters will make the spec very ambiguous.
Therefore, it's written down in the OpenAPI specification that if you're using path parameters they MUST be mandatory.
Hope this helps.