22
33<img align =" right " width =" 100px " height =" 100px " alt =" Swiss Knife " src =" ./knife.svg " >
44
5- A CLI app to find unordered diff between two ` JSON ` documents (based on [ ` swaggest/json-diff ` ] ( https://github.com/swaggest/json-diff ) ), generate JSON Schema and Go/PHP code, pretty print, minify, yaml convert, etc....
5+ A CLI app to find unordered diff between two ` JSON ` documents (based
6+ on [ ` swaggest/json-diff ` ] ( https://github.com/swaggest/json-diff ) ), generate JSON Schema and Go/PHP code, pretty print,
7+ minify, yaml convert, etc....
68
79[ ![ Build Status] ( https://travis-ci.org/swaggest/json-cli.svg?branch=master )] ( https://travis-ci.org/swaggest/json-cli )
810[ ![ Scrutinizer Code Quality] ( https://scrutinizer-ci.com/g/swaggest/json-cli/badges/quality-score.png?b=master )] ( https://scrutinizer-ci.com/g/swaggest/json-cli/?branch=master )
@@ -14,17 +16,20 @@ A CLI app to find unordered diff between two `JSON` documents (based on [`swagge
1416
1517## Purpose
1618
17- * To simplify changes review between two ` JSON ` files you can use a standard ` diff ` tool on rearranged pretty-printed ` JSON ` .
18- * To detect breaking changes by analyzing removals and changes from original ` JSON ` .
19- * To keep original order of object sets (for example ` swagger.json ` [ parameters] ( https://swagger.io/docs/specification/describing-parameters/ ) list).
20- * To make and apply JSON Patches, specified in [ RFC 6902] ( http://tools.ietf.org/html/rfc6902 ) from the IETF.
21- * To convert between YAML/JSON/PHP serialization.
22- * To resolve ` JSON Pointer ` to data.
23- * To resolve ` JSON Pointer ` to file position.
24- * To validate JSON data against [ ` JSON Schema ` ] ( http://json-schema.org/ ) .
25- * To [ generate or update] ( #buildschema ) JSON Schema with instance value(s).
26- * To [ render] ( #gengo ) ` JSON Schema ` as [ ` Go ` ] ( http://golang.org/ ) structure.
27- * To [ render] ( #genphp ) ` JSON Schema ` as ` PHP ` classes.
19+ * To simplify changes review between two ` JSON ` files you can use a standard ` diff ` tool on rearranged
20+ pretty-printed ` JSON ` .
21+ * To detect breaking changes by analyzing removals and changes from original ` JSON ` .
22+ * To keep original order of object sets (for
23+ example ` swagger.json ` [ parameters] ( https://swagger.io/docs/specification/describing-parameters/ ) list).
24+ * To make and apply JSON Patches, specified in [ RFC 6902] ( http://tools.ietf.org/html/rfc6902 ) from the IETF.
25+ * To convert between YAML/JSON/PHP serialization.
26+ * To resolve ` JSON Pointer ` to data.
27+ * To resolve ` JSON Pointer ` to file position.
28+ * To validate JSON data against [ ` JSON Schema ` ] ( http://json-schema.org/ ) .
29+ * To [ generate or update] ( #buildschema ) JSON Schema with instance value(s).
30+ * To [ render] ( #gengo ) ` JSON Schema ` as [ ` Go ` ] ( http://golang.org/ ) structure.
31+ * To [ render] ( #genphp ) ` JSON Schema ` as ` PHP ` classes.
32+ * To [ render] ( #genjsdoc ) ` JSON Schema ` as ` JSDoc ` type definitions.
2833
2934## Installation
3035
6065```
6166
6267Input paths can be .json/.yaml/.yml/.serialized files, file format is detected by file extension:
68+
6369* ` .json ` JSON
6470* ` .yaml ` , ` .yml ` YAML
6571* ` .serialized ` PHP serialization format
@@ -178,7 +184,6 @@ json-cli rearrange tests/assets/original.json tests/assets/new.json --rearrange-
178184> "key5": "wat"
179185```
180186
181-
182187#### Show difference between two JSON documents
183188
184189```
@@ -266,7 +271,8 @@ Options:
266271 --eol Add line break to the output
267272```
268273
269- Bash command to minify all JSON files in current directory.
274+ Bash command to minify all JSON files in current directory.
275+
270276```
271277for f in *.json; do json-cli minify $f --output $f; done
272278```
@@ -348,6 +354,7 @@ Usage:
348354```
349355
350356Example:
357+
351358```
352359json-cli validate-schema tests/assets/sample-data.json tests/assets/sample-schema.json
353360Data is invalid
@@ -386,6 +393,7 @@ Options:
386393```
387394
388395Basic example:
396+
389397```
390398json-cli build-schema tests/assets/original.json
391399
@@ -413,7 +421,7 @@ Usage:
413421 schema Path to JSON schema file
414422
415423Options:
416- --ptr-in-schema <ptrInSchema...> JSON pointers to structure in in root schema, default #
424+ --ptr-in-schema <ptrInSchema...> JSON pointers to structure in root schema, default #
417425 --def-ptr <defPtr...> Definitions pointers to strip from symbol names, default #/definitions
418426 --patches <patches...> JSON patches to apply to schema file before processing, merge patches are also supported
419427 --output <output> Path to output .go file, STDOUT is used by default
@@ -440,6 +448,7 @@ Example:
440448```
441449json-cli gen-go http://json-schema.org/learn/examples/address.schema.json
442450```
451+
443452```
444453// Code generated by github.com/swaggest/json-cli v1.6.3, DO NOT EDIT.
445454
@@ -462,7 +471,7 @@ type Structure struct {
462471}
463472```
464473
465- Advanced example:
474+ Advanced example:
466475
467476```
468477json-cli gen-go "https://raw.githubusercontent.com/asyncapi/asyncapi/2.0.0-rc1/examples/1.2.0/streetlights.yml" \
@@ -555,7 +564,7 @@ Usage:
555564 schema Path to JSON schema file
556565
557566Options:
558- --ptr-in-schema <ptrInSchema...> JSON pointers to structure in in root schema, default #
567+ --ptr-in-schema <ptrInSchema...> JSON pointers to structure in root schema, default #
559568 --def-ptr <defPtr...> Definitions pointers to strip from symbol names, default #/definitions
560569 --patches <patches...> JSON patches to apply to schema file before processing, merge patches are also supported
561570 --ns <ns> Namespace to use for generated classes, example \MyClasses
@@ -568,7 +577,7 @@ Options:
568577 --build-additional-properties-accessors Build accessors for additionalProperties
569578```
570579
571- Advanced example:
580+ Advanced example:
572581
573582```
574583mkdir ./StreetLights
@@ -698,3 +707,44 @@ class TurnOnOffPayload extends ClassStructure
698707 }
699708}
700709```
710+
711+ #### <a name =" genjsdoc " ></a > Generate ` JSDoc ` type definitions from ` JSON Schema ` .
712+
713+ ```
714+ v1.8.4 json-cli gen-jsdoc
715+ JSON CLI tool, https://github.com/swaggest/json-cli
716+ Generate JSDoc code from JSON schema
717+ Usage:
718+ json-cli gen-jsdoc <schema>
719+ schema Path to JSON schema file
720+
721+ Options:
722+ --ptr-in-schema <ptrInSchema...> JSON pointers to structure in root schema, default #
723+ --def-ptr <defPtr...> Definitions pointers to strip from symbol names, default #/definitions
724+ --patches <patches...> JSON patches to apply to schema file before processing, merge patches are also supported
725+ ```
726+
727+ Example:
728+
729+ ```
730+ json-cli gen-jsdoc "https://raw.githubusercontent.com/asyncapi/asyncapi/2.0.0-rc1/examples/1.2.0/streetlights.yml" \
731+ --ptr-in-schema "#/components/messages/lightMeasured/payload" "#/components/messages/turnOnOff/payload" \
732+ --def-ptr "#/components/schemas"
733+ ```
734+
735+ ```
736+ /**
737+ * @typedef ComponentsMessagesLightMeasuredPayload
738+ * @type {object}
739+ * @property {number} lumens - Light intensity measured in lumens.
740+ * @property {string} sentAt - Date and time when the message was sent.
741+ */
742+
743+ /**
744+ * @typedef ComponentsMessagesTurnOnOffPayload
745+ * @type {object}
746+ * @property {string} command - Whether to turn on or off the light.
747+ * @property {string} sentAt - Date and time when the message was sent.
748+ */
749+
750+ ```
0 commit comments