From 90060b9c8a372691ff0045d600d8bc57abba8411 Mon Sep 17 00:00:00 2001 From: p1c2u Date: Fri, 30 Apr 2021 08:50:20 +0100 Subject: [PATCH] Move create_spec shortcut --- openapi_core/shortcuts.py | 21 +-------------------- openapi_core/spec/shortcuts.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 20 deletions(-) create mode 100644 openapi_core/spec/shortcuts.py diff --git a/openapi_core/shortcuts.py b/openapi_core/shortcuts.py index 3bd32f0..504ae10 100644 --- a/openapi_core/shortcuts.py +++ b/openapi_core/shortcuts.py @@ -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) diff --git a/openapi_core/spec/shortcuts.py b/openapi_core/spec/shortcuts.py new file mode 100644 index 0000000..2df933d --- /dev/null +++ b/openapi_core/spec/shortcuts.py @@ -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)