[BUG] docs don't show nested enum attribute for body
See original GitHub issueDescribe the bug I have a post method with the body as pydantic object, with one attribute as Enum object; All validation works perfectly; However, two independent (?) issues occur:
- complaint.dict() generates a dictionary - but does not flatten nested enum object into string. I am getting this is beyound the idea of
dict()
, but would be nice to have something that flattens the whole entity; complaint_type
attribute does not show up on the swagger
To Reproduce example coe snippet:
class ComplaintType(Enum):
other = 'other'
commercial = "commercial"
house = "house"
park = "park"
residential = "residential"
street = "street"
vehicle = "vehicle"
class Complaint(BaseModel):
complaint_type:ComplaintType
timestamp:datetime = datetime.now()
lat:float
lon:float
description:str
Expected behavior I expected
- complaint_type to be on a swagger and in the schema as (I guess) “oneOf” element
- be able to flatten Pydantic object into a fully json-able dictionary (converting enum objects into strings)
Environment:
- OS: macOS
- FastAPI Version 0.30.0
- Python version 3,7.3
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Nested enum is static? - java - Stack Overflow
Your enum declaration is not static, it is top-level, and top-level classes cannot be static. Constant bodies define an implicit nested anonymous subclass...
Read more >Enums - Swagger
Enums. You can use the enum keyword to specify possible values of a request parameter or a model property. For example, the sort...
Read more >Enums - C# language specification - Microsoft Learn
An enum declaration cannot include a type parameter list, but any enum nested inside a generic class declaration or a generic struct ...
Read more >Handbook - Enums - TypeScript
In this generated code, an enum is compiled into an object that stores both forward ( name -> value ) and reverse (...
Read more >Defining an Enum - The Rust Programming Language - MIT
That property of IP addresses makes the enum data structure appropriate for this case, because enum values can only be one of the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Can you test whether this fixes it:
This works for me and correctly shows in SwaggerDocs. In your case, you’ve specified type
Enum
but not which type for Enum (looks like itsstr
, too).Thank you both! That makes a lot of sense - somehow I never used Enum before, so - good to know!