Reputation: 195
I'm trying to find the solution to add extra field to the existing json schema in a new json schema file, and generate them in github pipeline and the project can use them. But I'm not sure how to do it. for example, the existing schema below:
{
type: 'object',
required: [ 'product' ],
additionalProperties: false,
properties: {
productName: {
enum: [ 'product1', 'product2', 'product3' ],
},
price: { type: 'int' },
},
};
But know I want to add more fields in properties in additional json, how do I do it? for example I need product quantity
now, so I can compile two json schema and form one complete class. Also is it possible to reference definition from other schema or I always have to define them respectively.
Very much appreciated if you could help me out.
Upvotes: 0
Views: 170
Reputation: 195
I used js and Lodash to merge two scheme files into one, it works like magic.
const _ = require("lodash");
const schema = require('./schema.json');
const extention = require("./extentions.json", 'utf-8');
var newschema = _.merge(schema, extention);
const fs = require('fs')
fs.writeFile("./newschema.json", JSON.stringify(newschema, null, 4), (err) =>
{
if (err) throw err;
});
Upvotes: 1