2018-04-17 12:18:40 +00:00
|
|
|
"""OpenAPI core parameters models module"""
|
2017-09-21 11:51:37 +00:00
|
|
|
import logging
|
2017-10-18 13:42:10 +00:00
|
|
|
|
2018-04-18 10:49:49 +00:00
|
|
|
from openapi_core.schema.parameters.enums import (
|
|
|
|
ParameterLocation, ParameterStyle,
|
|
|
|
)
|
2018-04-17 12:18:40 +00:00
|
|
|
from openapi_core.schema.schemas.enums import SchemaType
|
2017-09-21 11:51:37 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class Parameter(object):
|
|
|
|
"""Represents an OpenAPI operation Parameter."""
|
|
|
|
|
|
|
|
def __init__(
|
2017-10-18 13:42:10 +00:00
|
|
|
self, name, location, schema=None, required=False,
|
|
|
|
deprecated=False, allow_empty_value=False,
|
2021-03-30 23:10:35 +00:00
|
|
|
items=None, style=None, explode=None, content=None,
|
|
|
|
extensions=None):
|
2017-09-21 11:51:37 +00:00
|
|
|
self.name = name
|
2017-11-14 11:28:45 +00:00
|
|
|
self.location = ParameterLocation(location)
|
2017-09-21 11:51:37 +00:00
|
|
|
self.schema = schema
|
2017-11-14 11:28:45 +00:00
|
|
|
self.required = (
|
|
|
|
True if self.location == ParameterLocation.PATH else required
|
|
|
|
)
|
2017-09-21 11:51:37 +00:00
|
|
|
self.deprecated = deprecated
|
2017-10-18 13:42:10 +00:00
|
|
|
self.allow_empty_value = (
|
2017-11-14 11:28:45 +00:00
|
|
|
allow_empty_value if self.location == ParameterLocation.QUERY
|
|
|
|
else False
|
2017-10-18 13:42:10 +00:00
|
|
|
)
|
2017-09-21 11:51:37 +00:00
|
|
|
self.items = items
|
2017-11-14 11:28:45 +00:00
|
|
|
self.style = ParameterStyle(style or self.default_style)
|
2017-11-14 16:05:03 +00:00
|
|
|
self.explode = self.default_explode if explode is None else explode
|
2021-03-30 10:12:36 +00:00
|
|
|
self.content = content
|
2021-03-30 23:10:35 +00:00
|
|
|
self.extensions = extensions and dict(extensions) or {}
|
2017-11-14 16:05:03 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def aslist(self):
|
|
|
|
return (
|
|
|
|
self.schema and
|
|
|
|
self.schema.type in [SchemaType.ARRAY, SchemaType.OBJECT]
|
|
|
|
)
|
2017-11-14 11:28:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def default_style(self):
|
|
|
|
simple_locations = [ParameterLocation.PATH, ParameterLocation.HEADER]
|
|
|
|
return (
|
|
|
|
'simple' if self.location in simple_locations else "form"
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def default_explode(self):
|
|
|
|
return self.style == ParameterStyle.FORM
|