def openapi2httpdomain(spec, **options):
generators = []
# OpenAPI spec may contain JSON references, common properties, etc.
# Trying to render the spec "As Is" will require to put multiple
# if-s around the code. In order to simplify flow, let's make the
# spec to have only one (expected) schema, i.e. normalize it.
_normalize_spec(spec, **options)
# If 'paths' are passed we've got to ensure they exist within an OpenAPI
# spec; otherwise raise error and ask user to fix that.
if 'paths' in options:
if not set(options['paths']).issubset(spec['paths']):
raise ValueError(
'One or more paths are not defined in the spec: %s.' % (
', '.join(set(options['paths']) - set(spec['paths'])),
)
)
for endpoint in options.get('paths', spec['paths']):
for method, properties in spec['paths'][endpoint].items():
generators.append(_httpresource(endpoint, method, properties))
return iter(itertools.chain(*generators))
评论列表
文章目录