[QUESTION] fastapi issue of swagger display ?
See original GitHub issueDescription
I have a pydantic model with Enum and Union parameters, and while they both appear in Schema, in a post route they are not displayed in the Example edit section. I hesitated to file a bug but I;d prefer to ask if that’s something that’s feasible first.
I was surprised and made a small exercice, take this model:
class DisplayMe(BaseModel):
my_bool: bool
my_float: float
my_str: str
my_int: int
my_dict: dict
# my_list: list
# my_tuple: tuple
# my_set: set
# my_List_str: List[str]
# my_tuple_str_int: Tuple[str, int]
# my_dict_str_int: Dict[str, int]
# my_union_str_int: Union[str, int]
# my_enum: Enum
my_emailstr: EmailStr
my_name_email: NameEmail
my_urlstr: UrlStr
my_dsn: DSN
my_bytes: bytes
my_decimal: Decimal
my_uuid1: UUID1
my_uuid3: UUID3
my_uuid4: UUID4
my_uuid5: UUID5
my_uuid: UUID
my_filepath: FilePath
my_directorypath: DirectoryPath
my_path: Path
my_datetime: datetime
my_date: date
add this route:
@router.post("/testypes")
async def types(tt: DisplayMe):
return tt
should you uncomment any of the pydantic types commented in the DisplayMe
model above, then the Edit section is empty, there’s nothing to edit.
But I can see them in schema, for instance on the below screen my_tuple
is visible in the Schema:
Now if I put them commented they are in the Edit section:
question is : is it possible to have the commented pydantic types in the swagger edit section, I’m mostyl interested in Union and Enum in fact 😃
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (5 by maintainers)
Sorry for the delay.
In fact, some of those types are generating errors.
I’ll check this more thoroughly as it seems there’s a bug in Pydantic to solve (which I probably introduced there while implementing all the JSON Schema stuff).
If you are curious, I create the API with your code, then I check the raw JSON OpenAPI endpoint, then I copy it and paste it here: https://editor.swagger.io, there I can debug it and see all the errors. You can check that if you want to see what is the actual problem in the generated schemas.
After a little more digging, I can see that FastAPI is doing the right thing here (the OpenAPI JSOn generated is correct). The problem seems to be on swagger-ui’s end. Some related issues are https://github.com/swagger-api/swagger-ui/issues/4819 and https://github.com/swagger-api/swagger-ui/issues/3803
I guess we’ll need to wait for this to be fixed upstream 😄
Cheers Fotis