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.37

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.37
File Size Uploaded
openapi2jsonschema2-1.1.37.tar.gz 8.2 kB Details

Built distribution (wheel)

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

Total release size: 18.5 kB

Release files / openapi2jsonschema2-1.1.37.tar.gz

Download URL openapi2jsonschema2-1.1.37.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
aee814d1ea5772817c81a6eb592af50cbfe93712861096a40ba875d3c6bff67a
BLAKE2b-256 checksum
How to use checksums
9dc3a4a10f9d3b3120f8e7ac1a1db53fbeace59da486d28ea453fc019883ccc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.6 Linux/6.8.0-1059-azure

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

Download URL openapi2jsonschema2-1.1.37-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
41af728e9641b90dbaf2436fcc87d7eb34efe84e1dc34aff7deda7c4b7205706
BLAKE2b-256 checksum
How to use checksums
567e0c607295598a11464e34fe25717f646706a53b8f3fdc391ff211e495077f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.6 Linux/6.8.0-1059-azure
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