Adding upstream version 0.5.1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
303fa6e9d8
commit
97e6d74bac
110 changed files with 12006 additions and 0 deletions
0
tests/schema_classes/__init__.py
Normal file
0
tests/schema_classes/__init__.py
Normal file
64
tests/schema_classes/test_schema.py
Normal file
64
tests/schema_classes/test_schema.py
Normal file
|
@ -0,0 +1,64 @@
|
|||
import logging
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from openapi_pydantic import Reference, schema_validate
|
||||
from openapi_pydantic.compat import (
|
||||
DEFS_KEY,
|
||||
PYDANTIC_V2,
|
||||
ConfigDict,
|
||||
Extra,
|
||||
models_json_schema,
|
||||
v1_schema,
|
||||
)
|
||||
|
||||
|
||||
def test_schema() -> None:
|
||||
schema = schema_validate(
|
||||
{
|
||||
"title": "reference list",
|
||||
"description": "schema for list of reference type",
|
||||
"allOf": [{"$ref": "#/definitions/TestType"}],
|
||||
}
|
||||
)
|
||||
logging.debug(f"schema.allOf={schema.allOf}")
|
||||
assert schema.allOf
|
||||
assert isinstance(schema.allOf, list)
|
||||
assert isinstance(schema.allOf[0], Reference)
|
||||
assert schema.allOf[0].ref == "#/definitions/TestType"
|
||||
|
||||
|
||||
def test_additional_properties_is_bool() -> None:
|
||||
class TestModel(BaseModel):
|
||||
test_field: str
|
||||
|
||||
if PYDANTIC_V2:
|
||||
model_config = ConfigDict(
|
||||
extra="forbid",
|
||||
)
|
||||
|
||||
else:
|
||||
|
||||
class Config:
|
||||
extra = Extra.forbid
|
||||
|
||||
if PYDANTIC_V2:
|
||||
_key_map, schema_definition = models_json_schema([(TestModel, "validation")])
|
||||
else:
|
||||
schema_definition = v1_schema([TestModel])
|
||||
|
||||
assert schema_definition == {
|
||||
DEFS_KEY: {
|
||||
"TestModel": {
|
||||
"title": "TestModel",
|
||||
"type": "object",
|
||||
"properties": {"test_field": {"title": "Test Field", "type": "string"}},
|
||||
"required": ["test_field"],
|
||||
"additionalProperties": False,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# allow "additionalProperties" to have boolean value
|
||||
result = schema_validate(schema_definition[DEFS_KEY]["TestModel"])
|
||||
assert result.additionalProperties is False
|
46
tests/schema_classes/test_security_scheme.py
Normal file
46
tests/schema_classes/test_security_scheme.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
from openapi_pydantic import SecurityScheme
|
||||
from openapi_pydantic.compat import PYDANTIC_V2
|
||||
|
||||
|
||||
def test_oidc_parsing() -> None:
|
||||
security_scheme_1 = SecurityScheme(
|
||||
type="openIdConnect", openIdConnectUrl="https://example.com/openIdConnect"
|
||||
)
|
||||
assert isinstance(security_scheme_1.openIdConnectUrl, str)
|
||||
dump1 = getattr(security_scheme_1, "model_dump_json" if PYDANTIC_V2 else "json")
|
||||
if PYDANTIC_V2:
|
||||
assert dump1(by_alias=True, exclude_none=True) == (
|
||||
'{"type":"openIdConnect","openIdConnectUrl":"https://example.com/openIdConnect"}'
|
||||
)
|
||||
else:
|
||||
assert dump1(by_alias=True, exclude_none=True) == (
|
||||
'{"type": "openIdConnect", "openIdConnectUrl": "https://example.com/openIdConnect"}'
|
||||
)
|
||||
|
||||
security_scheme_2 = SecurityScheme(
|
||||
type="openIdConnect", openIdConnectUrl="/openIdConnect"
|
||||
)
|
||||
assert isinstance(security_scheme_2.openIdConnectUrl, str)
|
||||
dump2 = getattr(security_scheme_2, "model_dump_json" if PYDANTIC_V2 else "json")
|
||||
if PYDANTIC_V2:
|
||||
assert dump2(by_alias=True, exclude_none=True) == (
|
||||
'{"type":"openIdConnect","openIdConnectUrl":"/openIdConnect"}'
|
||||
)
|
||||
else:
|
||||
assert dump2(by_alias=True, exclude_none=True) == (
|
||||
'{"type": "openIdConnect", "openIdConnectUrl": "/openIdConnect"}'
|
||||
)
|
||||
|
||||
security_scheme_3 = SecurityScheme(
|
||||
type="openIdConnect", openIdConnectUrl="openIdConnect"
|
||||
)
|
||||
assert isinstance(security_scheme_3.openIdConnectUrl, str)
|
||||
dump3 = getattr(security_scheme_3, "model_dump_json" if PYDANTIC_V2 else "json")
|
||||
if PYDANTIC_V2:
|
||||
assert dump3(by_alias=True, exclude_none=True) == (
|
||||
'{"type":"openIdConnect","openIdConnectUrl":"openIdConnect"}'
|
||||
)
|
||||
else:
|
||||
assert dump3(by_alias=True, exclude_none=True) == (
|
||||
'{"type": "openIdConnect", "openIdConnectUrl": "openIdConnect"}'
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue