🎨 Auto format

This commit is contained in:
pre-commit-ci-lite[bot] 2025-12-15 01:05:56 +00:00 committed by GitHub
parent 926f334a62
commit a63fc91182
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 31 additions and 75 deletions

View File

@ -5,9 +5,8 @@ See https://github.com/fastapi/fastapi/pull/14463
""" """
from fastapi import FastAPI from fastapi import FastAPI
from pydantic import BaseModel
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from pydantic import BaseModel
class ModelA(BaseModel): class ModelA(BaseModel):
@ -21,21 +20,19 @@ class ModelB(BaseModel):
app = FastAPI( app = FastAPI(
responses={ responses={
500: { 500: {
'model': ModelA | ModelB, "model": ModelA | ModelB,
'content': {"application/json": { "content": {"application/json": {"examples": {"Case A": {"value": "a"}}}},
'examples': {"Case A": {"value": "a"}}
}}
} }
} }
) )
@app.get('/route1') @app.get("/route1")
def route1(): def route1():
return "test" return "test"
@app.get('/route2') @app.get("/route2")
def route2(): def route2():
return "test" return "test"
@ -48,10 +45,7 @@ def test_openapi_schema():
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == { assert response.json() == {
"openapi": "3.1.0", "openapi": "3.1.0",
"info": { "info": {"title": "FastAPI", "version": "0.1.0"},
"title": "FastAPI",
"version": "0.1.0"
},
"paths": { "paths": {
"/route1": { "/route1": {
"get": { "get": {
@ -60,11 +54,7 @@ def test_openapi_schema():
"responses": { "responses": {
"200": { "200": {
"description": "Successful Response", "description": "Successful Response",
"content": { "content": {"application/json": {"schema": {}}},
"application/json": {
"schema": {}
}
}
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
@ -72,24 +62,16 @@ def test_openapi_schema():
"application/json": { "application/json": {
"schema": { "schema": {
"anyOf": [ "anyOf": [
{ {"$ref": "#/components/schemas/ModelA"},
"$ref": "#/components/schemas/ModelA" {"$ref": "#/components/schemas/ModelB"},
},
{
"$ref": "#/components/schemas/ModelB"
}
], ],
"title": "Response 500 Route1 Route1 Get" "title": "Response 500 Route1 Route1 Get",
}, },
"examples": { "examples": {"Case A": {"value": "a"}},
"Case A": {
"value": "a"
}
}
} }
} },
} },
} },
} }
}, },
"/route2": { "/route2": {
@ -99,11 +81,7 @@ def test_openapi_schema():
"responses": { "responses": {
"200": { "200": {
"description": "Successful Response", "description": "Successful Response",
"content": { "content": {"application/json": {"schema": {}}},
"application/json": {
"schema": {}
}
}
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
@ -111,55 +89,33 @@ def test_openapi_schema():
"application/json": { "application/json": {
"schema": { "schema": {
"anyOf": [ "anyOf": [
{ {"$ref": "#/components/schemas/ModelA"},
"$ref": "#/components/schemas/ModelA" {"$ref": "#/components/schemas/ModelB"},
},
{
"$ref": "#/components/schemas/ModelB"
}
], ],
"title": "Response 500 Route2 Route2 Get" "title": "Response 500 Route2 Route2 Get",
}, },
"examples": { "examples": {"Case A": {"value": "a"}},
"Case A": {
"value": "a"
}
}
} }
} },
} },
} },
} }
} },
}, },
"components": { "components": {
"schemas": { "schemas": {
"ModelA": { "ModelA": {
"properties": { "properties": {"a": {"type": "string", "title": "A"}},
"a": {
"type": "string",
"title": "A"
}
},
"type": "object", "type": "object",
"required": [ "required": ["a"],
"a" "title": "ModelA",
],
"title": "ModelA"
}, },
"ModelB": { "ModelB": {
"properties": { "properties": {"b": {"type": "string", "title": "B"}},
"b": {
"type": "string",
"title": "B"
}
},
"type": "object", "type": "object",
"required": [ "required": ["b"],
"b" "title": "ModelB",
], },
"title": "ModelB"
}
} }
} },
} }