-
-
Notifications
You must be signed in to change notification settings - Fork 66
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 #166 from p1c2u/refactor/schemas-and-validation-re…
…factor schemas and validation refactor
- Loading branch information
Showing
11 changed files
with
72 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
# -*- coding: utf-8 -*- | ||
from jsonschema.validators import Draft202012Validator | ||
from jsonschema.validators import Draft4Validator | ||
from jsonschema_spec.handlers import default_handlers | ||
|
||
from openapi_schema_validator.validators import OAS30Validator | ||
from openapi_schema_validator.validators import OAS31Validator | ||
from openapi_spec_validator.shortcuts import ( | ||
validate_spec_factory, validate_spec_url_factory, | ||
) | ||
from openapi_spec_validator.schemas import get_openapi_schema | ||
from openapi_spec_validator.validators import SpecValidator | ||
from openapi_spec_validator.validation import openapi_v2_spec_validator | ||
from openapi_spec_validator.validation import openapi_v3_spec_validator | ||
from openapi_spec_validator.validation import openapi_v30_spec_validator | ||
from openapi_spec_validator.validation import openapi_v31_spec_validator | ||
|
||
__author__ = 'Artur Maciag' | ||
__email__ = '[email protected]' | ||
|
@@ -34,30 +32,6 @@ | |
'validate_spec_url', | ||
] | ||
|
||
# v2.0 spec | ||
schema_v2, _ = get_openapi_schema('2.0') | ||
openapi_v2_schema_validator = Draft4Validator(schema_v2) | ||
openapi_v2_spec_validator = SpecValidator( | ||
openapi_v2_schema_validator, OAS30Validator, | ||
resolver_handlers=default_handlers, | ||
) | ||
|
||
# v3.0 spec | ||
schema_v30, _ = get_openapi_schema('3.0') | ||
openapi_v30_schema_validator = Draft4Validator(schema_v30) | ||
openapi_v30_spec_validator = SpecValidator( | ||
openapi_v30_schema_validator, OAS30Validator, | ||
resolver_handlers=default_handlers, | ||
) | ||
|
||
# v3.1 spec | ||
schema_v31, _ = get_openapi_schema('3.1') | ||
openapi_v31_schema_validator = Draft202012Validator(schema_v31) | ||
openapi_v31_spec_validator = SpecValidator( | ||
openapi_v31_schema_validator, OAS31Validator, | ||
resolver_handlers=default_handlers, | ||
) | ||
|
||
# shortcuts | ||
validate_v2_spec = validate_spec_factory(openapi_v2_spec_validator.validate) | ||
validate_v2_spec_url = validate_spec_url_factory( | ||
|
@@ -67,14 +41,11 @@ | |
validate_v30_spec_url = validate_spec_url_factory( | ||
openapi_v30_spec_validator.validate, default_handlers) | ||
|
||
|
||
validate_v31_spec = validate_spec_factory(openapi_v31_spec_validator.validate) | ||
validate_v31_spec_url = validate_spec_url_factory( | ||
openapi_v31_spec_validator.validate, default_handlers) | ||
|
||
# aliases to the latest v3 version | ||
schema_v3 = schema_v31 | ||
openapi_v3_spec_validator = openapi_v31_spec_validator | ||
validate_v3_spec = validate_v31_spec | ||
validate_v3_spec_url = validate_v31_spec_url | ||
|
||
|
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,11 @@ | ||
"""OpenAIP spec validator schemas module.""" | ||
from openapi_spec_validator.schemas.utils import get_schema | ||
|
||
__all__ = ["schema_v2", "schema_v3", "schema_v30", "schema_v31"] | ||
|
||
schema_v2, _ = get_schema('2.0') | ||
schema_v30, _ = get_schema('3.0') | ||
schema_v31, _ = get_schema('3.1') | ||
|
||
# alias to the latest v3 version | ||
schema_v3 = schema_v31 |
4 changes: 2 additions & 2 deletions
4
openapi_spec_validator/schemas.py → openapi_spec_validator/schemas/utils.py
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,44 @@ | ||
# -*- coding: utf-8 -*- | ||
from jsonschema.validators import Draft202012Validator | ||
from jsonschema.validators import Draft4Validator | ||
from jsonschema_spec.handlers import default_handlers | ||
from openapi_schema_validator import oas30_format_checker | ||
from openapi_schema_validator import oas31_format_checker | ||
from openapi_schema_validator.validators import OAS30Validator | ||
from openapi_schema_validator.validators import OAS31Validator | ||
|
||
from openapi_spec_validator.schemas import schema_v2 | ||
from openapi_spec_validator.schemas import schema_v30 | ||
from openapi_spec_validator.schemas import schema_v31 | ||
from openapi_spec_validator.validation.validators import SpecValidator | ||
|
||
__all__ = [ | ||
'openapi_v2_spec_validator', | ||
'openapi_v3_spec_validator', | ||
'openapi_v30_spec_validator', | ||
'openapi_v31_spec_validator', | ||
] | ||
|
||
# v2.0 spec | ||
openapi_v2_schema_validator = Draft4Validator(schema_v2) | ||
openapi_v2_spec_validator = SpecValidator( | ||
openapi_v2_schema_validator, OAS30Validator, oas30_format_checker, | ||
resolver_handlers=default_handlers, | ||
) | ||
|
||
# v3.0 spec | ||
openapi_v30_schema_validator = Draft4Validator(schema_v30) | ||
openapi_v30_spec_validator = SpecValidator( | ||
openapi_v30_schema_validator, OAS30Validator, oas30_format_checker, | ||
resolver_handlers=default_handlers, | ||
) | ||
|
||
# v3.1 spec | ||
openapi_v31_schema_validator = Draft202012Validator(schema_v31) | ||
openapi_v31_spec_validator = SpecValidator( | ||
openapi_v31_schema_validator, OAS31Validator, oas31_format_checker, | ||
resolver_handlers=default_handlers, | ||
) | ||
|
||
# alias to the latest v3 version | ||
openapi_v3_spec_validator = openapi_v31_spec_validator |
2 changes: 1 addition & 1 deletion
2
openapi_spec_validator/decorators.py → ...i_spec_validator/validation/decorators.py
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
File renamed without changes.
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