-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #393 from p1c2u/refactor/get-rid-of-create-spec-sh…
…ortcut Get rid of create_spec shortcut
- Loading branch information
Showing
33 changed files
with
495 additions
and
446 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from openapi_core.spec.paths import OpenAPIv30Spec | ||
|
||
__all__ = [ | ||
"OpenAPIv30Spec", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,51 @@ | ||
from jsonschema.validators import RefResolver | ||
from openapi_spec_validator import default_handlers | ||
from openapi_spec_validator import openapi_v3_spec_validator | ||
from openapi_spec_validator.validators import Dereferencer | ||
from pathable.paths import AccessorPath | ||
|
||
from openapi_core.spec.accessors import SpecAccessor | ||
|
||
SPEC_SEPARATOR = "#" | ||
|
||
|
||
class SpecPath(AccessorPath): | ||
class Spec(AccessorPath): | ||
@classmethod | ||
def from_spec(cls, spec_dict, dereferencer=None, *args, **kwargs): | ||
separator = kwargs.pop("separator", SPEC_SEPARATOR) | ||
accessor = SpecAccessor(spec_dict, dereferencer) | ||
def from_dict( | ||
cls, | ||
data, | ||
*args, | ||
url="", | ||
ref_resolver_handlers=default_handlers, | ||
separator=SPEC_SEPARATOR, | ||
): | ||
ref_resolver = RefResolver(url, data, handlers=ref_resolver_handlers) | ||
dereferencer = Dereferencer(ref_resolver) | ||
accessor = SpecAccessor(data, dereferencer) | ||
return cls(accessor, *args, separator=separator) | ||
|
||
|
||
class OpenAPIv30Spec(Spec): | ||
|
||
validator = openapi_v3_spec_validator | ||
|
||
@classmethod | ||
def create( | ||
cls, | ||
data, | ||
*args, | ||
url="", | ||
ref_resolver_handlers=default_handlers, | ||
separator=SPEC_SEPARATOR, | ||
validate=True, | ||
): | ||
if validate: | ||
cls.validator.validate(data, spec_url=url) | ||
|
||
return cls.from_dict( | ||
data, | ||
*args, | ||
url=url, | ||
ref_resolver_handlers=ref_resolver_handlers, | ||
separator=separator, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
from typing import Tuple | ||
|
||
from openapi_core.spec.paths import SpecPath | ||
from openapi_core.spec.paths import OpenAPIv30Spec as Spec | ||
from openapi_core.templating.datatypes import TemplateResult | ||
|
||
|
||
def template_path_len(template_path: Tuple[SpecPath, TemplateResult]) -> int: | ||
def template_path_len(template_path: Tuple[Spec, TemplateResult]) -> int: | ||
return len(template_path[1].variables) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.