diff --git a/aiopenapi3/v30/servers.py b/aiopenapi3/v30/servers.py index d269737f..8acdb68f 100644 --- a/aiopenapi3/v30/servers.py +++ b/aiopenapi3/v30/servers.py @@ -17,6 +17,13 @@ class ServerVariable(ObjectExtended): default: Optional[str] = Field(...) description: Optional[str] = Field(default=None) + @model_validator(mode="after") + def validate_ServerVariable(cls, s: "ServerVariable"): + assert isinstance(s.enum, (list, None.__class__)) + # default value must be in enum + assert s.default in (s.enum or [s.default]) + return s + class Server(ObjectExtended): """ diff --git a/aiopenapi3/v31/servers.py b/aiopenapi3/v31/servers.py index 2c401019..c16a0a50 100644 --- a/aiopenapi3/v31/servers.py +++ b/aiopenapi3/v31/servers.py @@ -21,7 +21,7 @@ class ServerVariable(ObjectExtended): def validate_ServerVariable(cls, s: "ServerVariable"): assert isinstance(s.enum, (list, None.__class__)) # default value must be in enum - assert s.default in (s.enum or [None]) + assert s.default in (s.enum or [s.default]) return s diff --git a/tests/conftest.py b/tests/conftest.py index 3bf7969c..63ab3308 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -56,7 +56,7 @@ def schema(self): return getattr(getattr(aiopenapi3, f"v{self.major}{self.minor}"), "Schema") -@pytest.fixture(scope="session", params=[_Version(3, 0, 3), _Version(3, 1, 0)]) +@pytest.fixture(scope="session", params=[_Version(3, 0, 3), _Version(3, 1, 0)], ids=("v30", "v31")) def openapi_version(request): return request.param @@ -74,7 +74,9 @@ def __str__(self): return f'swagger: "{self.major}.{self.minor}"' -@pytest.fixture(scope="session", params=[_VersionS(2, 0), _VersionS(3, 0, 3), _VersionS(3, 1, 0)]) +@pytest.fixture( + scope="session", params=[_VersionS(2, 0), _VersionS(3, 0, 3), _VersionS(3, 1, 0)], ids=("v20", "v30", "v31") +) def api_version(request): return request.param @@ -474,10 +476,10 @@ def with_schema_baseurl_v20(): @pytest.fixture -def with_paths_servers(): - yield _get_parsed_yaml("paths-servers.yaml") +def with_paths_servers(openapi_version): + yield _get_parsed_yaml("paths-servers.yaml", openapi_version) @pytest.fixture -def with_paths_server_variables(): - yield _get_parsed_yaml("paths-server-variables.yaml") +def with_paths_server_variables(openapi_version): + yield _get_parsed_yaml("paths-server-variables.yaml", openapi_version)