Skip to content

Spec 3.1 schema #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ OpenAPI Spec validator
About
#####

OpenAPI Spec Validator is a Python library that validates OpenAPI Specs
against the `OpenAPI 2.0 (aka
Swagger) <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md>`__
and `OpenAPI
3.0 <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md>`__
specification. The validator aims to check for full compliance with the
Specification.
OpenAPI Spec Validator is a Python library that validates OpenAPI Specs against the `OpenAPI 2.0 (aka Swagger) <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md>`__, `OpenAPI 3.0 <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md>`__ and `OpenAPI 3.1 <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md>`__ specification.

The validator aims to check for full compliance with the Specification.

Installation
############
Expand Down
58 changes: 44 additions & 14 deletions openapi_spec_validator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@
__license__ = 'Apache License, Version 2.0'

__all__ = [
'openapi_v2_spec_validator', 'openapi_v3_spec_validator',
'validate_v2_spec', 'validate_v3_spec', 'validate_spec',
'validate_v2_spec_url', 'validate_v3_spec_url', 'validate_spec_url',
'validate_spec', 'validate_spec_url',
'openapi_spec_validator',
'openapi_v2_spec_validator',
'validate_v2_spec', 'validate_v2_spec_url',
'openapi_v3_spec_validator',
'validate_v3_spec', 'validate_v3_spec_url',
'openapi_v3_0_spec_validator',
'validate_v3_0_spec', 'validate_v3_0_spec_url',
'openapi_v3_1_spec_validator',
'validate_v3_1_spec', 'validate_v3_1_spec_url',
]

file_object_handler = FileObjectHandler()
Expand All @@ -40,25 +47,48 @@
)

# v3.0 spec
schema_v3, schema_v3_url = get_openapi_schema('3.0')
openapi_v3_validator_factory = JSONSpecValidatorFactory(
schema_v3, schema_v3_url,
schema_v3_0, schema_v3_0_url = get_openapi_schema('3.0')
openapi_v3_0_validator_factory = JSONSpecValidatorFactory(
schema_v3_0, schema_v3_0_url,
resolver_handlers=default_handlers,
)
openapi_v3_spec_validator = SpecValidator(
openapi_v3_validator_factory,
openapi_v3_0_spec_validator = SpecValidator(
openapi_v3_0_validator_factory,
resolver_handlers=default_handlers,
)

# v3.1 spec
schema_v3_1, schema_v3_1_url = get_openapi_schema('3.1')
openapi_v3_1_validator_factory = JSONSpecValidatorFactory(
schema_v3_1, schema_v3_1_url,
resolver_handlers=default_handlers,
)
openapi_v3_1_spec_validator = SpecValidator(
openapi_v3_1_validator_factory,
resolver_handlers=default_handlers,
)

# shortcuts
validate_v2_spec = validate_spec_factory(openapi_v2_spec_validator.validate)
validate_v2_spec = validate_spec_factory(
openapi_v2_spec_validator.validate)
validate_v2_spec_url = validate_spec_url_factory(
openapi_v2_spec_validator.validate, default_handlers)

validate_v3_spec = validate_spec_factory(openapi_v3_spec_validator.validate)
validate_v3_spec_url = validate_spec_url_factory(
openapi_v3_spec_validator.validate, default_handlers)
validate_v3_0_spec = validate_spec_factory(
openapi_v3_0_spec_validator.validate)
validate_v3_0_spec_url = validate_spec_url_factory(
openapi_v3_0_spec_validator.validate, default_handlers)

validate_v3_1_spec = validate_spec_factory(
openapi_v3_1_spec_validator.validate)
validate_v3_1_spec_url = validate_spec_url_factory(
openapi_v3_1_spec_validator.validate, default_handlers)

# aliases to the latest version
validate_spec = validate_v3_spec
validate_spec_url = validate_v3_spec_url
schema_v3, schema_v3_url = schema_v3_0, schema_v3_0_url
openapi_v3_validator_factory = openapi_v3_0_validator_factory
openapi_v3_spec_validator = openapi_v3_0_spec_validator
validate_v3_spec = validate_v3_0_spec
validate_v3_spec_url = validate_v3_0_spec_url
validate_spec = validate_v3_0_spec
validate_spec_url = validate_v3_0_spec_url
12 changes: 7 additions & 5 deletions openapi_spec_validator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import sys

from openapi_spec_validator import (
openapi_v2_spec_validator, openapi_v3_spec_validator,
openapi_v2_spec_validator, openapi_v3_0_spec_validator,
openapi_v3_1_spec_validator
)
from openapi_spec_validator.exceptions import ValidationError
from openapi_spec_validator.readers import read_from_stdin, read_from_filename
Expand All @@ -20,10 +21,10 @@ def main(args=None):
parser.add_argument('filename', help="Absolute or relative path to file")
parser.add_argument(
'--schema',
help="OpenAPI schema (default: 3.0.0)",
help="OpenAPI schema (default: 3.1)",
type=str,
choices=['2.0', '3.0.0'],
default='3.0.0'
choices=['2.0', '3.0', '3.1'],
default='3.0'
)
args = parser.parse_args(args)

Expand All @@ -42,7 +43,8 @@ def main(args=None):
# choose the validator
validators = {
'2.0': openapi_v2_spec_validator,
'3.0.0': openapi_v3_spec_validator,
'3.0': openapi_v3_0_spec_validator,
'3.1': openapi_v3_1_spec_validator,
}
validator = validators[args.schema]

Expand Down
Loading