Skip to main content

openapi-spec-validator-rs

A fast, drop-in Rust companion to openapi-spec-validator.

It validates Swagger 2.0 and OpenAPI 3.0, 3.1 and 3.2 documents with the same rules as openapi-spec-validator, returns the same verdicts, and runs 40 to 145 times faster on large specs. It ships as a command-line tool, a Python package with the same API, and a pre-commit hook.

Command-line run time, including start-up and parsing, on an Apple M4 (mean of 10 runs; the range is openapi-spec-validator with its jsonschema-rs backend and with its default backend):

Spec openapi-spec-validator-rs openapi-spec-validator Speed-up
GitHub (OpenAPI 3.0, JSON, 13.5 MB) 57 ms 6.41 s – 8.18 s 113–144×
GitHub (OpenAPI 3.0, YAML, 10.3 MB) 152 ms 6.45 s – 8.20 s 42–54×
Stripe (OpenAPI 3.0, JSON, 8.3 MB) 31 ms 1.80 s – 2.82 s 59–92×
Kubernetes (Swagger 2.0, JSON, 4.3 MB) 20 ms 762 ms – 2.13 s 39–109×

Why

openapi-spec-validator is the standard OpenAPI validator in the Python ecosystem, but on large documents it takes seconds: most of the time goes into walking the document in Python, and its optional jsonschema-rs backend only speeds up a small part of that. This project ports the whole validator to Rust, rule for rule, so CI pipelines, pre-commit hooks and test suites get the same answers without the wait.

"Same answers" is checked, not assumed:

  • Every check is ported. Each keyword validator in openapi-spec-validator's keywords.py has a counterpart; COMPATIBILITY.md lists them, along with every known difference.
  • Real-world agreement. On all 4,138 specs in the APIs.guru directory, the verdict (valid, or which error class) and the first line of output match openapi-spec-validator 0.9.0 100% of the time, including the 482 specs it rejects.
  • Upstream's own test suite runs against the Python package, unmodified; the 17 of its 136 tests that cannot pass (argparse's wording, upstream's internal settings and caches) are listed with their reasons.
  • The quirks too. JSON and YAML are parsed exactly as PyYAML parses them, patterns follow Python's re rules, and errors are reported with the same messages, in the same order.

Install

pip install openapi-spec-validator-rs

This installs the openapi-spec-validator-rs command and the openapi_spec_validator_rs Python package (wheels for Linux, macOS and Windows; Python 3.10+). To build the command from source instead:

cargo install --path crates/openapi-spec-validator-rs-cli

Command line

Use it exactly like openapi-spec-validator:

openapi-spec-validator-rs openapi.yaml
openapi.yaml: OK

It accepts the same arguments (--schema {detect,2.0,3.0,3.1,3.2}, --validation-errors {first,all}, --subschema-errors {best-match,all}, - for standard input), prints the same messages and exits with the same status: 0 when valid, 1 for a validation or read error, 2 for any other error. Several files are validated in parallel and reported in order.

Python

The package mirrors openapi-spec-validator's API:

from openapi_spec_validator_rs import validate, validate_path, validate_url
from openapi_spec_validator_rs import OpenAPIV31SpecValidator, OpenAPIValidationError

validate(spec_dict)                     # raises the first error
validate_path("openapi.yaml")           # reads the file like the command line
validate_url("https://example.com/openapi.json")

errors = list(OpenAPIV31SpecValidator(spec_dict).iter_errors())

Errors are OpenAPIValidationError (or one of its subclasses: DuplicateOperationIDError, ParameterDuplicateError, UnresolvableParameterError, ExtraParametersError) with the same attributes and messages as upstream's. Moving over is usually a matter of changing the import from openapi_spec_validator to openapi_spec_validator_rs.

Validate your FastAPI schema in CI

FastAPI builds its OpenAPI document at runtime, so check it in your test suite:

# tests/test_openapi.py
from openapi_spec_validator_rs import validate

from myapp.main import app


def test_openapi_schema_is_valid():
    validate(app.openapi())

Run it in CI like any other test:

# .github/workflows/ci.yml
- run: pip install -e . pytest openapi-spec-validator-rs
- run: pytest tests/test_openapi.py

pre-commit

# .pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: openapi-spec-validator-rs
        name: openapi-spec-validator-rs
        entry: openapi-spec-validator-rs
        language: python
        additional_dependencies: [openapi-spec-validator-rs==0.1.0]
        files: .*(openapi|swagger).*\.(json|yaml|yml)$

Adjust files: to match your spec files. The repository also ships a .pre-commit-hooks.yaml, so the hook can be referenced as repo: https://github.com/Arjun-Aravind/openapi-spec-validator-rs with a rev instead, but pre-commit then builds the package from source, which needs a Rust toolchain on every machine that runs it; the form above installs the prebuilt wheel.

Benchmarks

Validation time per spec

