2020-01-17 14:20:20 +00:00
|
|
|
"""OpenAPI core schema shortcuts module"""
|
|
|
|
from jsonschema.validators import RefResolver
|
2021-02-12 23:41:01 +00:00
|
|
|
from openapi_spec_validator import (
|
|
|
|
default_handlers, openapi_v3_spec_validator,
|
|
|
|
)
|
2020-01-17 14:20:20 +00:00
|
|
|
|
|
|
|
from openapi_core.schema.specs.factories import SpecFactory
|
|
|
|
|
|
|
|
|
2021-02-12 23:41:01 +00:00
|
|
|
def create_spec(
|
|
|
|
spec_dict, spec_url='', handlers=default_handlers,
|
|
|
|
validate_spec=True,
|
|
|
|
):
|
|
|
|
if validate_spec:
|
|
|
|
openapi_v3_spec_validator.validate(spec_dict, spec_url=spec_url)
|
|
|
|
|
2020-01-17 14:20:20 +00:00
|
|
|
spec_resolver = RefResolver(
|
|
|
|
spec_url, spec_dict, handlers=handlers)
|
|
|
|
spec_factory = SpecFactory(spec_resolver)
|
|
|
|
return spec_factory.create(spec_dict, spec_url=spec_url)
|