Skip to content
Draft
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
7 changes: 4 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ OpenAPI Spec Validator is a CLI, pre-commit hook and python package that validat
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/main/versions/3.1.0.md>`__
`OpenAPI 3.1 <https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md>`__
and `OpenAPI 3.2 <https://spec.openapis.org/oas/v3.2.0.html>`__
specification. The validator aims to check for full compliance with the Specification.


Expand Down Expand Up @@ -119,9 +120,9 @@ Related projects
################

* `openapi-core <https://github.com/python-openapi/openapi-core>`__
Python library that adds client-side and server-side support for the OpenAPI v3.0 and OpenAPI v3.1 specification.
Python library that adds client-side and server-side support for the OpenAPI v3.0, OpenAPI v3.1 and OpenAPI v3.2 specification.
* `openapi-schema-validator <https://github.com/python-openapi/openapi-schema-validator>`__
Python library that validates schema against the OpenAPI Schema Specification v3.0 and OpenAPI Schema Specification v3.1.
Python library that validates schema against the OpenAPI Schema Specification v3.0, OpenAPI Schema Specification v3.1 and OpenAPI Schema Specification v3.2.

License
#######
Expand Down
4 changes: 2 additions & 2 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CLI (Command Line Interface)

usage: openapi-spec-validator [-h] [--subschema-errors {best-match,all}]
[--validation-errors {first,all}]
[--errors {best-match,all}] [--schema {detect,2.0,3.0,3.1}]
[--errors {best-match,all}] [--schema {detect,2.0,3.0,3.1,3.2}]
[--version] file [file ...]

positional arguments:
Expand All @@ -61,7 +61,7 @@ CLI (Command Line Interface)
use "all" to get all validation errors.
--errors {best-match,all}, --error {best-match,all}
Deprecated alias for --subschema-errors.
--schema {detect,2.0,3.0,3.1}
--schema {detect,2.0,3.0,3.1,3.2}
OpenAPI schema version (default: detect).
--version show program's version number and exit

Expand Down
7 changes: 4 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ OpenAPI Spec Validator is a CLI, pre-commit hook and python package that validat
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/main/versions/3.1.0.md>`__
`OpenAPI 3.1 <https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md>`__
and `OpenAPI 3.2 <https://spec.openapis.org/oas/v3.2.0.html>`__
specification. The validator aims to check for full compliance with the Specification.

Installation
Expand Down Expand Up @@ -111,9 +112,9 @@ Related projects
----------------

* `openapi-core <https://github.com/python-openapi/openapi-core>`__
Python library that adds client-side and server-side support for the OpenAPI v3.0 and OpenAPI v3.1 specification.
Python library that adds client-side and server-side support for the OpenAPI v3.0, OpenAPI v3.1 and OpenAPI v3.2 specification.
* `openapi-schema-validator <https://github.com/python-openapi/openapi-schema-validator>`__
Python library that validates schema against the OpenAPI Schema Specification v3.0 and OpenAPI Schema Specification v3.1.
Python library that validates schema against the OpenAPI Schema Specification v3.0, OpenAPI Schema Specification v3.1 and OpenAPI Schema Specification v3.2.

License
-------
Expand Down
9 changes: 5 additions & 4 deletions docs/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,21 @@ In order to explicitly validate a:

* Swagger / OpenAPI 2.0 spec, import ``OpenAPIV2SpecValidator``
* OpenAPI 3.0 spec, import ``OpenAPIV30SpecValidator``
* OpenAPI 3.1 spec, import ``OpenAPIV31SpecValidator``
* OpenAPI 3.1 spec, import ``OpenAPIV31SpecValidator``
* OpenAPI 3.2 spec, import ``OpenAPIV32SpecValidator``

and pass the validator class to ``validate`` or ``validate_url`` function:

.. code:: python

validate(spec_dict, cls=OpenAPIV31SpecValidator)
validate(spec_dict, cls=OpenAPIV32SpecValidator)

You can also explicitly import ``OpenAPIV3SpecValidator`` which is a shortcut to the latest v3 release.

If you want to iterate through validation errors:

.. code:: python

from openapi_spec_validator import OpenAPIV31SpecValidator
from openapi_spec_validator import OpenAPIV32SpecValidator

errors_iterator = OpenAPIV31SpecValidator(spec).iter_errors()
errors_iterator = OpenAPIV32SpecValidator(spec).iter_errors()
4 changes: 4 additions & 0 deletions openapi_spec_validator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
from openapi_spec_validator.validation import OpenAPIV3SpecValidator
from openapi_spec_validator.validation import OpenAPIV30SpecValidator
from openapi_spec_validator.validation import OpenAPIV31SpecValidator
from openapi_spec_validator.validation import OpenAPIV32SpecValidator
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
from openapi_spec_validator.validation import openapi_v32_spec_validator

__author__ = "Artur Maciag"
__email__ = "maciag.artur@gmail.com"
Expand All @@ -24,10 +26,12 @@
"openapi_v3_spec_validator",
"openapi_v30_spec_validator",
"openapi_v31_spec_validator",
"openapi_v32_spec_validator",
"OpenAPIV2SpecValidator",
"OpenAPIV3SpecValidator",
"OpenAPIV30SpecValidator",
"OpenAPIV31SpecValidator",
"OpenAPIV32SpecValidator",
"validate",
"validate_url",
"validate_spec",
Expand Down
20 changes: 16 additions & 4 deletions openapi_spec_validator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from openapi_spec_validator.validation import OpenAPIV2SpecValidator
from openapi_spec_validator.validation import OpenAPIV30SpecValidator
from openapi_spec_validator.validation import OpenAPIV31SpecValidator
from openapi_spec_validator.validation import OpenAPIV32SpecValidator
from openapi_spec_validator.validation import SpecValidator

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -55,8 +56,8 @@ def print_validationerror(
print("## " + str(best_match(exc.context)))
if len(exc.context) > 1:
print(
f"\n({len(exc.context) - 1} more subschemas errors,",
"use --subschema-errors=all to see them.)",
f"\n({len(exc.context) - 1} more subschemas errors, "
"use --subschema-errors=all to see them.)"
)


Expand Down Expand Up @@ -101,9 +102,18 @@ def main(args: Sequence[str] | None = None) -> None:
parser.add_argument(
"--schema",
type=str,
choices=["detect", "2.0", "3.0", "3.1", "3.0.0", "3.1.0"],
choices=[
"detect",
"2.0",
"3.0",
"3.1",
"3.2",
"3.0.0",
"3.1.0",
"3.2.0",
],
default="detect",
metavar="{detect,2.0,3.0,3.1}",
metavar="{detect,2.0,3.0,3.1,3.2}",
help="OpenAPI schema version (default: detect).",
)
parser.add_argument(
Expand Down Expand Up @@ -149,9 +159,11 @@ def main(args: Sequence[str] | None = None) -> None:
"2.0": OpenAPIV2SpecValidator,
"3.0": OpenAPIV30SpecValidator,
"3.1": OpenAPIV31SpecValidator,
"3.2": OpenAPIV32SpecValidator,
# backward compatibility
"3.0.0": OpenAPIV30SpecValidator,
"3.1.0": OpenAPIV31SpecValidator,
"3.2.0": OpenAPIV32SpecValidator,
}
validator_cls = validators[args_parsed.schema]

Expand Down
Loading