Replies: 7 comments
-
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. |
Beta Was this translation helpful? Give feedback.
-
I've pushed on my fork a branch that tries to help on this (https://github.com/euri10/fastapi/tree/display_pydantic_types) I used 2 models, Working and Failing:
the I guess most errors come from upstream in pydantic schema generation, just hope this branch helps in figuring out what types may cause issues, pydantic schema is a rather impressive topic to jump in 💥 🙀 , not sure I would not where to look at ! 🐙 |
Beta Was this translation helpful? Give feedback.
-
Yeah, Pydantic internals are quite heavy. It even uses undocumented Python features. I'll check it there with your examples to see where I did something wrong. |
Beta Was this translation helpful? Give feedback.
-
I hit this as well, both for Unions and Enum. Here is the simple reproduction for Enum: from enum import Enum
from fastapi import FastAPI
from pydantic import BaseModel
class ModelName(Enum):
alexnet = "alexnet"
resnet = "resnet"
lenet = "lenet"
class Model(BaseModel):
size: int
name: ModelName
app = FastAPI()
@app.post("/")
def post(model: Model):
pass And the docs miss the Workaround for Enum - inherit it from
|
Beta Was this translation helpful? Give feedback.
-
I just realized I replied in the PR but not here. Let me copy some sections from there: The way to use an enum would be like: class MyEnum(Enum):
a = "foo"
b = "bar" and then: my_enum: MyEnum @haizaar about enums with But is good to know there's a workaround for the API docs. Maybe we could use it in the FastAPI docs examples. On the other side, about |
Beta Was this translation helpful? Give feedback.
-
I just encountered this one today too with a Are there any workarounds for getting a Thanks so much |
Beta Was this translation helpful? Give feedback.
-
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 swagger-api/swagger-ui#4819 and swagger-api/swagger-ui#3803 I guess we'll need to wait for this to be fixed upstream 😄 Cheers |
Beta Was this translation helpful? Give feedback.
-
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:
add this route:
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 :)
Beta Was this translation helpful? Give feedback.
All reactions