-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support openapi specification for Tuple fields #3210
Comments
Something worth noting is that the |
Also just ran into this.
Suggestion: I think, without having to use anything specific to OpenAPI 3.1+, we can at least make it an valid schema by making use of The following change to https://github.com/samuelcolvin/pydantic/blob/4be3f45e20e6f3652572896fee062f44e1ff4ae5/pydantic/schema.py#L508 does this: else:
- f_schema = {'type': 'array', 'items': sub_schema}
+ f_schema = {'type': 'array', 'items': { 'oneOf': sub_schema }, 'minItems': len(sub_schema), 'maxItems': len(sub_schema) }
if field.shape == SHAPE_GENERIC: Then we get |
This should be solved in V2. |
Checks
Bug
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:When creating openapi schemas,
BaseModel
fields that areTuple
are indistinguishable fromList
instances. This is despite the fact that the openapi specification now supports fixed-length lists (i.e. tuple-like).Specifically, the following here is true:
This leads to an issue with the openapi specification generated by fastapi, in which the swagger can not correctly render the content of
Tuple
members, as referenced in these issues tiangolo/fastapi#3665 and tiangolo/fastapi#3782, and this pull request tiangolo/fastapi#3874Suggestion
I think that it would make sense to support the openAPI specification for
Tuple
types, as a result, the specification of theTupleModel
would change fromto
Where, each field of the
Tuple
is specified by an entry inprefixItems
(see the docs). In itself, this would allow extra arguments to the list, thus the fixed length nature of theTuple
is reflected byitems
being set tofalse
(see here).I have created a branch (https://github.com/victorbenichoux/pydantic/tree/fix-tuple) to implement this specification.
The text was updated successfully, but these errors were encountered: