Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
800 additions
and
511 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
default_stages: [commit, push] | ||
default_language_version: | ||
# force all unspecified python hooks to run python3 | ||
python: python3 | ||
minimum_pre_commit_version: "1.20.0" | ||
repos: | ||
- repo: meta | ||
hooks: | ||
- id: check-hooks-apply | ||
|
||
- repo: https://github.com/asottile/pyupgrade | ||
rev: v2.19.0 | ||
hooks: | ||
- id: pyupgrade | ||
args: ["--py36-plus"] | ||
|
||
- repo: local | ||
hooks: | ||
- id: flynt | ||
name: Convert to f-strings with flynt | ||
entry: flynt | ||
language: python | ||
additional_dependencies: ['flynt==0.76'] | ||
|
||
- id: black | ||
name: black | ||
entry: black | ||
language: system | ||
require_serial: true | ||
types: [python] | ||
|
||
- id: isort | ||
name: isort | ||
entry: isort | ||
args: ['--filter-files'] | ||
language: system | ||
require_serial: true | ||
types: [python] |
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,5 +1,6 @@ | ||
include README.md | ||
include requirements.txt | ||
include requirements_dev.txt | ||
include openapi_spec_validator/py.typed | ||
include openapi_spec_validator/resources/schemas/*/* | ||
include LICENSE |
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
Empty file.
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,18 +1,23 @@ | ||
import os | ||
import pathlib | ||
from os import path | ||
from pathlib import Path | ||
import sys | ||
from typing import Any | ||
from typing import Hashable | ||
from typing import Mapping | ||
from typing import Tuple | ||
|
||
from jsonschema_spec.handlers import file_handler, all_urls_handler | ||
from jsonschema_spec.handlers import all_urls_handler | ||
from jsonschema_spec.handlers import file_handler | ||
|
||
|
||
def read_from_stdin(filename): | ||
return file_handler(sys.stdin), '' | ||
def read_from_stdin(filename: str) -> Tuple[Mapping[Hashable, Any], str]: | ||
return file_handler(sys.stdin), "" | ||
|
||
|
||
def read_from_filename(filename): | ||
if not os.path.isfile(filename): | ||
raise IOError("No such file: {0}".format(filename)) | ||
def read_from_filename(filename: str) -> Tuple[Mapping[Hashable, Any], str]: | ||
if not path.isfile(filename): | ||
raise OSError(f"No such file: {filename}") | ||
|
||
filename = os.path.abspath(filename) | ||
uri = pathlib.Path(filename).as_uri() | ||
filename = path.abspath(filename) | ||
uri = Path(filename).as_uri() | ||
return all_urls_handler(uri), uri |
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 |
---|---|---|
@@ -1,14 +1,17 @@ | ||
"""OpenAIP spec validator schemas utils module.""" | ||
from os import path | ||
from typing import Any | ||
from typing import Hashable | ||
from typing import Mapping | ||
from typing import Tuple | ||
|
||
import importlib_resources | ||
|
||
from jsonschema_spec.readers import FilePathReader | ||
|
||
|
||
def get_schema(version): | ||
schema_path = 'resources/schemas/v{0}/schema.json'.format(version) | ||
ref = importlib_resources.files('openapi_spec_validator') / schema_path | ||
def get_schema(version: str) -> Tuple[Mapping[Hashable, Any], str]: | ||
schema_path = f"resources/schemas/v{version}/schema.json" | ||
ref = importlib_resources.files("openapi_spec_validator") / schema_path | ||
with importlib_resources.as_file(ref) as resource_path: | ||
schema_path_full = path.join(path.dirname(__file__), resource_path) | ||
return FilePathReader(schema_path_full).read() |
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,41 +1,50 @@ | ||
"""OpenAPI spec validator shortcuts module.""" | ||
import urllib.parse | ||
from typing import Any | ||
from typing import Callable | ||
from typing import Hashable | ||
from typing import Mapping | ||
from typing import Tuple | ||
|
||
from jsonschema_spec.handlers import all_urls_handler | ||
|
||
from openapi_spec_validator.exceptions import ValidatorDetectError | ||
from openapi_spec_validator.validation.validators import SpecValidator | ||
|
||
|
||
def detect_validator(choices, spec): | ||
def detect_validator(choices: Mapping[Tuple[str, str], SpecValidator], spec: Mapping[Hashable, Any]) -> SpecValidator: | ||
for (key, value), validator in choices.items(): | ||
if key in spec and spec[key].startswith(value): | ||
return validator | ||
raise ValidatorDetectError("Spec schema version not detected") | ||
|
||
|
||
def validate_spec_detect_factory(choices): | ||
def validate(spec, spec_url=''): | ||
validator_class = detect_validator(choices, spec) | ||
return validator_class.validate(spec, spec_url=spec_url) | ||
def validate_spec_detect_factory(choices: Mapping[Tuple[str, str], SpecValidator]) -> Callable[[Mapping[Hashable, Any], str], None]: | ||
def validate(spec: Mapping[Hashable, Any], spec_url: str = "") -> None: | ||
validator = detect_validator(choices, spec) | ||
return validator.validate(spec, spec_url=spec_url) | ||
|
||
return validate | ||
|
||
|
||
def validate_spec_factory(validator_class): | ||
def validate(spec, spec_url=''): | ||
return validator_class.validate(spec, spec_url=spec_url) | ||
def validate_spec_factory(validator: SpecValidator) -> Callable[[Mapping[Hashable, Any], str], None]: | ||
def validate(spec: Mapping[Hashable, Any], spec_url: str = "") -> None: | ||
return validator.validate(spec, spec_url=spec_url) | ||
|
||
return validate | ||
|
||
|
||
def validate_spec_url_detect_factory(choices): | ||
def validate(spec_url): | ||
def validate_spec_url_detect_factory(choices: Mapping[Tuple[str, str], SpecValidator]) -> Callable[[str], None]: | ||
def validate(spec_url: str) -> None: | ||
spec = all_urls_handler(spec_url) | ||
validator_class = detect_validator(choices, spec) | ||
return validator_class.validate(spec, spec_url=spec_url) | ||
validator = detect_validator(choices, spec) | ||
return validator.validate(spec, spec_url=spec_url) | ||
|
||
return validate | ||
|
||
|
||
def validate_spec_url_factory(validator_class): | ||
def validate(spec_url): | ||
def validate_spec_url_factory(validator: SpecValidator) -> Callable[[str], None]: | ||
def validate(spec_url: str) -> None: | ||
spec = all_urls_handler(spec_url) | ||
return validator_class.validate(spec, spec_url=spec_url) | ||
return validator.validate(spec, spec_url=spec_url) | ||
|
||
return validate |
Oops, something went wrong.