You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optional types in query parameters don't seem to play well with OpenAPI, resulting in a bad schema, except that upon some more testing if there is more than one non-None type in the annotation it works.
A query parameter annotated int | None produces incorrectly:
Additionally, optional types are being assumed to be optional parameters, resulting in "required": false regardless of whether the parameter has a default value or not.
And finally, route return types that are optional are mostly correct, but for some reason include an empty node (e.g. { "oneOf": [ { "type": "null" }, { "type": "integer" }, {} }). This results in /schema/redoc including a possible type of Any.
To Reproduce
(I ran this on 3.11, but IIRC 3.8+ for | None should work. I also tried with Optional and got the same results.)
Describe the bug
A query parameter annotated
int | None
produces incorrectly:While one annotated
int | str | date | None
produces correctly:Additionally, optional types are being assumed to be optional parameters, resulting in
"required": false
regardless of whether the parameter has a default value or not.And finally, route return types that are optional are mostly correct, but for some reason include an empty node (e.g.
{ "oneOf": [ { "type": "null" }, { "type": "integer" }, {} }
). This results in/schema/redoc
including a possible type ofAny
.To Reproduce
(I ran this on 3.11, but IIRC 3.8+ for
| None
should work. I also tried withOptional
and got the same results.)As a minimal example:
Check the generated schema below, or by running
uvicorn starlite_optionals:app
and navigating to http://127.0.0.1:8000/schema/openapi.json and/or http://127.0.0.1:8000/schema/.Generated OpenAPI schema.
The text was updated successfully, but these errors were encountered: