https://github.com/figadore/json-schema-generator
https://github.com/figadore/json-schema-generator
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/figadore/json-schema-generator
- Owner: figadore
- Created: 2016-07-25T19:19:41.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-10-13T22:00:57.000Z (almost 10 years ago)
- Last Synced: 2025-04-10T05:12:27.731Z (over 1 year ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#JSON Schema Generator
Generate/compile .yaml files (not .yml at the moment) into a single JSON schema file. Resolves references to other schema docuements in the same directory
Requires Node >= 5.0
## Usage
### cli
```
npm install -g @shinymayhem/json-schema-generator
schemagen ./schemas/car.yaml
```
### module
```
var generator = require("@shinymayhem/json-schema-generator");
generator.generate('test/data/car.yaml', function onGenerated(err, schema) {
if (err) {
throw err;
}
console.log(schema);
});
```
## Examples
### Input
window.yaml
```
---
$schema: http://json-schema.org/draft-04/hyper-schema
id: window
title: Window
strictProperties: true
additionalProperties: false
definitions:
style:
type:
- string
enum:
- georgian
- center bar
type:
- object
required:
- size
- style
properties:
style:
$ref: window#/definitions/style
size:
$ref: size
```
size.yaml
```
---
$schema: http://json-schema.org/draft-04/hyper-schema
id: size
title: Size
description: Length and width
strictProperties: true
additionalProperties: false
definitions:
width:
type: integer
minimum: 1
maximum: 100
height:
type: integer
minimum: 1
maximum: 100
units:
type: string
enum:
- inches
- centimeters
type:
- object
required:
- width
- height
- units
properties:
height:
$ref: size#/definitions/height
width:
$ref: size#/definitions/width
units:
$ref: size#/definitions/units
```
### Run it
```
schemagen ./window.yaml
```
### Output
```
{
"$schema":"http://json-schema.org/draft-04/hyper-schema",
"id":"window",
"title":"Window",
"strictProperties":true,
"additionalProperties":false,
"definitions":{
"style":{
"type":[
"string"
],
"enum":[
"georgian",
"center bar"
]
},
"size":{
"$schema":"http://json-schema.org/draft-04/hyper-schema",
"id":"size",
"title":"Size",
"description":"Length and width",
"strictProperties":true,
"additionalProperties":false,
"definitions":{
"width":{
"type":"integer",
"minimum":1,
"maximum":100
},
"height":{
"type":"integer",
"minimum":1,
"maximum":100
},
"units":{
"type":"string",
"enum":[
"inches",
"centimeters"
]
}
},
"type":[
"object"
],
"required":[
"width",
"height",
"units"
],
"properties":{
"height":{
"$ref":"#/definitions/size/definitions/height"
},
"width":{
"$ref":"#/definitions/size/definitions/width"
},
"units":{
"$ref":"#/definitions/size/definitions/units"
}
}
}
},
"type":[
"object"
],
"required":[
"size",
"style"
],
"properties":{
"style":{
"$ref":"#/definitions/style"
},
"size":{
"$ref":"#/definitions/size"
}
}
}
```
### Valid data
```
{
"style": "georgian",
"size": {
"width": 32,
"height": 32,
"units": "inches"
}
}
```
Alternatively, see 'test/data' dir for example schema files