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

Enhance marshaling performances #339

Merged
1 change: 1 addition & 0 deletions bravado_core/_compat_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
Func = typing.Callable[..., typing.Any]
FuncType = typing.TypeVar('FuncType', bound=Func)
JSONDict = typing.Dict[typing.Text, typing.Any]
MarshalingMethod = typing.Callable[[Arg(typing.Any, 'value')], typing.Any]
UnmarshalingMethod = typing.Callable[[Arg(typing.Any, 'value')], typing.Any]
10 changes: 4 additions & 6 deletions bravado_core/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@


@memoize_by_id
def handle_null_value(swagger_spec, object_schema, is_nullable=False):
# type: (Spec, JSONDict, bool) -> typing.Callable[[FuncType], FuncType]
def handle_null_value(swagger_spec, object_schema, is_nullable=False, is_marshaling_operation=False):
sjaensch marked this conversation as resolved.
Show resolved Hide resolved
# type: (Spec, JSONDict, bool, bool) -> typing.Callable[[FuncType], FuncType]
# TODO: remove is_nullable support once https://github.com/Yelp/bravado-core/issues/335 is addressed
"""
Function wrapper that performs some check to the wrapped function parameter.
Expand All @@ -31,9 +31,6 @@ def handle_null_value(swagger_spec, object_schema, is_nullable=False):
* nullable parameter is needed to ensure that x-nullable is propagated in the case it is defined
as sibling in a reference object (ie. `{'x-nullable': True, '$ref': '#/definitions/something'}`)

:type swagger_spec: :class:`bravado_core.spec.Spec`
:type object_schema: dict
:type is_nullable: bool
"""
default_value = schema.get_default(swagger_spec, object_schema)
is_nullable = is_nullable or schema.is_prop_nullable(swagger_spec, object_schema)
Expand All @@ -53,7 +50,8 @@ def wrapper(value):
raise SwaggerMappingError(
'Spec {0} is a required value'.format(object_schema),
)

elif is_marshaling_operation:
return value
return func(value)

return wrapper
Expand Down
Loading