-
|
Describe the bug OAI/OpenAPI-Specification#1026 (comment) There should be some way to properly degrade this. To Reproduce
class Test(BaseModel): app = FastAPI() @app.get("/", response_model=Tuple[bool,Test])
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
|
here is a copy of the test case for reference. |
Beta Was this translation helpful? Give feedback.
-
|
@toppk |
Beta Was this translation helpful? Give feedback.
-
|
@toppk The closest you can get with the openapi spec is probably equivalent to what is (or should be) generated by: from pydantic import conlist
@app.get("/", response_model=conlist(Union[bool,Test], min_items=2, max_items=2))(Note: I don't think this is actually generating the complete openapi schema properly; the min/max items count is not specified and I'm not exactly sure why.) But given the weak support for tuple in openapi spec, 1) I'm not sure it makes sense for FastAPI to support this, and 2) I would strongly preference creating a model for your response with named fields, rather than returning a tuple. If you are creating the server it seems like this should be within your control (unless you have backwards compatibility requirements). |
Beta Was this translation helpful? Give feedback.
-
|
@toppk as @dmontagu , tuples with exact values inside are explicitly unsupported by OpenAPI (there are notes stating that in the spec). So, yeah, I think the best you can do is something like what @dmontagu suggests. Or better, if you can, make it a Pydantic model with 2 fields. It would also probably be a lot easier to use for your API users. |
Beta Was this translation helpful? Give feedback.
-
|
Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues. |
Beta Was this translation helpful? Give feedback.
@toppk as @dmontagu , tuples with exact values inside are explicitly unsupported by OpenAPI (there are notes stating that in the spec).
So, yeah, I think the best you can do is something like what @dmontagu suggests. Or better, if you can, make it a Pydantic model with 2 fields. It would also probably be a lot easier to use for your API users.