Move create_spec shortcut

This commit is contained in:
p1c2u 2021-04-30 08:50:20 +01:00
parent c407e960ca
commit 90060b9c8a
2 changed files with 22 additions and 20 deletions

View file

@ -1,12 +1,6 @@
"""OpenAPI core shortcuts module"""
# backward compatibility
from jsonschema.validators import RefResolver
from openapi_spec_validator import (
default_handlers, openapi_v3_spec_validator,
)
from openapi_spec_validator.validators import Dereferencer
from openapi_core.spec.paths import SpecPath
from openapi_core.spec.shortcuts import create_spec
from openapi_core.validation.request.shortcuts import (
spec_validate_body as validate_body,
spec_validate_parameters as validate_parameters,
@ -21,16 +15,3 @@ __all__ = [
'create_spec', 'validate_body', 'validate_parameters', 'validate_data',
'RequestValidator', 'ResponseValidator',
]
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)
spec_resolver = RefResolver(
spec_url, spec_dict, handlers=handlers)
dereferencer = Dereferencer(spec_resolver)
return SpecPath.from_spec(spec_dict, dereferencer)

View file

@ -0,0 +1,21 @@
"""OpenAPI core spec shortcuts module"""
from jsonschema.validators import RefResolver
from openapi_spec_validator import (
default_handlers, openapi_v3_spec_validator,
)
from openapi_spec_validator.validators import Dereferencer
from openapi_core.spec.paths import SpecPath
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)
spec_resolver = RefResolver(
spec_url, spec_dict, handlers=handlers)
dereferencer = Dereferencer(spec_resolver)
return SpecPath.from_spec(spec_dict, dereferencer)