Friday, 9 June 2017

Schema <[object Object]> already exists with different definition

Getting Schema <[object Object]> already exists with different definition error while trying to refer 2 schemas in one.

Please correct me if am doing something wrong:

Coupons Schema in 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 Schema in 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;

Am referencing above defined schemas in Discounts 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)

Please correct me if am doing something wrong in defining schemas.



via Sanjeev Murthy

No comments:

Post a Comment