|
|
|
@ -3,7 +3,7 @@ import importlib |
|
|
|
import pytest |
|
|
|
from fastapi._compat import PYDANTIC_VERSION_MINOR_TUPLE |
|
|
|
from fastapi.testclient import TestClient |
|
|
|
from inline_snapshot import snapshot |
|
|
|
from inline_snapshot import Is, snapshot |
|
|
|
|
|
|
|
from ...utils import needs_py310 |
|
|
|
|
|
|
|
@ -66,6 +66,23 @@ def test_query_params_str_validations_item_query_nonregexquery(client: TestClien |
|
|
|
def test_openapi_schema(client: TestClient): |
|
|
|
response = client.get("/openapi.json") |
|
|
|
assert response.status_code == 200, response.text |
|
|
|
|
|
|
|
parameters_schema = { |
|
|
|
"anyOf": [ |
|
|
|
{ |
|
|
|
"type": "string", |
|
|
|
"minLength": 3, |
|
|
|
"maxLength": 50, |
|
|
|
"pattern": "^fixedquery$", |
|
|
|
}, |
|
|
|
{"type": "null"}, |
|
|
|
], |
|
|
|
"title": "Query string", |
|
|
|
"description": "Query string for the items to search in the database that have a good match", |
|
|
|
# See https://github.com/pydantic/pydantic/blob/80353c29a824c55dea4667b328ba8f329879ac9f/tests/test_fastapi.sh#L25-L34. |
|
|
|
**({"deprecated": True} if PYDANTIC_VERSION_MINOR_TUPLE >= (2, 10) else {}), |
|
|
|
} |
|
|
|
|
|
|
|
assert response.json() == snapshot( |
|
|
|
{ |
|
|
|
"openapi": "3.1.0", |
|
|
|
@ -96,25 +113,7 @@ def test_openapi_schema(client: TestClient): |
|
|
|
"description": "Query string for the items to search in the database that have a good match", |
|
|
|
"required": False, |
|
|
|
"deprecated": True, |
|
|
|
"schema": { |
|
|
|
"anyOf": [ |
|
|
|
{ |
|
|
|
"type": "string", |
|
|
|
"minLength": 3, |
|
|
|
"maxLength": 50, |
|
|
|
"pattern": "^fixedquery$", |
|
|
|
}, |
|
|
|
{"type": "null"}, |
|
|
|
], |
|
|
|
"title": "Query string", |
|
|
|
"description": "Query string for the items to search in the database that have a good match", |
|
|
|
# See https://github.com/pydantic/pydantic/blob/80353c29a824c55dea4667b328ba8f329879ac9f/tests/test_fastapi.sh#L25-L34. |
|
|
|
**( |
|
|
|
{"deprecated": True} |
|
|
|
if PYDANTIC_VERSION_MINOR_TUPLE >= (2, 10) |
|
|
|
else {} |
|
|
|
), |
|
|
|
}, |
|
|
|
"schema": Is(parameters_schema), |
|
|
|
"name": "item-query", |
|
|
|
"in": "query", |
|
|
|
} |
|
|
|
|