Object creation from separated json schema files

158 views Asked by At

Now I am building node.js app and my needs are:

1.validate&delete props which are unneccesary before routing

app.post('/comments', f_validateAndDeleteUnnecceraryPropsOfRequestBody, function(req, res, next){ ...

2.create objects from json schemas before response

app.post('/comments', f_validateAndDeleteRequestBody, function(req,res,next){
   ...
    res.json(xxxCreateObjectFromJsonSchema('./jsonSchemas/commentAdded.json'))
}

And I want to create separate json schema files like this:

- jsonSchemas/ 
    - def_address.json // address schema definition
    - person.json // ...properties:{ address: { $ref: 'def_address.json#address'} ....
    - ....
    - def_response.json // fixed response schema for every request but will be used in other schemas
    - commentAdded.json // properties:{ $ref: 'def_response.json#response' } 

This way I'm planning to make every object map and when I want to change something that I will have to first change schemas.

0

There are 0 answers