Export a JSON Schema document to Markdown documentation.
Project description
jsonschema-markdown
Generate markdown documentation from JSON Schema files. The main goal is to generate documentation that is easy to read and understand.
Can be used as a command line tool or as a library.
Easy to use in CI/CD pipelines, as a Docker image is available.
Installation
pipx install jsonschema-markdown
Usage
To use jsonschema-markdown
as a CLI, just pass the filename as an argument and redirect
the output to a file.
$ jsonschema-markdown --help
Usage: jsonschema-markdown [OPTIONS] FILENAME
Load FILENAME and output a markdown version.
Use '-' as FILENAME to read from stdin.
Options:
-t, --title TEXT Do not use the title from the schema, use
this title instead.
--footer / --no-footer Add a footer with a link to the project.
[default: footer]
--empty-columns / --no-empty-columns
Remove empty columns from the output, useful
when deprecated or examples are not used.
[default: empty-columns]
--resolve / --no-resolve [Experimental] Resolve $ref pointers.
[default: no-resolve]
--debug / --no-debug Enable debug output. [default: no-debug]
--examples-format [text|yaml|json]
Format of the examples in the output.
[default: text]
--version Show the version and exit.
--help Show this message and exit.
# Example
$ jsonschema-markdown schema.json > schema.md
Usage with Docker
The jsonschema-markdown
command is also available as a Docker image. To use it, you can mount the schema file as a volume.
cat my-schema.json | docker run --rm -i elisiariocouto/jsonschema-markdown - > schema.md
⚠️ Warning: Do not pass the -t
flag.
The Docker image is available at:
Usage as a library
To use it as a library, load your JSON schema file as Python dict
and pass it to generate.
The function will return a string with the markdown.
import jsonschema_markdown
with open('schema.json') as f:
schema = json.load(f)
markdown = jsonschema_markdown.generate(schema)
Features
The goal is to support the latest JSON Schema specification, 2020-12
. However,
this project does not currently support all features, but it should support:
- Required fields
- String patterns
- Enumerations
- Default values
- Descriptions and titles
- Nested objects using
$defs
ordefinitions
- Basic
oneOf
,anyOf
,allOf
functionality - Arrays
- Integers with minimum, maximum values and exclusives
- Boolean values
- Deprecated fields (using the
deprecated
option, additionaly searches for case-insensitivedeprecated
in the field description) - Supports optional YAML and JSON formatting for examples
Caveats
- This project is still in early development, and the output may change in the future.
- Custom definitions are expected to be in the same file as the schema that uses them,
in the
definitions
or$defs
parameter at the root of the document. - Inline nested definitions are not represented in the output yet. See #18.
Examples
Example 1 Input
Given the following JSON Schema:
{
"$id": "https://example.com/movie.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"description": "A representation of a movie",
"type": "object",
"required": ["title", "director", "releaseDate"],
"properties": {
"title": {
"type": "string"
},
"director": {
"type": "string"
},
"releaseDate": {
"type": "string",
"format": "date"
},
"genre": {
"type": "string",
"enum": ["Action", "Comedy", "Drama", "Science Fiction"]
},
"duration": {
"type": "string"
},
"cast": {
"type": "array",
"items": {
"type": "string"
},
"additionalItems": false
}
}
}
Example 1 Ouput
The following markdown will be generated:
jsonschema-markdown
A representation of a movie
Type: object
Property | Type | Required | Possible values | Deprecated | Default | Description | Examples |
---|---|---|---|---|---|---|---|
title | string |
✅ | string | ||||
director | string |
✅ | string | ||||
releaseDate | string |
✅ | Format: date |
||||
genre | string |
Action Comedy Drama Science Fiction |
|||||
duration | string |
string | |||||
cast | array |
string |
Markdown generated with jsonschema-markdown.
Example 2
In tests/model.py you can see a more complex example of a model that is exported as a JSON Schema.
The output can be seen in tests/model.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file jsonschema_markdown-0.3.17.tar.gz
.
File metadata
- Download URL: jsonschema_markdown-0.3.17.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d9988e680ac0bfcaa4d2e4735bc6e4eff8af8fbb45bb5e157b0c922b06a9a28 |
|
MD5 | 0a6a311a7014e6b0d4fa5a89b8859467 |
|
BLAKE2b-256 | 282d51cb4d228eee7a07323b9f5091cb9818f974e05450493ad0f8f92659086a |
Provenance
The following attestation bundles were made for jsonschema_markdown-0.3.17.tar.gz
:
Publisher:
release.yml
on elisiariocouto/jsonschema-markdown
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
jsonschema_markdown-0.3.17.tar.gz
- Subject digest:
0d9988e680ac0bfcaa4d2e4735bc6e4eff8af8fbb45bb5e157b0c922b06a9a28
- Sigstore transparency entry: 149642490
- Sigstore integration time:
- Predicate type:
File details
Details for the file jsonschema_markdown-0.3.17-py3-none-any.whl
.
File metadata
- Download URL: jsonschema_markdown-0.3.17-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa1b3eeccdc32c6b2e0530083dedf9edd089f070f43750cc8e354c2dbb05fea4 |
|
MD5 | f42db6ebc75ae0e5d08b34afd63ece60 |
|
BLAKE2b-256 | 443da225fba86dbf682fbf21309aea62f5c8803aac93f00df040e05e8f1259f6 |
Provenance
The following attestation bundles were made for jsonschema_markdown-0.3.17-py3-none-any.whl
:
Publisher:
release.yml
on elisiariocouto/jsonschema-markdown
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
jsonschema_markdown-0.3.17-py3-none-any.whl
- Subject digest:
aa1b3eeccdc32c6b2e0530083dedf9edd089f070f43750cc8e354c2dbb05fea4
- Sigstore transparency entry: 149642491
- Sigstore integration time:
- Predicate type: