Skip to main content

OpenAPI 2.0 (aka Swagger) and OpenAPI 3 spec validator

Project description

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

About

OpenAPI Spec Validator is a CLI, pre-commit hook and python package that validates OpenAPI Specs against the OpenAPI 2.0 (aka Swagger), OpenAPI 3.0 OpenAPI 3.1 and OpenAPI 3.2 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

Installation

pip install openapi-spec-validator

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

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:

openapi-spec-validator openapi.yaml

pipes way:

cat openapi.yaml | openapi-spec-validator -

docker way:

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

or more pythonic way:

python -m openapi_spec_validator openapi.yaml

For more details, read about CLI (Command Line Interface).

pre-commit hook

repos:
-   repo: https://github.com/python-openapi/openapi-spec-validator
    rev: 0.8.4 # The version to use or 'master' for latest
    hooks:
    -   id: openapi-spec-validator

For more details, read about pre-commit hook.

Python package

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.

Performance tuning

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

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:

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:

pip install jsonschema-rs

License

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openapi_spec_validator-0.8.4.tar.gz (1.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openapi_spec_validator-0.8.4-py3-none-any.whl (50.3 kB view details)

Uploaded Python 3

File details

Details for the file openapi_spec_validator-0.8.4.tar.gz.

File metadata

  • Download URL: openapi_spec_validator-0.8.4.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for openapi_spec_validator-0.8.4.tar.gz
Algorithm Hash digest
SHA256 8bb324b9b08b9b368b1359dec14610c60a8f3a3dd63237184eb04456d4546f49
MD5 7d1e4238d9b20509ed8b4b29c9ba7382
BLAKE2b-256 10de0199b15f5dde3ca61df6e6b3987420bfd424db077998f0162e8ffe12e4f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_spec_validator-0.8.4.tar.gz:

Publisher: python-publish.yml on python-openapi/openapi-spec-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openapi_spec_validator-0.8.4-py3-none-any.whl.

File metadata

File hashes

Hashes for openapi_spec_validator-0.8.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cf905117063d7c4d495c8a5a167a1f2a8006da6ffa8ba234a7ed0d0f11454d51
MD5 47d798d1699c17cf6f61fb0855bff9b3
BLAKE2b-256 cb7052310f9ece5f4eb02e0b31d538b51f729169517767a8d0100a25db31d67f

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_spec_validator-0.8.4-py3-none-any.whl:

Publisher: python-publish.yml on python-openapi/openapi-spec-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page