在尝试引用2个架构时出错Schema <[object Object]> already exists with different definition
。架构<[object object]>已存在不同定义
请纠正我,如果我做错了什么:在coupons.js
const COUPONS_SCHEMA = {
"id": "/Coupons",
"items": {
"id": "/items",
"properties": {
"Description": {
"type": "string"
},
"Ean": {
"type": "string"
},
"ExpiryDate": {
"type": "string"
},
"Id": {
"type": "string"
},
"Name": {
"type": "string"
},
"StartDate": {
"type": "string"
},
"Type": {
"type": "string"
},
"VoucherValue": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
};
export default COUPONS_SCHEMA;
奖励模式
优惠券模式在rewards.js
const REWARDS_SCHEMA = { "id": "/Rewards", "items": { "id": "/items", "properties": { "PromotionId": { "type": "string" }, "Reward Amount": { "type": "string" }, "RewardType": { "type": "string" } }, "type": "object" }, "type": "array" }; export default REWARDS_SCHEMA;
上午引用定义的模式上述折扣架构
import { Validator } from 'jsonschema'; import Coupons from './coupons'; import Rewards from './rewards'; let validator = new Validator(); const DISCOUNTS_SCHEMA = { "id": "/Discounts", "properties": { "Coupons": { "$ref": "/Coupons" }, "PromotionalClubCardPoints": { "type": "string" }, "Rewards": { "$ref": "/Rewards" }, "StaffDiscount": { "type": "string" }, "StandardClubCardPoints": { "type": "string" }, "TotalClubCardPoints": { "type": "string" }, "TotalCoupons": { "type": "string" }, "TotalGiftCards": { "type": "string" }, "TotalGreenClubCardPoints": { "type": "string" }, "TotalSavings": { "type": "string" }, "TotalVouchers": { "type": "string" } }, "type": "object" }; validator.addSchema(Coupons,'/Discounts'); validator.addSchema(Rewards,'/Discounts'); export default DISCOUNTS_SCHEMA;
and getting the below error throw new Error('Schema <'+schema+'> already exists with different definition'); ^ Error: Schema <[object Object]> already exists with different definition at Validator.addSubSchema (/Users/repo/node_modules/jsonschema/lib/validator.js:72:15) at Validator.addSubSchemaArray (/Users/repo/node_modules/jsonschema/lib/validator.js:99:10) at Validator.addSubSchema (/Users/repo/node_modules/jsonschema/lib/validator.js:80:8) at Validator.addSchema (/Users/repo/node_modules/jsonschema/lib/validator.js:48:8) at Object.<anonymous> (/Users/repo/src/schema/discounts.js:47:11) at Module._compile (module.js:570:32) at loader (/Users/repo/node_modules/babel-register/lib/node.js:144:5) at Object.require.extensions.(anonymous function) [as .js] (/Users/repo/node_modules/babel-register/lib/node.js:154:7) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12)
请纠正我,如果我做错了什么定义模式。
我们可以看看Validator类/函数吗? – Nevosis
验证器功能从'jsonschema'npm包导入 –