openapi-spec-validator

OpenAPI 2.0 (aka Swagger) and OpenAPI 3 spec validator

48 个版本 Python <4.0,>=3.10
Artur Maciag <maciag.artur@gmail.com>
安装
pip install openapi-spec-validator
poetry add openapi-spec-validator
pipenv install openapi-spec-validator
conda install openapi-spec-validator
描述

OpenAPI Spec validator


.. image:: https://img.shields.io/docker/v/pythonopenapi/openapi-spec-validator.svg?color=%23086DD7&label=docker%20hub&sort=semver :target: https://hub.docker.com/r/pythonopenapi/openapi-spec-validator .. image:: https://img.shields.io/pypi/v/openapi-spec-validator.svg :target: https://pypi.python.org/pypi/openapi-spec-validator .. image:: https://img.shields.io/codecov/c/github/python-openapi/openapi-spec-validator/master.svg?style=flat :target: https://codecov.io/github/python-openapi/openapi-spec-validator?branch=master .. image:: https://img.shields.io/pypi/pyversions/openapi-spec-validator.svg :target: https://pypi.python.org/pypi/openapi-spec-validator .. image:: https://img.shields.io/pypi/format/openapi-spec-validator.svg :target: https://pypi.python.org/pypi/openapi-spec-validator .. image:: https://img.shields.io/pypi/status/openapi-spec-validator.svg :target: https://pypi.python.org/pypi/openapi-spec-validator

About

OpenAPI Spec Validator is a CLI, pre-commit hook and python package 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> 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.

Documentation #############

Check documentation to see more details about the features. All documentation is in the "docs" directory and online at openapi-spec-validator.readthedocs.io <https://openapi-spec-validator.readthedocs.io>__

Installation ############

.. code-block:: console

pip install openapi-spec-validator

Alternatively you can download the code and install from the repository:

.. code-block:: bash

pip install -e git+https://github.com/python-openapi/openapi-spec-validator.git#egg=openapi_spec_validator

Usage

CLI (Command Line Interface)


Straight forward way:

.. code-block:: bash

openapi-spec-validator openapi.yaml

pipes way:

.. code-block:: bash

cat openapi.yaml | openapi-spec-validator -

docker way:

.. code-block:: bash

docker run -v path/to/openapi.yaml:/openapi.yaml --rm pythonopenapi/openapi-spec-validator /openapi.yaml

or more pythonic way:

.. code-block:: bash

python -m openapi_spec_validator openapi.yaml

For more details, read about CLI (Command Line Interface) <https://openapi-spec-validator.readthedocs.io/en/latest/cli.html>__.

pre-commit hook


.. code-block:: yaml

repos:

For more details, read about pre-commit hook <https://openapi-spec-validator.readthedocs.io/en/latest/hook.html>__.

Python package


.. code:: python

from openapi_spec_validator import validate
from openapi_spec_validator.readers import read_from_filename

spec_dict, base_uri = read_from_filename('openapi.yaml')

# If no exception is raised by validate(), the spec is valid.
validate(spec_dict)

# Example of an intentionally invalid spec.
invalid_spec = {'openapi': '3.1.0'}

validate(invalid_spec)

Traceback (most recent call last):
    ...
OpenAPIValidationError: 'info' is a required property

For more details, read about Python package <https://openapi-spec-validator.readthedocs.io/en/latest/python.html>__.

Performance tuning


You can tune resolved-path caching with an environment variable:

.. code-block:: bash

OPENAPI_SPEC_VALIDATOR_RESOLVED_CACHE_MAXSIZE=2048

Rules:

  • Default is 128.
  • Set 0 to disable the resolved cache.
  • Invalid values (non-integer or negative) fall back to 128.

You can also choose schema validator backend:

.. code-block:: bash

OPENAPI_SPEC_VALIDATOR_SCHEMA_VALIDATOR_BACKEND=jsonschema-rs

Allowed values are auto (default), jsonschema, and jsonschema-rs. Invalid values raise a warning and fall back to auto.

If you select the jsonschema-rs backend, make sure the optional jsonschema-rs package is installed:

.. code-block:: bash

pip install jsonschema-rs

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, 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, OpenAPI Schema Specification v3.1 and OpenAPI Schema Specification v3.2.

License #######

Copyright (c) 2017-2023, Artur Maciag, All rights reserved. Apache v2

版本列表
0.9.0 2026-05-20
0.8.5 2026-04-24
0.8.4 2026-03-01
0.8.3 2026-02-28
0.8.2 2026-02-27
0.8.1 2026-02-24
0.8.0 2026-02-23
0.8.0b3 2026-02-17
0.8.0b2 2026-02-14
0.8.0b1 2025-06-07
0.7.2 2025-06-07
0.7.1 2023-10-13
0.7.0 2023-10-09
0.6.0 2023-07-10
0.6.0a2 2023-06-16
0.6.0a1 2023-06-15
0.5.7 2023-06-11
0.5.6 2023-03-17
0.5.5 2023-02-06
0.5.4 2023-02-02
0.5.3 2023-02-01
0.5.2 2023-01-16
0.5.1 2022-09-05
0.5.0 2022-09-02
0.5.0a3 2022-08-31
0.5.0a2 2022-06-21
0.5.0a1 2022-01-28
0.4.0 2022-01-28
0.3.3 2022-01-27
0.3.2 2022-01-17
0.3.1 2021-05-12
0.3.0 2021-02-24
0.2.10 2021-02-24
0.2.9 2020-07-27
0.2.8 2019-07-22
0.2.7 2019-05-20
0.2.6 2019-02-28
0.2.5 2019-02-24
0.2.4 2018-07-30
0.2.3 2018-07-23
0.2.2 2018-06-21
0.2.1 2018-06-05
0.2.0 2018-04-09
0.1.2 2018-01-19
0.1.1 2017-10-27
0.1.0 2017-09-13
0.0.3 2017-09-07
0.0.2 2017-09-06