https://github.com/regular/get-properties-from-schema
https://github.com/regular/get-properties-from-schema
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/regular/get-properties-from-schema
- Owner: regular
- Created: 2018-12-04T10:54:39.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-04T10:58:35.000Z (over 7 years ago)
- Last Synced: 2025-04-24T04:43:27.530Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 1000 Bytes
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
```
const getProperties = require('get-properties-from-schema')
const schema = {
"description": "A 2D/3D rectangle or box with position, anchor (origin) and rotation",
"type": "object",
"required": [
"size",
"type"
],
"properties": {
"type": {
"const": "transform"
},
"size": {
"$ref": "#/definitions/vec3f"
}
},
"definitions": {
"vec3f": {
"type": "object",
"required": [
"x",
"y"
],
"properties": {
"x": {
"type": "number"
},
"y": {
"type": "number"
}
}
}
}
}
test('get root properties', t => {
const props = getProperties(schema)
t.equal(props.length, 2)
t.deepEqual(props[0], {key: 'type', value: {"const": "transform"}})
t.deepEqual(props[1], {key: 'size', value: schema.definitions.vec3f})
console.log(props[1])
const size_props = getProperties(props[1].value)
t.equal(size_props.length, 2)
t.deepEqual(size_props[0], {key: 'x', value: {type: 'number'}})
t.deepEqual(size_props[1], {key: 'y', value: {type: 'number'}})
t.end()
})
```
Note: Only local $ref references are supported