Skip to content

Commit 523fcf7

Browse files
authored
Merge pull request #7 from kuimono/schema-additionalProperties-type-fix
Allow `Schema` type `additionalProperties` field to be boolean
2 parents df82022 + e7863bf commit 523fcf7

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## v1.2.2 - Unreleased
4+
5+
### Fixed
6+
- [4](https://github.com/kuimono/openapi-schema-pydantic/issues/4) Allow `Schema` type `additionalProperties` field to be boolean
7+
8+
39
## v1.2.1 - 2021-09-10
410

511
### Added

openapi_schema_pydantic/v3/v3_1_0/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class Schema(BaseModel):
243243
object.
244244
"""
245245

246-
additionalProperties: Optional[Union[Reference, "Schema"]] = None
246+
additionalProperties: Optional[Union[Reference, "Schema", bool]] = None
247247
"""
248248
The value of "additionalProperties" MUST be a valid JSON Schema.
249249

tests/test_schema_class.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import logging
22

3+
from pydantic import BaseModel, Extra
4+
from pydantic.schema import schema
5+
36
from openapi_schema_pydantic import Schema, Reference
47

58

@@ -16,3 +19,30 @@ def test_schema():
1619
assert isinstance(schema.allOf, list)
1720
assert isinstance(schema.allOf[0], Reference)
1821
assert schema.allOf[0].ref == "#/definitions/TestType"
22+
23+
24+
def test_issue_4():
25+
"""https://github.com/kuimono/openapi-schema-pydantic/issues/4"""
26+
27+
class TestModel(BaseModel):
28+
test_field: str
29+
30+
class Config:
31+
extra = Extra.forbid
32+
33+
schema_definition = schema([TestModel])
34+
assert schema_definition == {
35+
"definitions": {
36+
"TestModel": {
37+
"title": "TestModel",
38+
"type": "object",
39+
"properties": {"test_field": {"title": "Test Field", "type": "string"}},
40+
"required": ["test_field"],
41+
"additionalProperties": False,
42+
}
43+
}
44+
}
45+
46+
# allow "additionalProperties" to have boolean value
47+
result = Schema.parse_obj(schema_definition["definitions"]["TestModel"])
48+
assert result.additionalProperties is False

0 commit comments

Comments
 (0)