npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wetzel

v0.2.3

Published

Generate Markdown or AsciiDoctor documentation from JSON Schema

Downloads

571

Readme

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.

  • Type: integer
  • Required: No, default: 0
  • Minimum: >= 0

example.type

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

  • Type: string
  • Required: ✓ Yes
  • Allowed values:
    • "SCALAR"
    • "VEC2"
    • "VEC3"
    • "VEC4"
    • "MAT2"
    • "MAT3"
    • "MAT4"

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

  • The -l option specifies the starting header level.
  • The -c option lets you specify a custom symbol to place in front of required properties.
  • The -k option replaces the word must with a specified keyword, such as **MUST**.
  • The -p option lets you specify the relative path that should be used when referencing the schema, relative to where you store the documentation.
  • The -s option lets you specify the path string that should be used when loading the schema reference paths.
  • The -e option writes an additional output file that embeds the full text of JSON schemas (AsciiDoctor mode only).
  • The -m option controls the output style mode. The default is Markdown, use -m=a for AsciiDoctor mode.
  • The -n option will skip writing a Table of Contents.
  • The -w option will suppress any warnings about potential documentation problems that wetzel normally prints by default.
  • The -d option lets you specify the root filename that will be used for writing intermediate wetzel artifacts that are useful when doing wetzel development.
  • The -a option will attempt to aggressively auto-link referenced type names in descriptions between each other. If it's too aggressive, you can add =cqo so that it only attempts to auto-link type names that are within "code-quotes only" (cqo) (e.g.: typeName)
  • The -i option lets you specify an array of schema filenames that might be referenced by others, but shouldn't get their own documentation section.

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.