2017-09-21 11:51:37 +00:00
|
|
|
"""OpenAPI core parameters module"""
|
|
|
|
import logging
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class Parameter(object):
|
|
|
|
"""Represents an OpenAPI operation Parameter."""
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self, name, location, schema=None, default=None,
|
|
|
|
required=False, deprecated=False, allow_empty_value=False,
|
|
|
|
items=None, collection_format=None):
|
|
|
|
self.name = name
|
|
|
|
self.location = location
|
|
|
|
self.schema = schema
|
|
|
|
self.default = default
|
|
|
|
self.required = required
|
|
|
|
self.deprecated = deprecated
|
|
|
|
self.allow_empty_value = allow_empty_value
|
|
|
|
self.items = items
|
|
|
|
self.collection_format = collection_format
|
|
|
|
|
|
|
|
def unmarshal(self, value):
|
|
|
|
if not self.schema:
|
|
|
|
return value
|
|
|
|
|
|
|
|
return self.schema.unmarshal(value)
|
|
|
|
|
|
|
|
|
|
|
|
class ParametersGenerator(object):
|
|
|
|
|
2017-09-22 08:54:37 +00:00
|
|
|
def __init__(self, dereferencer, schemas_registry):
|
2017-09-21 11:51:37 +00:00
|
|
|
self.dereferencer = dereferencer
|
2017-09-22 08:54:37 +00:00
|
|
|
self.schemas_registry = schemas_registry
|
2017-09-21 11:51:37 +00:00
|
|
|
|
|
|
|
def generate(self, paramters):
|
|
|
|
for parameter in paramters:
|
|
|
|
parameter_deref = self.dereferencer.dereference(parameter)
|
|
|
|
|
|
|
|
default = parameter_deref.get('default')
|
|
|
|
required = parameter_deref.get('required', False)
|
|
|
|
|
|
|
|
schema_spec = parameter_deref.get('schema', None)
|
|
|
|
schema = None
|
|
|
|
if schema_spec:
|
2017-09-22 08:54:37 +00:00
|
|
|
schema, _ = self.schemas_registry.get_or_create(schema_spec)
|
2017-09-21 11:51:37 +00:00
|
|
|
|
|
|
|
yield (
|
|
|
|
parameter_deref['name'],
|
|
|
|
Parameter(
|
|
|
|
parameter_deref['name'], parameter_deref['in'],
|
|
|
|
schema=schema, default=default, required=required,
|
|
|
|
),
|
|
|
|
)
|