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 example/examples on parameters #88

Open
wants to merge 2 commits into
base: master
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 src/openapi_parser/builders/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def build(self, data: dict) -> Parameter:
"required": PropertyMeta(name="required", cast=None),
"schema": PropertyMeta(name="schema", cast=self.schema_factory.create),
"description": PropertyMeta(name="description", cast=str),
"example": PropertyMeta(name="example", cast=None),
"examples": PropertyMeta(name="examples", cast=None),
"deprecated": PropertyMeta(name="deprecated", cast=None),
"explode": PropertyMeta(name="explode", cast=None),
}
Expand Down
4 changes: 2 additions & 2 deletions src/openapi_parser/specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ class Parameter:
schema: Schema
required: Optional[bool] = field(default=False)
description: Optional[str] = None
# example: Optional[Any] # TODO
# examples: list[Any] = field(default_factory=list) # TODO
example: Optional[Any] = None
examples: list[Any] = field(default_factory=list)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After checking the docs for v3 spec, it looks like it won't work with a list type. It should work with dict-like structure, where the key is a string and the value is an Example object, here you can find more details - Parameter object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. Thanks. People are amusing on changing spec every time :)

# allow_reserved: bool # TODO
deprecated: Optional[bool] = field(default=False)
style: Optional[str] = None
Expand Down
3 changes: 3 additions & 0 deletions tests/openapi_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ def create_specification() -> Specification:
name="uuid",
location=ParameterLocation.PATH,
description="User unique id",
example="12345678-1234-5678-1234-567812345678",
required=True,
explode=False,
style=PathParameterStyle.SIMPLE,
Expand All @@ -306,6 +307,7 @@ def create_specification() -> Specification:
name="limit",
location=ParameterLocation.QUERY,
description="Result items limit",
example=10,
required=True,
explode=True,
style=QueryParameterStyle.FORM,
Expand All @@ -315,6 +317,7 @@ def create_specification() -> Specification:
name="offset",
location=ParameterLocation.QUERY,
description="Result items start offset",
example=0,
thaichat04 marked this conversation as resolved.
Show resolved Hide resolved
required=True,
explode=True,
style=QueryParameterStyle.FORM,
Expand Down
Loading