|
|
|
@ -2,6 +2,7 @@ from typing import List, Optional |
|
|
|
|
|
|
|
from fastapi import FastAPI |
|
|
|
from fastapi.testclient import TestClient |
|
|
|
from inline_snapshot import snapshot |
|
|
|
from pydantic import BaseModel |
|
|
|
|
|
|
|
from .utils import PYDANTIC_V2, needs_pydanticv2 |
|
|
|
@ -135,217 +136,223 @@ def test_openapi_schema(): |
|
|
|
client = get_app_client() |
|
|
|
response = client.get("/openapi.json") |
|
|
|
assert response.status_code == 200, response.text |
|
|
|
assert response.json() == { |
|
|
|
"openapi": "3.1.0", |
|
|
|
"info": {"title": "FastAPI", "version": "0.1.0"}, |
|
|
|
"paths": { |
|
|
|
"/items/": { |
|
|
|
"get": { |
|
|
|
"summary": "Read Items", |
|
|
|
"operationId": "read_items_items__get", |
|
|
|
"responses": { |
|
|
|
"200": { |
|
|
|
"description": "Successful Response", |
|
|
|
"content": { |
|
|
|
"application/json": { |
|
|
|
"schema": { |
|
|
|
"items": { |
|
|
|
"$ref": "#/components/schemas/Item-Output" |
|
|
|
}, |
|
|
|
"type": "array", |
|
|
|
"title": "Response Read Items Items Get", |
|
|
|
assert response.json() == snapshot( |
|
|
|
{ |
|
|
|
"openapi": "3.1.0", |
|
|
|
"info": {"title": "FastAPI", "version": "0.1.0"}, |
|
|
|
"paths": { |
|
|
|
"/items/": { |
|
|
|
"get": { |
|
|
|
"summary": "Read Items", |
|
|
|
"operationId": "read_items_items__get", |
|
|
|
"responses": { |
|
|
|
"200": { |
|
|
|
"description": "Successful Response", |
|
|
|
"content": { |
|
|
|
"application/json": { |
|
|
|
"schema": { |
|
|
|
"items": { |
|
|
|
"$ref": "#/components/schemas/Item-Output" |
|
|
|
}, |
|
|
|
"type": "array", |
|
|
|
"title": "Response Read Items Items Get", |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
"post": { |
|
|
|
"summary": "Create Item", |
|
|
|
"operationId": "create_item_items__post", |
|
|
|
"requestBody": { |
|
|
|
"content": { |
|
|
|
"application/json": { |
|
|
|
"schema": {"$ref": "#/components/schemas/Item-Input"} |
|
|
|
}, |
|
|
|
} |
|
|
|
}, |
|
|
|
"required": True, |
|
|
|
}, |
|
|
|
"responses": { |
|
|
|
"200": { |
|
|
|
"description": "Successful Response", |
|
|
|
"post": { |
|
|
|
"summary": "Create Item", |
|
|
|
"operationId": "create_item_items__post", |
|
|
|
"requestBody": { |
|
|
|
"content": { |
|
|
|
"application/json": { |
|
|
|
"schema": { |
|
|
|
"$ref": "#/components/schemas/Item-Output" |
|
|
|
"$ref": "#/components/schemas/Item-Input" |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
"required": True, |
|
|
|
}, |
|
|
|
"402": { |
|
|
|
"description": "Payment Required", |
|
|
|
"content": { |
|
|
|
"application/json": { |
|
|
|
"schema": { |
|
|
|
"$ref": "#/components/schemas/Item-Output" |
|
|
|
"responses": { |
|
|
|
"200": { |
|
|
|
"description": "Successful Response", |
|
|
|
"content": { |
|
|
|
"application/json": { |
|
|
|
"schema": { |
|
|
|
"$ref": "#/components/schemas/Item-Output" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
"422": { |
|
|
|
"description": "Validation Error", |
|
|
|
"content": { |
|
|
|
"application/json": { |
|
|
|
"schema": { |
|
|
|
"$ref": "#/components/schemas/HTTPValidationError" |
|
|
|
"402": { |
|
|
|
"description": "Payment Required", |
|
|
|
"content": { |
|
|
|
"application/json": { |
|
|
|
"schema": { |
|
|
|
"$ref": "#/components/schemas/Item-Output" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
"422": { |
|
|
|
"description": "Validation Error", |
|
|
|
"content": { |
|
|
|
"application/json": { |
|
|
|
"schema": { |
|
|
|
"$ref": "#/components/schemas/HTTPValidationError" |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
"/items-list/": { |
|
|
|
"post": { |
|
|
|
"summary": "Create Item List", |
|
|
|
"operationId": "create_item_list_items_list__post", |
|
|
|
"requestBody": { |
|
|
|
"content": { |
|
|
|
"application/json": { |
|
|
|
"schema": { |
|
|
|
"items": { |
|
|
|
"$ref": "#/components/schemas/Item-Input" |
|
|
|
}, |
|
|
|
"type": "array", |
|
|
|
"title": "Item", |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
"required": True, |
|
|
|
}, |
|
|
|
"responses": { |
|
|
|
"200": { |
|
|
|
"description": "Successful Response", |
|
|
|
"content": {"application/json": {"schema": {}}}, |
|
|
|
}, |
|
|
|
"422": { |
|
|
|
"description": "Validation Error", |
|
|
|
"/items-list/": { |
|
|
|
"post": { |
|
|
|
"summary": "Create Item List", |
|
|
|
"operationId": "create_item_list_items_list__post", |
|
|
|
"requestBody": { |
|
|
|
"content": { |
|
|
|
"application/json": { |
|
|
|
"schema": { |
|
|
|
"$ref": "#/components/schemas/HTTPValidationError" |
|
|
|
"items": { |
|
|
|
"$ref": "#/components/schemas/Item-Input" |
|
|
|
}, |
|
|
|
"type": "array", |
|
|
|
"title": "Item", |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
"required": True, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
"components": { |
|
|
|
"schemas": { |
|
|
|
"HTTPValidationError": { |
|
|
|
"properties": { |
|
|
|
"detail": { |
|
|
|
"items": {"$ref": "#/components/schemas/ValidationError"}, |
|
|
|
"type": "array", |
|
|
|
"title": "Detail", |
|
|
|
} |
|
|
|
}, |
|
|
|
"type": "object", |
|
|
|
"title": "HTTPValidationError", |
|
|
|
}, |
|
|
|
"Item-Input": { |
|
|
|
"properties": { |
|
|
|
"name": {"type": "string", "title": "Name"}, |
|
|
|
"description": { |
|
|
|
"anyOf": [{"type": "string"}, {"type": "null"}], |
|
|
|
"title": "Description", |
|
|
|
}, |
|
|
|
"sub": { |
|
|
|
"anyOf": [ |
|
|
|
{"$ref": "#/components/schemas/SubItem-Input"}, |
|
|
|
{"type": "null"}, |
|
|
|
] |
|
|
|
"responses": { |
|
|
|
"200": { |
|
|
|
"description": "Successful Response", |
|
|
|
"content": {"application/json": {"schema": {}}}, |
|
|
|
}, |
|
|
|
"422": { |
|
|
|
"description": "Validation Error", |
|
|
|
"content": { |
|
|
|
"application/json": { |
|
|
|
"schema": { |
|
|
|
"$ref": "#/components/schemas/HTTPValidationError" |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
"type": "object", |
|
|
|
"required": ["name"], |
|
|
|
"title": "Item", |
|
|
|
} |
|
|
|
}, |
|
|
|
"Item-Output": { |
|
|
|
"properties": { |
|
|
|
"name": {"type": "string", "title": "Name"}, |
|
|
|
"description": { |
|
|
|
"anyOf": [{"type": "string"}, {"type": "null"}], |
|
|
|
"title": "Description", |
|
|
|
}, |
|
|
|
"sub": { |
|
|
|
"anyOf": [ |
|
|
|
{"$ref": "#/components/schemas/SubItem-Output"}, |
|
|
|
{"type": "null"}, |
|
|
|
] |
|
|
|
}, |
|
|
|
"components": { |
|
|
|
"schemas": { |
|
|
|
"HTTPValidationError": { |
|
|
|
"properties": { |
|
|
|
"detail": { |
|
|
|
"items": { |
|
|
|
"$ref": "#/components/schemas/ValidationError" |
|
|
|
}, |
|
|
|
"type": "array", |
|
|
|
"title": "Detail", |
|
|
|
} |
|
|
|
}, |
|
|
|
"type": "object", |
|
|
|
"title": "HTTPValidationError", |
|
|
|
}, |
|
|
|
"type": "object", |
|
|
|
"required": ["name", "description", "sub"], |
|
|
|
"title": "Item", |
|
|
|
}, |
|
|
|
"SubItem-Input": { |
|
|
|
"properties": { |
|
|
|
"subname": {"type": "string", "title": "Subname"}, |
|
|
|
"sub_description": { |
|
|
|
"anyOf": [{"type": "string"}, {"type": "null"}], |
|
|
|
"title": "Sub Description", |
|
|
|
"Item-Input": { |
|
|
|
"properties": { |
|
|
|
"name": {"type": "string", "title": "Name"}, |
|
|
|
"description": { |
|
|
|
"anyOf": [{"type": "string"}, {"type": "null"}], |
|
|
|
"title": "Description", |
|
|
|
}, |
|
|
|
"sub": { |
|
|
|
"anyOf": [ |
|
|
|
{"$ref": "#/components/schemas/SubItem-Input"}, |
|
|
|
{"type": "null"}, |
|
|
|
] |
|
|
|
}, |
|
|
|
}, |
|
|
|
"tags": { |
|
|
|
"items": {"type": "string"}, |
|
|
|
"type": "array", |
|
|
|
"title": "Tags", |
|
|
|
"default": [], |
|
|
|
"type": "object", |
|
|
|
"required": ["name"], |
|
|
|
"title": "Item", |
|
|
|
}, |
|
|
|
"Item-Output": { |
|
|
|
"properties": { |
|
|
|
"name": {"type": "string", "title": "Name"}, |
|
|
|
"description": { |
|
|
|
"anyOf": [{"type": "string"}, {"type": "null"}], |
|
|
|
"title": "Description", |
|
|
|
}, |
|
|
|
"sub": { |
|
|
|
"anyOf": [ |
|
|
|
{"$ref": "#/components/schemas/SubItem-Output"}, |
|
|
|
{"type": "null"}, |
|
|
|
] |
|
|
|
}, |
|
|
|
}, |
|
|
|
"type": "object", |
|
|
|
"required": ["name", "description", "sub"], |
|
|
|
"title": "Item", |
|
|
|
}, |
|
|
|
"type": "object", |
|
|
|
"required": ["subname"], |
|
|
|
"title": "SubItem", |
|
|
|
}, |
|
|
|
"SubItem-Output": { |
|
|
|
"properties": { |
|
|
|
"subname": {"type": "string", "title": "Subname"}, |
|
|
|
"sub_description": { |
|
|
|
"anyOf": [{"type": "string"}, {"type": "null"}], |
|
|
|
"title": "Sub Description", |
|
|
|
"SubItem-Input": { |
|
|
|
"properties": { |
|
|
|
"subname": {"type": "string", "title": "Subname"}, |
|
|
|
"sub_description": { |
|
|
|
"anyOf": [{"type": "string"}, {"type": "null"}], |
|
|
|
"title": "Sub Description", |
|
|
|
}, |
|
|
|
"tags": { |
|
|
|
"items": {"type": "string"}, |
|
|
|
"type": "array", |
|
|
|
"title": "Tags", |
|
|
|
"default": [], |
|
|
|
}, |
|
|
|
}, |
|
|
|
"tags": { |
|
|
|
"items": {"type": "string"}, |
|
|
|
"type": "array", |
|
|
|
"title": "Tags", |
|
|
|
"default": [], |
|
|
|
"type": "object", |
|
|
|
"required": ["subname"], |
|
|
|
"title": "SubItem", |
|
|
|
}, |
|
|
|
"SubItem-Output": { |
|
|
|
"properties": { |
|
|
|
"subname": {"type": "string", "title": "Subname"}, |
|
|
|
"sub_description": { |
|
|
|
"anyOf": [{"type": "string"}, {"type": "null"}], |
|
|
|
"title": "Sub Description", |
|
|
|
}, |
|
|
|
"tags": { |
|
|
|
"items": {"type": "string"}, |
|
|
|
"type": "array", |
|
|
|
"title": "Tags", |
|
|
|
"default": [], |
|
|
|
}, |
|
|
|
}, |
|
|
|
"type": "object", |
|
|
|
"required": ["subname", "sub_description", "tags"], |
|
|
|
"title": "SubItem", |
|
|
|
}, |
|
|
|
"type": "object", |
|
|
|
"required": ["subname", "sub_description", "tags"], |
|
|
|
"title": "SubItem", |
|
|
|
}, |
|
|
|
"ValidationError": { |
|
|
|
"properties": { |
|
|
|
"loc": { |
|
|
|
"items": { |
|
|
|
"anyOf": [{"type": "string"}, {"type": "integer"}] |
|
|
|
"ValidationError": { |
|
|
|
"properties": { |
|
|
|
"loc": { |
|
|
|
"items": { |
|
|
|
"anyOf": [{"type": "string"}, {"type": "integer"}] |
|
|
|
}, |
|
|
|
"type": "array", |
|
|
|
"title": "Location", |
|
|
|
}, |
|
|
|
"type": "array", |
|
|
|
"title": "Location", |
|
|
|
"msg": {"type": "string", "title": "Message"}, |
|
|
|
"type": {"type": "string", "title": "Error Type"}, |
|
|
|
}, |
|
|
|
"msg": {"type": "string", "title": "Message"}, |
|
|
|
"type": {"type": "string", "title": "Error Type"}, |
|
|
|
"type": "object", |
|
|
|
"required": ["loc", "msg", "type"], |
|
|
|
"title": "ValidationError", |
|
|
|
}, |
|
|
|
"type": "object", |
|
|
|
"required": ["loc", "msg", "type"], |
|
|
|
"title": "ValidationError", |
|
|
|
}, |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
@needs_pydanticv2 |
|
|
|
|