Skip to content

Commit

Permalink
Fix bug issues with duplicate params and null data (#246)
Browse files Browse the repository at this point in the history
* Fix bug issues with duplicate params and null data

* bump version
  • Loading branch information
ahopkins committed Aug 15, 2021
1 parent 65547bc commit 4d4f3f5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
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

0 comments on commit 4d4f3f5

Please sign in to comment.