1 | # JSON Schema Markdown Tools
|
2 |
|
3 | [![CircleCI](https://circleci.com/gh/adobe/jsonschema2md.svg?style=svg)](https://circleci.com/gh/adobe/jsonschema2md)
|
4 |
|
5 | Documenting 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 |
|
7 | These 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 |
|
20 | Using 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 |
|
37 | The generated documentation can be internationalized. Select the language you want to use for the output using the `-l` parameter.
|
38 |
|
39 | Supported languages are:
|
40 | - English
|
41 | - German
|
42 |
|
43 | If 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
|
53 | In 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 | ## Using JSON Schema Markdown Tools from `npm`
|
61 |
|
62 | You 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`
|
63 |
|
64 | ```json
|
65 | "devDependencies": {
|
66 | "@adobe/jsonschema2md": "^4.0.0"
|
67 | }
|
68 | ```
|
69 |
|
70 | Then add the following to the `"scripts"` section of your `package.json` and adapt accordingly:
|
71 |
|
72 | ```json
|
73 | "scripts": {
|
74 | "prepare": "mkdir -p docs/reference && jsonschema2md -o docs/reference -d schemas/draft-04
|
75 | }
|
76 | ```
|
77 |
|
78 | If 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.
|
79 |
|
80 | ## Tests
|
81 |
|
82 | Ensure you have all the dependencies installed via `npm install`, then run:
|
83 |
|
84 | ```bash
|
85 | npm test
|
86 | ```
|
87 |
|
88 | This will run our Jasmine test suite as well as lint the JavaScript according to our style guide (see below).
|
89 |
|
90 | ### CI
|
91 |
|
92 | Continuous integration runs on [CircleCI](https://circleci.com/gh/adobe/jsonschema2md).
|
93 | All pull requests automatically trigger a job that runs the [tests](#tests) by executing the [`config.yml`](.circleci/config.yml).
|
94 |
|
95 | ### Code Coverage
|
96 |
|
97 | `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.
|
98 |
|
99 | ## Style Guide / Linting
|
100 |
|
101 | This project uses [eslint](https://eslint.org) to enforce JavaScript coding style. To run the linter:
|
102 |
|
103 | ```bash
|
104 | npm run lint
|
105 | ```
|
106 |
|
107 | ## TODOs
|
108 |
|
109 | Add support for [missing keywords](schemasupport.md)
|
110 |
|
111 | ## Contributing
|
112 |
|
113 | Please see [Contributing.md](Contributing.md) for details. Pull requests are welcome.
|
114 |
|
115 | ## License/Copyright
|
116 |
|
117 | Copyright 2017 Adobe Systems Incorporated. All rights reserved.
|
118 | This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
119 | you may not use this file except in compliance with the License. You may obtain a copy
|
120 | of the License at http://www.apache.org/licenses/LICENSE-2.0
|