Skip to main content

Load, resolve, and normalise OpenAPI 3.x / Swagger 2.0 specs into a version-agnostic model.

Project description

openapi-normalizer

PyPI Python License: MIT

Load, resolve, and normalise OpenAPI 3.x and Swagger 2.0 specifications into a single, version-agnostic data model.

  • 🔗 $ref resolution — resolves intra-document references with cycle protection
  • 📦 Version normalisation — OpenAPI 3.x and Swagger 2.0 become the same internal model
  • 🌐 HTTP + local files — load specs from URLs or filesystem paths
  • 📄 JSON + YAML — both formats supported
  • Typed, tested, and linted

Installation

pip install openapi-normalizer

Requires Python 3.10+.

Quickstart

from openapi_normalizer import load_spec, resolve_refs, parse_spec

# Load from URL or file (JSON or YAML)
document = load_spec("https://petstore3.swagger.io/api/v3/openapi.json")

# Resolve all intra-document $ref pointers
document = resolve_refs(document)

# Normalise into a version-agnostic model
spec = parse_spec(document)

print(spec.title)     # "Swagger Petstore - OpenAPI 3.0"
print(spec.base_url)  # "/api/v3"
for op in spec.operations:
    print(op.method, op.path, op.operation_id)

API

load_spec(ref, *, timeout=30.0) → dict

Load a spec from a URL or local file. Returns the parsed document as a dict.

resolve_refs(document) → dict

Resolve all local $ref pointers (e.g. #/components/schemas/Pet) in-place. External references are preserved. Cycles are broken safely.

detect_version(document) → str

Return "openapi-3" or "swagger-2".

parse_spec(document, *, source_ref=None, base_url_override=None) → ParsedSpec

Normalise a ref-resolved document into a ParsedSpec containing:

  • title, base_url, spec_version
  • operations — list of Operation (method, path, parameters, request body, tags)
  • security_schemes — dict of SecurityScheme (type, scheme, name, location)

License

MIT

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_normalizer-0.1.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

openapi_normalizer-0.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file openapi_normalizer-0.1.0.tar.gz.

File metadata

  • Download URL: openapi_normalizer-0.1.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for openapi_normalizer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 181d95b3cf59054d83097f2f5575a9f64f48f919ab88b5d6091ad02e2ef5f37f
MD5 8106ab0695e7c2d015eccb0159b438bb
BLAKE2b-256 e144dfc2640996acc31787b4180e1a7ce7ae3cbf091fbc032faf454da7c9b092

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_normalizer-0.1.0.tar.gz:

Publisher: release.yml on sssdavid529/openapi-normalizer

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_normalizer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openapi_normalizer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c4879124f62bbafb598dad0e2282928ecff2ce8e1b1cf5a1273cbad060a31142
MD5 f936c988459fb4e31dc8bc2a1406fca2
BLAKE2b-256 f7118be5d129940986160b202fa10d4a6fe370595c44241ba63970ca3206d303

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_normalizer-0.1.0-py3-none-any.whl:

Publisher: release.yml on sssdavid529/openapi-normalizer

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