CesiumGS / wetzel

Generate Markdown documentation from JSON Schema
Apache License 2.0
134 stars 54 forks source link
json-schema

wetzel

Generate Markdown or AsciiDoctor documentation from JSON Schema

Purpose and Limitations

This tool was developed to generate reference documentation for the glTF schema. As such, it doesn't support the entire JSON Schema spec, only what is needed by the glTF schema. Currently it accepts JSON Schema drafts 3, 4, 7, and 2020-12.

Example

This JSON Schema:

{
    "$schema" : "https://json-schema.org/draft/2020-12/schema",
    "title" : "example",
    "type" : "object",
    "description" : "Example description.",
    "properties" : {
        "byteOffset" : {
            "type" : "integer",
            "description" : "The offset relative to the start of the buffer in bytes.",
            "minimum" : 0,
            "default" : 0
        },
        "type" : {
            "type" : "string",
            "description" : "Specifies if the elements are scalars, vectors, or matrices.",
            "enum" : ["SCALAR", "VEC2", "VEC3", "VEC4", "MAT2", "MAT3", "MAT4"]
        }
    },
    "required" : ["type"],
    "additionalProperties" : false
}

can be used to generate this Markdown documentation:


example

Example description.

example Properties

Type Description Required
byteOffset integer The offset relative to the start of the buffer in bytes. No, default: 0
type string Specifies if the elements are scalars, vectors, or matrices. ✓ Yes

Additional properties are not allowed.

example.byteOffset

The offset relative to the start of the buffer in bytes.

example.type

Specifies if the elements are scalars, vectors, or matrices.


Getting Started

Install Node.js if you don't already have it, clone this repo, and then:

cd wetzel
npm install

Run node bin/wetzel.js and pass it the path to a file with a JSON Schema, and the generated Markdown is output to the console.

It is useful to pipe the Markdown output to the clipboard and then paste into a temporary GitHub issue for testing.

On Mac:

wetzel ../glTF/specification/2.0/schema/accessor.schema.json -l 2 | pbcopy

On Windows:

wetzel.js ../glTF/specification/2.0/schema/accessor.schema.json -l 2 | clip

Run the tests:

npm run test

There's also a version published on npm.

Command-Line Options

Common Usage

This tool is used to generate the glTF Properties Reference section and the JSON Schema Reference Appendix of the glTF specification, using the glTF JSON Schema files as its input data.

The process is initiated from a GitHub Action in the glTF repository (CI.yml). This action runs glTF's Makefile. The Makefile calls wetzel with a command similar to the following:

~/bin/wetzel.js \
    -n -a=cqo -m=a \
    -p "schema" \
    -e "JsonSchemaReference.adoc" \
    -i '["gltfchildofrootproperty.schema.json", "gltfid.schema.json", "gltfproperty.schema.json"]' \
    -c "icon:check[]" \
    -k "**MUST**" \
    schema/glTF.schema.json > PropertiesReference.adoc

This will read schema/glTF.schema.json and all referenced sub-schemas, and produce two different output files:

These files are then included into glTF's Specification.adoc using AsciiDoc include commands:

[[properties-reference]]
= Properties Reference

// Generated with wetzel
include::PropertiesReference.adoc[]

and later:

[appendix]
[[appendix-a-json-schema-reference]]
= JSON Schema Reference (Informative)

// Generated with wetzel
include::JsonSchemaReference.adoc[]

Finally, the Makefile uses asciidoctor to convert Specification.adoc and its included, generated documentation, into HTML and PDF forms of the final glTF specification document, which are then posted to the glTF Registry.

Contributions

Pull requests are appreciated! Please use the same Contributor License Agreement (CLA) used for Cesium.


Developed by the Cesium team and external contributors.