https://github.com/ontodevelopment/json-schema-doc-ts
Generate documentation for JSON Schemas
https://github.com/ontodevelopment/json-schema-doc-ts
documentation json json-schema
Last synced: 3 months ago
JSON representation
Generate documentation for JSON Schemas
- Host: GitHub
- URL: https://github.com/ontodevelopment/json-schema-doc-ts
- Owner: OntoDevelopment
- License: gpl-3.0
- Created: 2025-03-11T05:11:43.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2025-03-17T05:00:02.000Z (3 months ago)
- Last Synced: 2025-03-17T05:05:30.013Z (3 months ago)
- Topics: documentation, json, json-schema
- Language: TypeScript
- Homepage:
- Size: 1.05 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# json-schema-doc-ts
**NOTE:** This module supports [json-schema.org](https://json-schema.org/) `draft-7`. Previous drafts may not generate documentation correctly.
## Generate markdown documentation for JSON Schemas
[Click here](https://github.com/BrianWendt/json-schema-md-doc/tree/master/samples/node) to see the Node example.
If you just need to quickly create markdown from a JSON schema, use the [online tool](https://brianwendt.github.io/json-schema-md-doc/).
### Simple Implementation
**es6 and later**
```
npm install json-schema-doc-ts
``````javascript
import { JSONSchemaMarkdownDoc } from "json-schema-doc-ts";// simple schema for the example
const colors_schema = {
description: "Choose a color",
type: "string",
enum: ["red", "amber", "green"],
};// create an instance of JSONSchemaMarkdownDoc and load the schema
const Doccer = new JSONSchemaMarkdownDoc(colors_schema);
// generate the markdown
console.log(Doccer.generate());
```**Result**
```markdown
_Choose a color_Type: `string`
_path: #_
The value is restricted to the following:
1. _"red"_
2. _"amber"_
3. _"green"__Generated with [OntoDevelopment/json-schema-doc-ts](https://github.com/OntoDevelopment/json-schema-doc-ts)_
```### Extendabale
You may easily extend `JSONSchemaMarkdownDoc` to customize the formatting of your markdown by overriding any method.
```typescript
import { JSONSchemaMarkdownDoc } from "json-schema-doc-ts";class MyDoccer extends JSONSchemaMarkdownDoc {
footer = "Thanks for reading the documentation!";
valueBool(bool: boolean | string) {
if (typeof bool === "string") {
return bool;
} else {
return bool ? "TRUE" : "FALSE"; //uppercase instead of true/false
}
}
}
```## Generate documentation in other formats for JSON Schemas
This project may add a JSONSchemaHtmlDoc (JSON Schema to HTML documentation) class in the future. This is a small sample of what that might look like.
```typescript
import { JSONSchemaDocAbstract } from "json-schema-doc-ts";class JSONSchemaHtmlDoc extends JSONSchemaDocAbstract {
writeLine(text: string = "", level: number = 1): this {
this.response += '' + text + "
";
return this;
}
// ...
}
```## Unit Testing
Unit tests built with vitest.
See [github.com/OntoDevelopment/json-schema-doc-tests](https://github.com/OntoDevelopment/json-schema-doc-tests)