|
|
@ -3,7 +3,7 @@ import importlib |
|
|
import pytest |
|
|
import pytest |
|
|
from fastapi.testclient import TestClient |
|
|
from fastapi.testclient import TestClient |
|
|
|
|
|
|
|
|
from ...utils import needs_py310 |
|
|
from ...utils import needs_py310, needs_pydanticv1, needs_pydanticv2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture( |
|
|
@pytest.fixture( |
|
|
@ -37,7 +37,8 @@ def test_path_operation(client: TestClient): |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_openapi_schema(client: TestClient): |
|
|
@needs_pydanticv2 |
|
|
|
|
|
def test_openapi_schema_pv2(client: TestClient): |
|
|
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() == { |
|
|
@ -150,3 +151,138 @@ def test_openapi_schema(client: TestClient): |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@needs_pydanticv1 |
|
|
|
|
|
def test_openapi_schema_pv1(client: TestClient): |
|
|
|
|
|
response = client.get("/openapi.json") |
|
|
|
|
|
assert response.status_code == 200, response.text |
|
|
|
|
|
assert response.json() == { |
|
|
|
|
|
"info": { |
|
|
|
|
|
"title": "FastAPI", |
|
|
|
|
|
"version": "0.1.0", |
|
|
|
|
|
}, |
|
|
|
|
|
"openapi": "3.1.0", |
|
|
|
|
|
"paths": { |
|
|
|
|
|
"/items/{id}": { |
|
|
|
|
|
"put": { |
|
|
|
|
|
"operationId": "update_item_items__id__put", |
|
|
|
|
|
"parameters": [ |
|
|
|
|
|
{ |
|
|
|
|
|
"in": "path", |
|
|
|
|
|
"name": "id", |
|
|
|
|
|
"required": True, |
|
|
|
|
|
"schema": { |
|
|
|
|
|
"title": "Id", |
|
|
|
|
|
"type": "string", |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
], |
|
|
|
|
|
"requestBody": { |
|
|
|
|
|
"content": { |
|
|
|
|
|
"application/json": { |
|
|
|
|
|
"schema": { |
|
|
|
|
|
"$ref": "#/components/schemas/Item", |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
"required": True, |
|
|
|
|
|
}, |
|
|
|
|
|
"responses": { |
|
|
|
|
|
"200": { |
|
|
|
|
|
"content": { |
|
|
|
|
|
"application/json": { |
|
|
|
|
|
"schema": {}, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
"description": "Successful Response", |
|
|
|
|
|
}, |
|
|
|
|
|
"422": { |
|
|
|
|
|
"content": { |
|
|
|
|
|
"application/json": { |
|
|
|
|
|
"schema": { |
|
|
|
|
|
"$ref": "#/components/schemas/HTTPValidationError", |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
"description": "Validation Error", |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
"summary": "Update Item", |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
"components": { |
|
|
|
|
|
"schemas": { |
|
|
|
|
|
"HTTPValidationError": { |
|
|
|
|
|
"properties": { |
|
|
|
|
|
"detail": { |
|
|
|
|
|
"items": { |
|
|
|
|
|
"$ref": "#/components/schemas/ValidationError", |
|
|
|
|
|
}, |
|
|
|
|
|
"title": "Detail", |
|
|
|
|
|
"type": "array", |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
"title": "HTTPValidationError", |
|
|
|
|
|
"type": "object", |
|
|
|
|
|
}, |
|
|
|
|
|
"Item": { |
|
|
|
|
|
"properties": { |
|
|
|
|
|
"description": { |
|
|
|
|
|
"title": "Description", |
|
|
|
|
|
"type": "string", |
|
|
|
|
|
}, |
|
|
|
|
|
"timestamp": { |
|
|
|
|
|
"format": "date-time", |
|
|
|
|
|
"title": "Timestamp", |
|
|
|
|
|
"type": "string", |
|
|
|
|
|
}, |
|
|
|
|
|
"title": { |
|
|
|
|
|
"title": "Title", |
|
|
|
|
|
"type": "string", |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
"required": [ |
|
|
|
|
|
"title", |
|
|
|
|
|
"timestamp", |
|
|
|
|
|
], |
|
|
|
|
|
"title": "Item", |
|
|
|
|
|
"type": "object", |
|
|
|
|
|
}, |
|
|
|
|
|
"ValidationError": { |
|
|
|
|
|
"properties": { |
|
|
|
|
|
"loc": { |
|
|
|
|
|
"items": { |
|
|
|
|
|
"anyOf": [ |
|
|
|
|
|
{ |
|
|
|
|
|
"type": "string", |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
"type": "integer", |
|
|
|
|
|
}, |
|
|
|
|
|
], |
|
|
|
|
|
}, |
|
|
|
|
|
"title": "Location", |
|
|
|
|
|
"type": "array", |
|
|
|
|
|
}, |
|
|
|
|
|
"msg": { |
|
|
|
|
|
"title": "Message", |
|
|
|
|
|
"type": "string", |
|
|
|
|
|
}, |
|
|
|
|
|
"type": { |
|
|
|
|
|
"title": "Error Type", |
|
|
|
|
|
"type": "string", |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
"required": [ |
|
|
|
|
|
"loc", |
|
|
|
|
|
"msg", |
|
|
|
|
|
"type", |
|
|
|
|
|
], |
|
|
|
|
|
"title": "ValidationError", |
|
|
|
|
|
"type": "object", |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
} |
|
|
|