Skip to content

Commit 589e12b

Browse files
authored
Add additionalProperties to Schema object (#43)
1 parent 4ffc7b1 commit 589e12b

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

openapidocs/v3.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
version 3.
44
https://swagger.io/specification/
55
"""
6+
67
from abc import ABC
78
from dataclasses import dataclass
89
from enum import Enum
@@ -118,6 +119,7 @@ class Schema(OpenAPIElement):
118119
format: Union[None, str, ValueFormat] = None
119120
required: Optional[List[str]] = None
120121
properties: Optional[Dict[str, Union["Schema", "Reference"]]] = None
122+
additional_properties: Union[None, bool, "Schema", "Reference"] = None
121123
default: Optional[Any] = None
122124
deprecated: Optional[bool] = None
123125
example: Any = None

tests/test_v3.py

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ class FooParent:
9292

9393
class TestItem:
9494
@abstractmethod
95-
def get_instance(self) -> Any:
96-
...
95+
def get_instance(self) -> Any: ...
9796

9897
def expected_yaml(self) -> str:
9998
return dedent(self.yaml()).strip()
@@ -102,12 +101,10 @@ def expected_json(self) -> str:
102101
return dedent(self.json()).strip()
103102

104103
@abstractmethod
105-
def json(self) -> str:
106-
...
104+
def json(self) -> str: ...
107105

108106
@abstractmethod
109-
def yaml(self) -> str:
110-
...
107+
def yaml(self) -> str: ...
111108

112109

113110
class ParameterExample1(TestItem):
@@ -2050,6 +2047,49 @@ def json(self) -> str:
20502047
"""
20512048

20522049

2050+
class ResponseExample2(TestItem):
2051+
def get_instance(self) -> Any:
2052+
return Response(
2053+
description="A simple string response",
2054+
content={
2055+
"text/plain": MediaType(
2056+
schema=Schema(
2057+
type="object",
2058+
additional_properties=Schema(type="string"),
2059+
)
2060+
)
2061+
},
2062+
)
2063+
2064+
def yaml(self) -> str:
2065+
return """
2066+
description: A simple string response
2067+
content:
2068+
text/plain:
2069+
schema:
2070+
type: object
2071+
additionalProperties:
2072+
type: string
2073+
"""
2074+
2075+
def json(self) -> str:
2076+
return """
2077+
{
2078+
"description": "A simple string response",
2079+
"content": {
2080+
"text/plain": {
2081+
"schema": {
2082+
"type": "object",
2083+
"additionalProperties": {
2084+
"type": "string"
2085+
}
2086+
}
2087+
}
2088+
}
2089+
}
2090+
"""
2091+
2092+
20532093
class RequestBodyExample1(TestItem):
20542094
def get_instance(self) -> Any:
20552095
return RequestBody(

0 commit comments

Comments
 (0)