|
|
@ -1,4 +1,5 @@ |
|
|
import pytest |
|
|
import pytest |
|
|
|
|
|
from dirty_equals import IsOneOf |
|
|
from fastapi import FastAPI |
|
|
from fastapi import FastAPI |
|
|
from fastapi.testclient import TestClient |
|
|
from fastapi.testclient import TestClient |
|
|
from inline_snapshot import snapshot |
|
|
from inline_snapshot import snapshot |
|
|
@ -63,7 +64,9 @@ def test_openapi_schema(client: TestClient): |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
"components": { |
|
|
"components": { |
|
|
"schemas": { |
|
|
"schemas": IsOneOf( |
|
|
|
|
|
# Newer Pydantic: no top-level OtherRole |
|
|
|
|
|
{ |
|
|
"PlatformRole": { |
|
|
"PlatformRole": { |
|
|
"type": "string", |
|
|
"type": "string", |
|
|
"enum": ["admin", "user"], |
|
|
"enum": ["admin", "user"], |
|
|
@ -84,7 +87,35 @@ def test_openapi_schema(client: TestClient): |
|
|
"required": ["username", "role"], |
|
|
"required": ["username", "role"], |
|
|
"title": "User", |
|
|
"title": "User", |
|
|
}, |
|
|
}, |
|
|
} |
|
|
}, |
|
|
|
|
|
# Older Pydantic: adds a top-level OtherRole schema |
|
|
|
|
|
{ |
|
|
|
|
|
"OtherRole": { |
|
|
|
|
|
"enum": [], |
|
|
|
|
|
"title": "OtherRole", |
|
|
|
|
|
}, |
|
|
|
|
|
"PlatformRole": { |
|
|
|
|
|
"type": "string", |
|
|
|
|
|
"enum": ["admin", "user"], |
|
|
|
|
|
"title": "PlatformRole", |
|
|
|
|
|
}, |
|
|
|
|
|
"User": { |
|
|
|
|
|
"properties": { |
|
|
|
|
|
"username": {"type": "string", "title": "Username"}, |
|
|
|
|
|
"role": { |
|
|
|
|
|
"anyOf": [ |
|
|
|
|
|
{"$ref": "#/components/schemas/PlatformRole"}, |
|
|
|
|
|
{"enum": [], "title": "OtherRole"}, |
|
|
|
|
|
], |
|
|
|
|
|
"title": "Role", |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
"type": "object", |
|
|
|
|
|
"required": ["username", "role"], |
|
|
|
|
|
"title": "User", |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
) |
|
|
}, |
|
|
}, |
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
|