Identical duplicated schemas in openapi.json #14288
Unanswered
marwan-alloreview
asked this question in
Questions
Replies: 1 comment 6 replies
-
|
This happens because FastAPI (with Pydantic v2) now creates separate input and output schemas in the generated OpenAPI spec. Even if you only define one model, FastAPI splits it into User-Input and User-Output so that it can describe small differences between request and response — like optional fields, default values, or readOnly / writeOnly behavior in JSON Schema. If you’d like to keep just one schema for both, you can set this option when creating your app: app = FastAPI(separate_input_output_schemas=False)That will make FastAPI generate a single schema instead of two. Reference: https://fastapi.tiangolo.com/how-to/separate-openapi-schemas/?h=#do-not-separate-schemas |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
Hello 👋
In the provided code example, there is no default value for
User,ConfigorItemmodels so I would not expect any-Inputor-Output"schemas in openapi.json, but I do getUser-InputandUser-Outputschemas, which are identical :{ // ... "components": { "schemas": { "Config": { "properties": { "item": { "$ref": "#/components/schemas/Item" } }, "type": "object", "required": [ "item" ], "title": "Config" }, "Item": { "properties": { "name": { "type": "string", "title": "Name" } }, "type": "object", "required": [ "name" ], "title": "Item" }, "User-Input": { "properties": { "config": { "$ref": "#/components/schemas/Config" } }, "type": "object", "required": [ "config" ], "title": "User" }, "User-Output": { "properties": { "config": { "$ref": "#/components/schemas/Config" } }, "type": "object", "required": [ "config" ], "title": "User" } } } }Any Idea what could cause that ? Thanks a lot !
Operating System
macOS
Operating System Details
No response
FastAPI Version
0.121.0
Pydantic Version
2.12.3
Python Version
3.13.3
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions