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.
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.
Using the schemas in examples/schemas (note the *.schema.json extension), the output in examples/docs has been generated.
Installing and running
$ npm install -g @adobe/jsonschema2md
# show usage information
$ jsonschema2md
# run task
$ jsonschema2md -d examples/schemas -o examples/docs
# generated output for whole folder is written to ./examples/docs
By default, jsonschema2md looks for schema files ending in *.schema.json. You can specify another extension by using the --schema-extension or -e command line argument.
Internationalization
The generated documentation can be internationalized. Select the language you want to use for the output using the -l parameter.
Display custom attributes in the property description
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.
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.
# run against JSON Schema Draft 06
$ jsonschema2md -d examples/schemas -o examples/docs -v 06 -h false
Examples as YAML
If 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.
Using JSON Schema Markdown Tools from npm
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
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.
Please see Contributing.md for details. Pull requests are welcome.
License/Copyright
Copyright 2017 Adobe Systems Incorporated. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
请发表评论