mirror of
https://github.com/correl/openapi-core.git
synced 2024-11-25 11:09:53 +00:00
4c725af0ba
Extensions are allowed on Parameter objects, per the spec: > This object MAY be extended with Specification Extensions. https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#parameterObject
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
"""OpenAPI core parameters models module"""
|
|
import logging
|
|
|
|
from openapi_core.schema.parameters.enums import (
|
|
ParameterLocation, ParameterStyle,
|
|
)
|
|
from openapi_core.schema.schemas.enums import SchemaType
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
class Parameter(object):
|
|
"""Represents an OpenAPI operation Parameter."""
|
|
|
|
def __init__(
|
|
self, name, location, schema=None, required=False,
|
|
deprecated=False, allow_empty_value=False,
|
|
items=None, style=None, explode=None, content=None,
|
|
extensions=None):
|
|
self.name = name
|
|
self.location = ParameterLocation(location)
|
|
self.schema = schema
|
|
self.required = (
|
|
True if self.location == ParameterLocation.PATH else required
|
|
)
|
|
self.deprecated = deprecated
|
|
self.allow_empty_value = (
|
|
allow_empty_value if self.location == ParameterLocation.QUERY
|
|
else False
|
|
)
|
|
self.items = items
|
|
self.style = ParameterStyle(style or self.default_style)
|
|
self.explode = self.default_explode if explode is None else explode
|
|
self.content = content
|
|
self.extensions = extensions and dict(extensions) or {}
|
|
|
|
@property
|
|
def aslist(self):
|
|
return (
|
|
self.schema and
|
|
self.schema.type in [SchemaType.ARRAY, SchemaType.OBJECT]
|
|
)
|
|
|
|
@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
|