sanic-ext
sanic-ext copied to clipboard
Complete OpenAPI Spec in signatures
Describe the bug
Missed the possibility to point out allowed values of path or query string parameters in sanic-ext openapi decorator.
I remember it was possible when openapi docs were settled with @doc
decorator. But in @openapi.parameter
I don't see any possible keys to set such values. Key kwargs
decieves me in this case.
Expected behavior
For example I have a parameter which shall accept an int
in range from 0
to 2
.
I'd like to point it out in swagger and to make this field accept not any input, but only preset choices: 0
, 1
and 2
.
So I expect to find in @openapi.parameter
a key like allowed_values
or something like that:
@openapi.parameter(..., allowed_values=list(range(3)))
Additional question
Is it possible to make swagger fields to be dependant from the value set in other fields?
For example I have a field device
with allowed values screen
, phone
, tablet
and a field size
.
Each kind of device has its correspondent range of sizes, e.g.: screens: 15''-40'', phone: 5''-8'', tablets: 9''-15''.
Depending on the device
value field size
shall allow in swagger to choose any size from the correspondent range.
Is it possible?
FOUND SOLUTION!
Finally I found out how it really works, and I think it must be added to documentation.
So, if we want to add some default choices to @openapi.parameter
we shall create a Enum
with our choices as values and pass this Enum
as follows:
my_enum = enum.Enum('schema', [('1', 'choice1'), ('2', 'choice2')])
@openapi.parameter(schema=my_enum)
And we'll get correct json.
@ahopkins, I think this issue can be closed and documentation shall be added with this info.
Documentation, yes! But I want to leave it because it points to a larger issue in needing to update the API to make it more intuitive.
You're the boss))