Skip to content

Commit

Permalink
tests - v3x
Browse files Browse the repository at this point in the history
  • Loading branch information
commonism committed Dec 7, 2023
1 parent e9e419b commit dec219b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
7 changes: 7 additions & 0 deletions aiopenapi3/v30/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion aiopenapi3/v31/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
14 changes: 8 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit dec219b

Please sign in to comment.