Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additionalProperties to Schema object #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions openapidocs/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
version 3.
https://swagger.io/specification/
"""

from abc import ABC
from dataclasses import dataclass
from enum import Enum
Expand Down Expand Up @@ -118,6 +119,7 @@ class Schema(OpenAPIElement):
format: Union[None, str, ValueFormat] = None
required: Optional[List[str]] = None
properties: Optional[Dict[str, Union["Schema", "Reference"]]] = None
additional_properties: Union[None, bool, "Schema", "Reference"] = None
default: Optional[Any] = None
deprecated: Optional[bool] = None
example: Any = None
Expand Down
52 changes: 46 additions & 6 deletions tests/test_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ class FooParent:

class TestItem:
@abstractmethod
def get_instance(self) -> Any:
...
def get_instance(self) -> Any: ...

def expected_yaml(self) -> str:
return dedent(self.yaml()).strip()
Expand All @@ -102,12 +101,10 @@ def expected_json(self) -> str:
return dedent(self.json()).strip()

@abstractmethod
def json(self) -> str:
...
def json(self) -> str: ...

@abstractmethod
def yaml(self) -> str:
...
def yaml(self) -> str: ...


class ParameterExample1(TestItem):
Expand Down Expand Up @@ -2050,6 +2047,49 @@ def json(self) -> str:
"""


class ResponseExample2(TestItem):
def get_instance(self) -> Any:
return Response(
description="A simple string response",
content={
"text/plain": MediaType(
schema=Schema(
type="object",
additional_properties=Schema(type="string"),
)
)
},
)

def yaml(self) -> str:
return """
description: A simple string response
content:
text/plain:
schema:
type: object
additionalProperties:
type: string
"""

def json(self) -> str:
return """
{
"description": "A simple string response",
"content": {
"text/plain": {
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
"""


class RequestBodyExample1(TestItem):
def get_instance(self) -> Any:
return RequestBody(
Expand Down