Skip to content

open-metadata/json-schema-md-doc

 
 

Repository files navigation

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

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
        }
    }
};

About

Generate markdown documentation for JSON Schemas

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 88.3%
  • JavaScript 11.7%