Skip to main content

openapi2jsonschema2

A utility to extract JSON Schema from a valid OpenAPI specification.

Forked and updated from openapi2jsonschema. The original project does not appear to be maintained. All credit to the original authors.

Why

OpenAPI contains a list of type definitions using a superset of JSON Schema. These are used internally by various OpenAPI compatible tools. I found myself however wanting to use those schemas separately, outside existing OpenAPI tooling. Generating separate schemas for types defined in OpenAPI allows for all sorts of indepent tooling to be build which can be easily maintained, because the canonical definition is shared.

Installation

openapi2jsonschema2 is implemented in Python. Assuming you have a Python intepreter and pip installed you should be able to install with:

pip install openapi2jsonschema2

This has not yet been widely tested and is currently in a works on my machine state.

Usage

The simplest usage is to point the openapi2jsonschema2 tool at a URL containing a JSON (or YAML) OpenAPI definition like so:

openapi2jsonschema2 https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json

This will generate a set of schemas in a schemas directory. The tool provides a number of options to modify the output:

$ openapi2jsonschema2 --help
Usage: openapi2jsonschema2 [OPTIONS] SCHEMA

  Converts a valid OpenAPI specification into a set of JSON Schema files

Options:
  -o, --output PATH  Directory to store schema files
  -p, --prefix TEXT  Prefix for JSON references (only for OpenAPI versions
                     before 3.0)
  --stand-alone      Whether or not to de-reference JSON schemas
  --kubernetes       Enable Kubernetes specific processors
  --strict           Prohibits properties not in the schema
                     (additionalProperties: false)
  --help             Show this message and exit.

Example

My specific use-case was being able to validate a Kubernetes configuration file without a Kubernetes client like kubectl and without the server. For that I have a bash script, available here.

The output from running this script can be seen in the accompanying instrumenta/kubernetes-json-schema.

Metadata

Release files for openapi2jsonschema2 1.1.12

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

Source distribution (sdist)

Source distribution for openapi2jsonschema2 1.1.12
File Size Uploaded Provenance Actions
openapi2jsonschema2-1.1.12.tar.gz 6.1 kB Without provenance Details for openapi2jsonschema2-1.1.12.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for openapi2jsonschema2 1.1.12
File Interpreter ABI Platform Actions
openapi2jsonschema2-1.1.12-py3-none-any.whl Python 3 none any Details for openapi2jsonschema2-1.1.12-py3-none-any.whl

Total release size: 14.5 kB

Release files / openapi2jsonschema2-1.1.12.tar.gz

Download URL openapi2jsonschema2-1.1.12.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4b91bfa9c2752d59da58d10d9e86f6a40d1e9cd047facaf9b61fbe4c44d972d6
BLAKE2b-256 checksum
How to use checksums
ea7d07f46da2e20055bd70380b267f34db8c4560a1c4d646d48d828c6d9c8c5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.13.2 Linux/5.15.0-1074-azure

Release files / openapi2jsonschema2-1.1.12-py3-none-any.whl

Download URL openapi2jsonschema2-1.1.12-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
431c2362b4f1758f0d11f505a68a83b2f09f0f43b54b6b49614de2514d1456a5
BLAKE2b-256 checksum
How to use checksums
dc8d17529d13bb453efc1fbd36677c98a882e81a94a496e7add664edef1c169f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.13.2 Linux/5.15.0-1074-azure

Security for openapi2jsonschema2 1.1.12

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

1.1.12 This release

2 release files No provenance

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