Skip to content

Commit 0514b73

Browse files
committed
Spec 3.1 schema
1 parent 51b791d commit 0514b73

File tree

12 files changed

+1816
-166
lines changed

12 files changed

+1816
-166
lines changed

README.rst

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@ OpenAPI Spec validator
1818
About
1919
#####
2020

21-
OpenAPI Spec Validator is a Python library that validates OpenAPI Specs
22-
against the `OpenAPI 2.0 (aka
23-
Swagger) <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md>`__
24-
and `OpenAPI
25-
3.0 <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md>`__
26-
specification. The validator aims to check for full compliance with the
27-
Specification.
21+
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.
22+
23+
The validator aims to check for full compliance with the Specification.
2824

2925
Installation
3026
############

openapi_spec_validator/__init__.py

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@
1414
__license__ = 'Apache License, Version 2.0'
1515

1616
__all__ = [
17-
'openapi_v2_spec_validator', 'openapi_v3_spec_validator',
18-
'validate_v2_spec', 'validate_v3_spec', 'validate_spec',
19-
'validate_v2_spec_url', 'validate_v3_spec_url', 'validate_spec_url',
17+
'validate_spec', 'validate_spec_url',
18+
'openapi_spec_validator',
19+
'openapi_v2_spec_validator',
20+
'validate_v2_spec', 'validate_v2_spec_url',
21+
'openapi_v3_spec_validator',
22+
'validate_v3_spec', 'validate_v3_spec_url',
23+
'openapi_v3_0_spec_validator',
24+
'validate_v3_0_spec', 'validate_v3_0_spec_url',
25+
'openapi_v3_1_spec_validator',
26+
'validate_v3_1_spec', 'validate_v3_1_spec_url',
2027
]
2128

2229
file_object_handler = FileObjectHandler()
@@ -40,25 +47,48 @@
4047
)
4148

4249
# v3.0 spec
43-
schema_v3, schema_v3_url = get_openapi_schema('3.0')
44-
openapi_v3_validator_factory = JSONSpecValidatorFactory(
45-
schema_v3, schema_v3_url,
50+
schema_v3_0, schema_v3_0_url = get_openapi_schema('3.0')
51+
openapi_v3_0_validator_factory = JSONSpecValidatorFactory(
52+
schema_v3_0, schema_v3_0_url,
4653
resolver_handlers=default_handlers,
4754
)
48-
openapi_v3_spec_validator = SpecValidator(
49-
openapi_v3_validator_factory,
55+
openapi_v3_0_spec_validator = SpecValidator(
56+
openapi_v3_0_validator_factory,
57+
resolver_handlers=default_handlers,
58+
)
59+
60+
# v3.1 spec
61+
schema_v3_1, schema_v3_1_url = get_openapi_schema('3.1')
62+
openapi_v3_1_validator_factory = JSONSpecValidatorFactory(
63+
schema_v3_1, schema_v3_1_url,
64+
resolver_handlers=default_handlers,
65+
)
66+
openapi_v3_1_spec_validator = SpecValidator(
67+
openapi_v3_1_validator_factory,
5068
resolver_handlers=default_handlers,
5169
)
5270

5371
# shortcuts
54-
validate_v2_spec = validate_spec_factory(openapi_v2_spec_validator.validate)
72+
validate_v2_spec = validate_spec_factory(
73+
openapi_v2_spec_validator.validate)
5574
validate_v2_spec_url = validate_spec_url_factory(
5675
openapi_v2_spec_validator.validate, default_handlers)
5776

58-
validate_v3_spec = validate_spec_factory(openapi_v3_spec_validator.validate)
59-
validate_v3_spec_url = validate_spec_url_factory(
60-
openapi_v3_spec_validator.validate, default_handlers)
77+
validate_v3_0_spec = validate_spec_factory(
78+
openapi_v3_0_spec_validator.validate)
79+
validate_v3_0_spec_url = validate_spec_url_factory(
80+
openapi_v3_0_spec_validator.validate, default_handlers)
81+
82+
validate_v3_1_spec = validate_spec_factory(
83+
openapi_v3_1_spec_validator.validate)
84+
validate_v3_1_spec_url = validate_spec_url_factory(
85+
openapi_v3_1_spec_validator.validate, default_handlers)
6186

6287
# aliases to the latest version
63-
validate_spec = validate_v3_spec
64-
validate_spec_url = validate_v3_spec_url
88+
schema_v3, schema_v3_url = schema_v3_1, schema_v3_1_url
89+
openapi_v3_validator_factory = openapi_v3_1_validator_factory
90+
openapi_v3_spec_validator = openapi_v3_1_spec_validator
91+
validate_v3_spec = validate_v3_1_spec
92+
validate_v3_spec_url = validate_v3_1_spec_url
93+
validate_spec = validate_v3_1_spec
94+
validate_spec_url = validate_v3_1_spec_url

openapi_spec_validator/__main__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import sys
44

55
from openapi_spec_validator import (
6-
openapi_v2_spec_validator, openapi_v3_spec_validator,
6+
openapi_v2_spec_validator, openapi_v3_0_spec_validator,
7+
openapi_v3_1_spec_validator
78
)
89
from openapi_spec_validator.exceptions import ValidationError
910
from openapi_spec_validator.readers import read_from_stdin, read_from_filename
@@ -20,10 +21,10 @@ def main(args=None):
2021
parser.add_argument('filename', help="Absolute or relative path to file")
2122
parser.add_argument(
2223
'--schema',
23-
help="OpenAPI schema (default: 3.0.0)",
24+
help="OpenAPI schema (default: 3.1)",
2425
type=str,
25-
choices=['2.0', '3.0.0'],
26-
default='3.0.0'
26+
choices=['2.0', '3.0', '3.1'],
27+
default='3.1'
2728
)
2829
args = parser.parse_args(args)
2930

@@ -42,7 +43,8 @@ def main(args=None):
4243
# choose the validator
4344
validators = {
4445
'2.0': openapi_v2_spec_validator,
45-
'3.0.0': openapi_v3_spec_validator,
46+
'3.0': openapi_v3_0_spec_validator,
47+
'3.1': openapi_v3_1_spec_validator,
4648
}
4749
validator = validators[args.schema]
4850

0 commit comments

Comments
 (0)