Gathering detailed insights and metrics for @stoplight/json-schema-generator
Gathering detailed insights and metrics for @stoplight/json-schema-generator
Gathering detailed insights and metrics for @stoplight/json-schema-generator
Gathering detailed insights and metrics for @stoplight/json-schema-generator
npm install @stoplight/json-schema-generator
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
10 Stars
139 Commits
1 Forks
2 Watching
6 Branches
55 Contributors
Updated on 17 Apr 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-13.7%
19,642
Compared to previous day
Last week
5.4%
114,632
Compared to previous week
Last month
11.7%
489,195
Compared to previous month
Last year
78.7%
4,443,397
Compared to previous year
JSON schema generated based on draft-v4 of the specification. Note that the full spec if not yet supported. The compiler will be enhanced to support as much as possible. More specifically, there's no support for $ref nodes or special nodes like location (lat, long), etc. These features will be added in future releases or you can always fork and make it better :-)
1git clone https://github.com/krg7880/json-schema-generator 2cd json-schema-generator 3npm install .
Run on the command line:
1npm install -g json-schema-generator
Then use (for example):
1#### JSON PATH 2json-schema-generator path/to/input.json -o path/to/output.json 3#### JSON URL 4json-schema-generator https://sample.com/path/to/input.json --jsondir ./source/backup -o ./path/to/dir/ 5#### JSON STDIN | STDOUT 6cat input.json | json-schema-generator > output.json
Run on the command line:
1npm install json-schema-generator --save-dev
Then, in your project:
1var jsonSchemaGenerator = require('json-schema-generator'), 2 obj = { some: { object: true } }, 3 schemaObj; 4 5schemaObj = jsonSchemaGenerator(json);
Usage: json-schema-generator [<target>|--url <url>|--file <file>|--stdin]
If <target> is specified, it is interpreted as follows: a protocol (like http://)
means url; anything else is treated as path to a local file.
If no input file is specified and stdin is provided, stdin is used.
Options:
--stdin Use stdin as input.
--url Remote json document to use as input.
--file Local json document to use as input.
--schemadir, -o Directory (or file, if ending with .json) where the schema will
be stored.
--jsondir Directory (or file, if ending with .json) where the source
document is copied to. Useful with --url.
--pretty Whether to use pretty json format. Use --no-pretty for false.
[default: true]
--force, -f If a destination file already exists, overwrite it.
--help, -h Show this help text.
1{ 2 "title": "fresh fruit schema v1", 3 "type": "object", 4 "required": ["skin", "colors", "taste"], 5 "properties": { 6 "colors": { 7 "type": "array", 8 "minItems": 1, 9 "uniqueItems": true, 10 "items": { 11 "type": "string" 12 } 13 }, 14 "skin": { 15 "type": "string" 16 }, 17 "taste": { 18 "type": "number", 19 "minimum": 5 20 } 21 } 22}
1{ 2 "$schema": "http://json-schema.org/draft-04/schema#", 3 "description": "", 4 "type": "object", 5 "properties": { 6 "title": { 7 "type": "string", 8 "minLength": 1 9 }, 10 "type": { 11 "type": "string", 12 "minLength": 1 13 }, 14 "required": { 15 "type": "array", 16 "items": { 17 "required": [ 18 19 ], 20 "properties": { 21 22 } 23 } 24 }, 25 "properties": { 26 "type": "object", 27 "properties": { 28 "colors": { 29 "type": "object", 30 "properties": { 31 "type": { 32 "type": "string", 33 "minLength": 1 34 }, 35 "minItems": { 36 "type": "number" 37 }, 38 "uniqueItems": { 39 "type": "boolean" 40 }, 41 "items": { 42 "type": "object", 43 "properties": { 44 "type": { 45 "type": "string", 46 "minLength": 1 47 } 48 }, 49 "required": [ 50 "type" 51 ] 52 } 53 }, 54 "required": [ 55 "type", 56 "minItems", 57 "uniqueItems", 58 "items" 59 ] 60 }, 61 "skin": { 62 "type": "object", 63 "properties": { 64 "type": { 65 "type": "string", 66 "minLength": 1 67 } 68 }, 69 "required": [ 70 "type" 71 ] 72 }, 73 "taste": { 74 "type": "object", 75 "properties": { 76 "type": { 77 "type": "string", 78 "minLength": 1 79 }, 80 "minimum": { 81 "type": "number" 82 } 83 }, 84 "required": [ 85 "type", 86 "minimum" 87 ] 88 } 89 }, 90 "required": [ 91 "colors", 92 "skin", 93 "taste" 94 ] 95 } 96 }, 97 "required": [ 98 "title", 99 "type", 100 "required", 101 "properties" 102 ] 103}
I created this schema generator to validate JSON responses from APIs. As the JSON API is enhanced and nodes are added or removed from the response, the schema is regenerated and validated against the newly deployed API.
To run tests, including fetching documents via HTTP, we've added node-stubby-server-cli to help with serving mock data. The ports for the stub server is defined under test/helpers/stubby-cli, in the event the default port is in use, you can change them there.
1npm install -g stubby
Install mocha globally (as cli) and run
1npm test
JSON documents can be validated against schemas using chai-json-schema. See the tests under test for example usage.
Thanks to those who have contributed. These kind folks are listed below:
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 5/30 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
46 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More