|
|
@ -1,6 +1,7 @@ |
|
|
from fastapi import FastAPI |
|
|
from fastapi import FastAPI |
|
|
from fastapi.responses import JSONResponse |
|
|
from fastapi.responses import JSONResponse |
|
|
from fastapi.testclient import TestClient |
|
|
from fastapi.testclient import TestClient |
|
|
|
|
|
from inline_snapshot import snapshot |
|
|
from pydantic import BaseModel |
|
|
from pydantic import BaseModel |
|
|
|
|
|
|
|
|
app = FastAPI() |
|
|
app = FastAPI() |
|
|
@ -39,76 +40,78 @@ client = TestClient(app) |
|
|
def test_openapi_schema(): |
|
|
def test_openapi_schema(): |
|
|
response = client.get("/openapi.json") |
|
|
response = client.get("/openapi.json") |
|
|
assert response.status_code == 200, response.text |
|
|
assert response.status_code == 200, response.text |
|
|
assert response.json() == { |
|
|
assert response.json() == snapshot( |
|
|
"openapi": "3.1.0", |
|
|
{ |
|
|
"info": {"title": "FastAPI", "version": "0.1.0"}, |
|
|
"openapi": "3.1.0", |
|
|
"paths": { |
|
|
"info": {"title": "FastAPI", "version": "0.1.0"}, |
|
|
"/a": { |
|
|
"paths": { |
|
|
"get": { |
|
|
"/a": { |
|
|
"responses": { |
|
|
"get": { |
|
|
"500": { |
|
|
"responses": { |
|
|
"description": "Error", |
|
|
"500": { |
|
|
"content": { |
|
|
"description": "Error", |
|
|
"application/vnd.api+json": { |
|
|
"content": { |
|
|
"schema": { |
|
|
"application/vnd.api+json": { |
|
|
"$ref": "#/components/schemas/JsonApiError" |
|
|
"schema": { |
|
|
|
|
|
"$ref": "#/components/schemas/JsonApiError" |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
"200": { |
|
|
|
|
|
"description": "Successful Response", |
|
|
|
|
|
"content": {"application/vnd.api+json": {"schema": {}}}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
"200": { |
|
|
"summary": "A", |
|
|
"description": "Successful Response", |
|
|
"operationId": "a_a_get", |
|
|
"content": {"application/vnd.api+json": {"schema": {}}}, |
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
"/b": { |
|
|
|
|
|
"get": { |
|
|
|
|
|
"responses": { |
|
|
|
|
|
"500": { |
|
|
|
|
|
"description": "Error", |
|
|
|
|
|
"content": { |
|
|
|
|
|
"application/json": { |
|
|
|
|
|
"schema": {"$ref": "#/components/schemas/Error"} |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
"200": { |
|
|
|
|
|
"description": "Successful Response", |
|
|
|
|
|
"content": {"application/json": {"schema": {}}}, |
|
|
|
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
"summary": "B", |
|
|
"summary": "A", |
|
|
"operationId": "b_b_get", |
|
|
"operationId": "a_a_get", |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
"/b": { |
|
|
"components": { |
|
|
"get": { |
|
|
"schemas": { |
|
|
"responses": { |
|
|
"Error": { |
|
|
"500": { |
|
|
"title": "Error", |
|
|
"description": "Error", |
|
|
"required": ["status", "title"], |
|
|
"content": { |
|
|
"type": "object", |
|
|
"application/json": { |
|
|
"properties": { |
|
|
"schema": {"$ref": "#/components/schemas/Error"} |
|
|
"status": {"title": "Status", "type": "string"}, |
|
|
} |
|
|
"title": {"title": "Title", "type": "string"}, |
|
|
}, |
|
|
|
|
|
}, |
|
|
}, |
|
|
"200": { |
|
|
}, |
|
|
"description": "Successful Response", |
|
|
"JsonApiError": { |
|
|
"content": {"application/json": {"schema": {}}}, |
|
|
"title": "JsonApiError", |
|
|
|
|
|
"required": ["errors"], |
|
|
|
|
|
"type": "object", |
|
|
|
|
|
"properties": { |
|
|
|
|
|
"errors": { |
|
|
|
|
|
"title": "Errors", |
|
|
|
|
|
"type": "array", |
|
|
|
|
|
"items": {"$ref": "#/components/schemas/Error"}, |
|
|
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
"summary": "B", |
|
|
|
|
|
"operationId": "b_b_get", |
|
|
|
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
} |
|
|
"components": { |
|
|
) |
|
|
"schemas": { |
|
|
|
|
|
"Error": { |
|
|
|
|
|
"title": "Error", |
|
|
|
|
|
"required": ["status", "title"], |
|
|
|
|
|
"type": "object", |
|
|
|
|
|
"properties": { |
|
|
|
|
|
"status": {"title": "Status", "type": "string"}, |
|
|
|
|
|
"title": {"title": "Title", "type": "string"}, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
"JsonApiError": { |
|
|
|
|
|
"title": "JsonApiError", |
|
|
|
|
|
"required": ["errors"], |
|
|
|
|
|
"type": "object", |
|
|
|
|
|
"properties": { |
|
|
|
|
|
"errors": { |
|
|
|
|
|
"title": "Errors", |
|
|
|
|
|
"type": "array", |
|
|
|
|
|
"items": {"$ref": "#/components/schemas/Error"}, |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
} |
|
|
|
|
|
|