Closed guillaume-alvarez closed 2 months ago
OpenAPI and pydantic have completely different definitions for examples, so they can't be mixed.
OpenAPI-Parameter Object:
Pydantic-Field:
In fact, Flask-openapi3 already supports customizing the examples
field, please refer to the documentation.
Thanks for the explanation.
Environment:
/!\ This issue is similar to https://github.com/luolingchun/flask-openapi3/issues/176 but this time for a model used in a query
Warning
If I define a model setting
Field.example
(not defined in pydantic):then it causes warnings because it is not officially supported by pydantic:
Crash
If I define a model setting the
Field.examples
as advised by pydantic:Then it crashes the application:
This field was added in pydantic 2.5.0 by https://github.com/pydantic/pydantic/pull/8013
Debugging the code I see that
flask_openapi3.utils.parse_query
will try to parse the examples value as anOptional[Dict[str, Union[Example, Reference]]]
, which seems in line with the OpenAPI 3.1.0 spec. Maybe some conversion could be made inflask_openapi3.utils.parse_query
to support a list[str] example that is valid in pydantic?