/json-schema-md-doc

Generate markdown documentation for JSON Schemas

Primary LanguageJavaScriptGNU General Public License v3.0GPL-3.0

json-schema-md-doc

Generate markdown documentation for JSON Schemas

Try it out at brianwendt.github.io/json-schema-md-doc

Download JSONSchemaMarkdown.js

Click here to see the Node example.

NOTE: JSONSchemaMarkdown.js supports json-schema.org draft-7. Previous drafts may not generate documentation correctly.

Simple Implementation

NPM Project

npm install json-schema-md-doc
import { JSONSchemaMarkdown } from "json-schema-md-doc";

or HTML

<script src="https://brianwendt.github.io/json-schema-md-doc/lib/JSONSchemaMarkdown.js"></script>

Javascript

// simple schema for the example
const colors_schema = {
	"description": "Choose a color",
	"type": "string",
	"enum": ["red", "amber", "green"]
}

// create an instance of JSONSchemaMarkdown 
const Doccer = new JSONSchemaMarkdown();
// load the schema
Doccer.load(colors_schema);
// generate the markdown
console.log(Doccer.generate());

Result

 _Choose a color_

Type: `string`

Enum Values: 

 1. _"red"_
 2. _"amber"_
 3. _"green"_

_Generated with [json-schema-md-doc](https://brianwendt.github.io/json-schema-md-doc/)_

For a more complete example, check out this JSFiddle.

Extendabale

You may easily extend JSONSchemaMarkdown.js to customize the formatting of your markdown by overriding any method.

class MyDoccer extends JSONSchemaMarkdown {
    constructor(){
        super();
        this.footer = "Thanks for reading the documentation!";
    }
    valueBool(bool) {
        if (typeof bool === "string") {
            return bool;
        } else {
            return (bool) ? "TRUE" : "FALSE"; //uppercase instead of true/false
        }
    }
};