Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xtx1130/jsonschema-decorator
jsonschema decorator
https://github.com/xtx1130/jsonschema-decorator
Last synced: about 1 month ago
JSON representation
jsonschema decorator
- Host: GitHub
- URL: https://github.com/xtx1130/jsonschema-decorator
- Owner: xtx1130
- License: mit
- Created: 2017-10-30T02:33:57.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-03T08:01:24.000Z (over 6 years ago)
- Last Synced: 2024-11-15T22:43:06.310Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 49.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
### jsonSchema-decorator
> a decorator for jsonSchema
[![Build Status](https://travis-ci.org/xtx1130/jsonschema-decorator.svg?branch=master)](https://travis-ci.org/xtx1130/jsonschema-decorator) [![Coverage Status](https://coveralls.io/repos/github/xtx1130/jsonschema-decorator/badge.svg?branch=master)](https://coveralls.io/github/xtx1130/jsonschema-decorator?branch=master)
#### UsageInstall code:
```js
npm install jsonschema-decorator
```
You need to establish a folder in your project root dir:
```shell
$/projectRootDir mkdir mock-decorators
chmod -R 777 mock-decorators
```
or you can use `package.json` to config a folder that jsonSchema will read:
```json
// package.json
{
"jsonSchema": {
"path": "The schema path you want"
}
}
```Then, you can create js schema roles in dirctory mock-decorator,eg:
```code
mock-decorator/----common/(write common rules in here)
|
|--schema.js(write unique rules in js files)
|--folders/(you can also create more folders to save js files)
|
|--otherschema.js(other unique rules)
```
There is and example for jsonschema-decorator:
```js
//schema.js
'use strict';
require('./common/person');//This is a common schemaexports = module.exports = {//This is the unique schema
"id": "/jsontest",
"type": "object",
"properties": {
"test": {
"type": "boolean",
"required": "true"
},
"name": {
"type": "string",
"required": "true"
},
"params": {
"$ref": "/jsonTestParam"
}
}
}//index.js
const jd = require('jsonschema-decorator');
@jd.jsontest
class jsonTest {
constructor(){
this.val = {
test:true,
name:'xtx',
params:{
sex:'male',
age:25
}
}
}
}
router.get('/jsontest',async (ctx,next) => {
ctx.set('Content-Type','application/json');
let jsonT = new jsonTest();//new Object in here
let json = jsonT.getVal();//get the schema value,if passed on ,it will return the mock json,else it will return a json contains the mistake
ctx.body = jsonp(json);//use the json
});
```
for more example,please see the [test case](https://github.com/xtx1130/jsonschema-decorator/blob/master/test/server.js)#### LICENSE
MIT