question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION] fastapi issue of swagger display ?

See original GitHub issue

Description

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:

Imgur

Now if I put them commented they are in the Edit section: Imgur

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:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
tiangolocommented, Mar 27, 2019

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.

1reaction
fgimiancommented, Oct 9, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - FastAPI swagger does not render because of custom ...
Got a solution to fix 1 part of the problem by Chris, but the swagger wasn't still loading. The code was hung up...
Read more >
Release Notes - FastAPI
This handles a security issue in Swagger UI itself where it could be possible ... as it's currently broken, and Gitter's response doesn't...
Read more >
Swagger UI tutorial | Documenting APIs - Idratherbewriting.com
Swagger UI provides a display framework that reads an OpenAPI ... Troubleshooting issues with Swagger UI; Embedding Swagger UI within an ...
Read more >
[FastAPI - Swagger UI] Blank Page - SmartBear Community
I follow instructions of FastAPI and when I input ... [FastAPI - Swagger UI] Blank Page ... I'm also experiencing the same issue....
Read more >
Using FastAPI to Build Python Web APIs - Real Python
In this guide, you'll learn the main concepts of FastAPI and how to use it to quickly ... the interactive documentation with Swagger...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found