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

Fix bug issues with duplicate params and null data #246

Merged
merged 2 commits into from Aug 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion sanic_openapi/__init__.py
Expand Up @@ -3,7 +3,7 @@

swagger_blueprint = openapi2_blueprint

__version__ = "21.6.0"
__version__ = "21.6.1"
__all__ = [
"openapi2_blueprint",
"swagger_blueprint",
Expand Down
8 changes: 8 additions & 0 deletions sanic_openapi/openapi3/blueprint.py
Expand Up @@ -93,6 +93,14 @@ def build_spec(app, loop):
# )

for _parameter in route_parameters:
if any(
(
param.fields["name"] == _parameter.name
for param in operation.parameters
)
):
continue

operation.parameter(
_parameter.name, _parameter.cast, "path"
)
Expand Down
2 changes: 2 additions & 0 deletions sanic_openapi/openapi3/definitions.py
Expand Up @@ -171,6 +171,8 @@ class Parameter(Definition):
deprecated: Optional[bool]
allowEmptyValue: Optional[bool]

__nullable__ = None

def __init__(
self,
name: str,
Expand Down
15 changes: 13 additions & 2 deletions sanic_openapi/openapi3/types.py
Expand Up @@ -3,11 +3,12 @@
from datetime import date, datetime, time
from enum import Enum
from inspect import isclass
from typing import Any, Dict, List, Union, get_type_hints
from typing import Any, Dict, List, Optional, Union, get_type_hints


class Definition:
__fields: dict
__nullable__: Optional[List[str]] = []

def __init__(self, **kwargs):
self.__fields = self.guard(kwargs)
Expand All @@ -24,7 +25,17 @@ def guard(self, fields):
}

def serialize(self):
return _serialize(self.fields)
return {
k: v
for k, v in _serialize(self.fields).items()
if (
v
or (
isinstance(self.__nullable__, list)
and (not self.__nullable__ or k in self.__nullable__)
)
)
}

def __str__(self):
return json.dumps(self.serialize())
Expand Down