UNPKG

4.69 kBMarkdownView Raw
1# JSON Schema Markdown Tools
2
3[![CircleCI](https://circleci.com/gh/adobe/jsonschema2md.svg?style=svg)](https://circleci.com/gh/adobe/jsonschema2md)
4
5Documenting and validating complex JSON Schemas can be hard. This tool makes it easier by providing a number of scripts that can turn JSON Schema files into readable Markdown documentation that is ready for consumption on GitHub or processed using Jekyll or other static site generators.
6
7These tools have been introduced by Adobe to document Adobe's Experience Data Models (XDM), but can be used for other JSON Schema documents, too.
8
9## JSON Schema Support
10
11`jsonschema2md` is developed against JSON Schema `2019-09`, but not the full vocabulary is supported. Please check the [detailed list of JSON Schema keywords supported by `jsonschema2md`](schemasupport.md). This list is updated by our tests.
12
13## Requirements
14
15- `npm` version 3.10.8 or up
16- `node` v10 or up
17
18## Example Output
19
20Using the schemas in [`examples/schemas`](examples/schemas), the output in [`examples/docs`](examples/docs) has been generated.
21
22## Installing and running
23
24```bash
25$ npm install -g @adobe/jsonschema2md
26
27# show usage information
28$ jsonschema2md
29
30# run task
31$ jsonschema2md -d examples/schemas -o examples/docs
32# generated output for whole folder is written to ./examples/docs
33```
34
35## Internationalization
36
37The generated documentation can be internationalized. Select the language you want to use for the output using the `-l` parameter.
38
39Supported languages are:
40- English
41- German
42
43If you want to provide a translation of your own, [please use GitLocalize](https://gitlocalize.com/repo/3622)
44
45## Display custom attributes in the property description
46`jsonschema2md` displays only the attributes of an property which are defined by the JSON Schema standard. If you want to display additional attributes in the property description you could provide a comma separated list with your custom attributes.
47
48```bash
49$ jsonschema2md -d examples/schemas -o examples/docs -p version,test
50```
51
52## Disable header template
53In some cases you do not need a header because it does not provide any useful information. With the `--header` (or `-h`) parameter you can disable the inclusion of headers.
54
55```bash
56# run against JSON Schema Draft 06
57$ jsonschema2md -d examples/schemas -o examples/docs -v 06 -h false
58```
59
60## Examples as YAML
61
62If you are using JSON Schema to validate YAML documents, for instance configuration files, you might wish for examples to be formatted as YAML, not JSON. Using the command line option `-f yaml` or `--example-format yaml` achieves this goal.
63
64## Using JSON Schema Markdown Tools from `npm`
65
66You can conveniently use the JSON Schema Markdown Tools from `npm`. This makes it possible to set up a conversion toolchain for your JSON Schema project that is driven entirely by `npm`. To do so, first define the dependency by adding this to your `"devDependencies"` section of `package.json`
67
68```json
69 "devDependencies": {
70 "@adobe/jsonschema2md": "^4.0.0"
71 }
72```
73
74Then add the following to the `"scripts"` section of your `package.json` and adapt accordingly:
75
76```json
77"scripts": {
78 "prepare": "mkdir -p docs/reference && jsonschema2md -o docs/reference -d schemas/draft-04"
79}
80```
81
82If you run `npm install` before running `npm run prepare`, `npm` will install the `@adobe/jsonschema2md` in a `node_modules/.bin` path, even if you did not install the JSON Schema Markdown beforehand.
83
84## Tests
85
86Ensure you have all the dependencies installed via `npm install`, then run:
87
88```bash
89npm test
90```
91
92This will run our Jasmine test suite as well as lint the JavaScript according to our style guide (see below).
93
94### CI
95
96Continuous integration runs on [CircleCI](https://circleci.com/gh/adobe/jsonschema2md).
97All pull requests automatically trigger a job that runs the [tests](#tests) by executing the [`config.yml`](.circleci/config.yml).
98
99### Code Coverage
100
101`npm run test` will generate a code coverage report at the end of the test run. Anything below 100% coverage counts as a test failure.
102
103## Style Guide / Linting
104
105This project uses [eslint](https://eslint.org) to enforce JavaScript coding style. To run the linter:
106
107```bash
108npm run lint
109```
110
111## TODOs
112
113Add support for [missing keywords](schemasupport.md)
114
115## Contributing
116
117Please see [Contributing.md](Contributing.md) for details. Pull requests are welcome.
118
119## License/Copyright
120
121Copyright 2017 Adobe Systems Incorporated. All rights reserved.
122This file is licensed to you under the Apache License, Version 2.0 (the "License");
123you may not use this file except in compliance with the License. You may obtain a copy
124of the License at http://www.apache.org/licenses/LICENSE-2.0