-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
changeSuggested alteration to Pydantic, not a new feature nor a bugSuggested alteration to Pydantic, not a new feature nor a bug
Milestone
Description
Multi-value Literal returns const in the JSON sub-schema of an anyOf, which isn't supported by OpenAPI:
anyOf – the subschemas must be OpenAPI schemas and not standard JSON Schemas.
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":
pydantic version: 1.4
pydantic compiled: False
install path: /Users/[...]/venv/lib/python3.7/site-packages/pydantic
python version: 3.7.4 (default, Sep 7 2019, 18:27:02) [Clang 10.0.1 (clang-1001.0.46.4)]
platform: Darwin-18.7.0-x86_64-i386-64bit
optional deps. installed: ['typing-extensions']
Code to reproduce
from pydantic import BaseModel
from typing_extensions import Literal
class FooBar(BaseModel):
values: Literal["value_1", "value_2"]
print(FooBar.schema_json(indent=2))output:
{
"title": "FooBar",
"type": "object",
"properties": {
"values": {
"title": "Values",
"anyOf": [
{
"const": "value_1",
"type": "string"
},
{
"const": "value_2",
"type": "string"
}
]
}
},
"required": [
"values"
]
}
Literal with only one value is OpenAPI compliant btw
This issue is linked to: fastapi/fastapi#562, #649 (the simple enum would work well)
NixBiks
Metadata
Metadata
Assignees
Labels
changeSuggested alteration to Pydantic, not a new feature nor a bugSuggested alteration to Pydantic, not a new feature nor a bug