Skip to content

Commit

Permalink
v20 - boolean schemas, false
Browse files Browse the repository at this point in the history
  • Loading branch information
commonism committed Nov 16, 2024
1 parent bdcb8bc commit 2325ec4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion aiopenapi3/v20/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Schema(ObjectExtended, SchemaBase):
items: Optional[Union[list[Union["Schema", Reference]], Union["Schema", Reference]]] = Field(default=None)
allOf: list[Union["Schema", Reference]] = Field(default_factory=list)
properties: dict[str, Union["Schema", Reference]] = Field(default_factory=dict)
additionalProperties: Optional[Union["Schema", Reference]] = Field(default=None)
additionalProperties: Optional[Union["Schema", Reference, "_Not"]] = Field(default=None)

discriminator: Optional[str] = Field(default=None) # 'Discriminator'
readOnly: Optional[bool] = Field(default=None)
Expand All @@ -60,3 +60,7 @@ def is_boolean_schema(cls, data: Any) -> Any:

def __getstate__(self):
return SchemaBase.__getstate__(self)


class _Not(Schema):
not_: Optional["Schema"] = Field(alias="not")
4 changes: 4 additions & 0 deletions tests/fixtures/schema-boolean-v20.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ definitions:
A:
type: object
additionalProperties: true

B:
type: object
additionalProperties: false
10 changes: 9 additions & 1 deletion tests/schema_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,4 +757,12 @@ def test_schema_boolean(with_schema_boolean):


def test_schema_boolean_v20(with_schema_boolean_v20):
OpenAPI("/", with_schema_boolean_v20)
api = OpenAPI("/", with_schema_boolean_v20)

A = api._root.definitions["A"].get_type()
B = api._root.definitions["B"].get_type()

A.model_validate({"a": 1})

with pytest.raises(ValidationError):
B.model_validate({"b": 1})

0 comments on commit 2325ec4

Please sign in to comment.