Calling validate(spec_dict) from Python on an already-loaded document (what a test that validates FastAPI's app.openapi() does), median of 5 runs:

Spec openapi-spec-validator-rs openapi-spec-validator, jsonschema-rs backend openapi-spec-validator, default backend
GitHub (13.5 MB) 33 ms 4.67 s (143× slower) 6.38 s (196× slower)
Stripe (8.3 MB) 16 ms 0.89 s (55× slower) 1.91 s (119× slower)
Kubernetes (4.3 MB) 11 ms 0.33 s (29× slower) 1.70 s (149× slower)

It also needs about a quarter of the memory on JSON specs: 81 MiB instead of 290 MiB for GitHub's.

Validating every spec in the APIs.guru directory that openapi-spec-validator accepts (3,646 files, 535 MB of YAML) takes 1.6 s instead of 202–332 s.

See BENCHMARKS.md for the method, every measurement and how to reproduce them.

How it works

The validator is a Rust library (crates/openapi-spec-validator-rs) with a CLI and PyO3 bindings on top. It follows the reference implementation step by step:

  1. Load: JSON goes through serde_json when libyaml would read it the same way; anything else goes through libyaml (the parser inside PyYAML) with PyYAML's YAML 1.1 rules, then through the same JSON round trip.
  2. Meta-schema: the whole document is validated against the official schema for its version with the jsonschema crate.
  3. Walk: the document is walked like keywords.py, following $refs, checking every reachable schema against its dialect, default values against their schemas, and operation IDs, parameters, path templates and tags.

Python-specific behaviour (re syntax, str.format parsing of path templates, repr in messages, format checks) is reproduced by small modules tested against CPython.

Compatibility

See COMPATIBILITY.md. In short: verdicts match openapi-spec-validator 0.9.0's default installation. Remote (http://) $refs are not fetched, and a handful of pathological inputs (schemas nested over 120 levels deep, NaN literals) behave differently.

License

Apache-2.0, like openapi-spec-validator, which this project ports. See LICENSE and NOTICE.

Metadata

Release files for openapi-spec-validator-rs 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openapi-spec-validator-rs 0.1.0
File Size Uploaded Provenance
openapi_spec_validator_rs-0.1.0.tar.gz 208.2 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for openapi-spec-validator-rs 0.1.0
File
openapi_spec_validator_rs-0.1.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
openapi_spec_validator_rs-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
openapi_spec_validator_rs-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
openapi_spec_validator_rs-0.1.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
openapi_spec_validator_rs-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 15.9 MB

Release files / openapi_spec_validator_rs-0.1.0.tar.gz

Download URL openapi_spec_validator_rs-0.1.0.tar.gz
Size 208.2 kB
Tags Source
SHA-256 checksum
How to use checksums
146b5a3c05d533fc7a3176e47ea07a609762cd2d7b018869ed222d55ef68ed28
BLAKE2b-256 checksum
How to use checksums
76a4e7579fdfdddd26a0f4fe9ebe0cc806a4ea37d654b6bbdfd3554f9507fedc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / openapi_spec_validator_rs-0.1.0-cp310-abi3-win_amd64.whl

Download URL openapi_spec_validator_rs-0.1.0-cp310-abi3-win_amd64.whl
Size 3.1 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
9e802a475c1eb3d0cf28ad3de43b71a68203aa777c78732bb7d779d4ffbb1b07
BLAKE2b-256 checksum
How to use checksums
27ee14732fc0247a56857ae53533a5b33b366ba5128d73c67e10a7368291cfd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / openapi_spec_validator_rs-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL openapi_spec_validator_rs-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 3.3 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
78690e25c276c7b3ed6d95632a14a4d991f927bb42bc57bfb8d596924aa73e3a
BLAKE2b-256 checksum
How to use checksums
08148b14a0aa2fc1ff292b077cfe417d5de01324e4c11b476f5cadd43ca40991
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / openapi_spec_validator_rs-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL openapi_spec_validator_rs-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 3.1 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
a7587a9e429f8a059212f9f6025e0df09bf3e06d82c1713d6f030665d953616d
BLAKE2b-256 checksum
How to use checksums
7ba88064397f9e422e7e7276214a88e70132dc19735a814fbadcf23461bef3ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / openapi_spec_validator_rs-0.1.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL openapi_spec_validator_rs-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Size 3.0 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
dd29c4b92cb0e31a0734e59afaeac2bd690173a0a024f21189e92691789ea77c
BLAKE2b-256 checksum
How to use checksums
1ec5d36a18a59d164f2e255c5f12383036dad51884d757d4ec59583b1e4aebff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / openapi_spec_validator_rs-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL openapi_spec_validator_rs-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 3.2 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
134fdc0c6bf1b244540752b772de0a56ee74f251e0142405237bf26662fda6b8
BLAKE2b-256 checksum
How to use checksums
a8b963cb61c6c1550cf9c230eb994a576447dac099b4d0c23b07d1a280655b9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Security for openapi-spec-validator-rs 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for openapi_spec_validator_rs-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page