Skip to main content

A utility to extract JSON Schema from a valid OpenAPI specification

Project description

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.

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

openapi2jsonschema2-1.1.26.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

openapi2jsonschema2-1.1.26-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file openapi2jsonschema2-1.1.26.tar.gz.

File metadata

  • Download URL: openapi2jsonschema2-1.1.26.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.5 Linux/5.15.0-1090-azure

File hashes

Hashes for openapi2jsonschema2-1.1.26.tar.gz
Algorithm Hash digest
SHA256 c6a39ce9ff184fd843e0f3f8c18f8461530baaed98555d4235b6c1dd3e15b258
MD5 fe7ff723c5b54a1313c434a6f1a4cde0
BLAKE2b-256 baf484b56580dc66bc1afe3e574ebea46f7754cf4494bb7493f26c1d51ae520f

See more details on using hashes here.

File details

Details for the file openapi2jsonschema2-1.1.26-py3-none-any.whl.

File metadata

  • Download URL: openapi2jsonschema2-1.1.26-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.5 Linux/5.15.0-1090-azure

File hashes

Hashes for openapi2jsonschema2-1.1.26-py3-none-any.whl
Algorithm Hash digest
SHA256 ca0751b66ffab1e3fbba697ec00309ec88ca44f72f07854087081b39d199695e
MD5 00b7fcd86c7fdda317dfa997b67bc893
BLAKE2b-256 b4121e0327392e60c51c583aa87e734b317b6a16e2a298bbc54e2e43a0d3b83c

See more details on using hashes here.

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