tv4
tv4 copied to clipboard
minor issue: wrong subErrors when validating oneOf
Merry Christmas in advance !
Taken the sample from below (WIP) try to change the postalCode in the data
to something invalid.
The subErrors array also has a message
No enum match for: "CAN"
var data = {
"name": "Ed",
"co": "",
"number": "44",
"street": "xstr",
"street2": "",
"city": "xc",
"national": {
"country": "CAN",
"province": "AB",
"postalCode": "M4B1B3"
}
};
var v = tv4.validate(data, {
"$schema": "http://json-schema.org/draft-04/hyper-schema#",
"title": "Address",
"description": "An internationalized postal address",
"definitions": {
"name": {"type": "string"},
"co": {"type": "string"},
"number": {"type": "string"},
"street": {"type": "string"},
"street2": {"type": "string"},
"city": {"type": "string"},
"CAN": {
"definitions": {
"country": {"type": "string", "enum": ["CAN"]},
"province": {
"type": "string",
"enum": ["AB", "BC", "MB", "NB", "NL", "NS", "NT", "NU", "ON", "PE", "QC", "SK", "YT"]
},
"postalCode": {"type": "string", "pattern": "^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$"}
},
"properties": {
"country": {"title": "Country", "$ref": "#/definitions/CAN/definitions/country"},
"province": {"title": "Province", "$ref": "#/definitions/CAN/definitions/province"},
"postalCode": {"title": "Postal Code", "$ref": "#/definitions/CAN/definitions/postalCode"}
},
"type":"object",
"additionalProperties": false,
"required": ["country", "province", "postalCode"]
},
"DEU": {
"definitions": {
"country": {"type": "string", "enum": ["DEU"]},
"province": {
"type": "string",
"enum": ["BW", "BY", "BE", "BB", "HB", "HH", "HE", "MV", "NI", "NW", "RP", "SL", "SN", "ST", "SH", "TH"]
},
"postalCode": {"type": "string", "pattern":"^[0-9]{5}$"}
},
"properties": {
"country": {"title": "Country", "$ref": "#/definitions/DEU/definitions/country"},
"province": {"title": "State", "$ref": "#/definitions/DEU/definitions/province"},
"postalCode": {"title": "Postal Code", "$ref": "#/definitions/DEU/definitions/postalCode"}
},
"type":"object",
"additionalProperties": false,
"required": ["country", "postalCode"]
},
"MEX": {
"definitions": {
"country": {"type":"string", "enum":["MEX"]},
"province": {
"type":"string",
"enum": ["AGS", "BC", "BCS", "CAM", "COAH", "COL", "CHIH", "CHIS", "DF", "DGO", "GTO", "GRO", "HGO", "JAL", "MEX", "MICH",
"MOR", "NAY", "NL", "OAX", "PUE", "QRO", "Q ROO", "SLP", "SIN", "SON", "TAB", "TAMPS", "TLAX", "VER", "YUC", "ZAC"]
},
"postalCode": {"type": "string", "pattern":"^[0-9]{5}$"}
},
"properties": {
"country": {"title": "Country", "$ref": "#/definitions/MEX/definitions/country"},
"province": {"title": "State", "$ref": "#/definitions/MEX/definitions/province"},
"postalCode": {"title": "Postal Code", "$ref": "#/definitions/MEX/definitions/postalCode"}
},
"type":"object",
"additionalProperties": false,
"required": ["country", "province", "postalCode"]
},
"USA": {
"definitions": {
"country": {"type":"string", "enum":["USA"]},
"province": {
"type": "string",
"enum": ["AL", "AK", "AR", "AS", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "FM", "GA", "GU", "HI", "IA",
"ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MH", "MI", "MN", "MO", "MP", "MS", "MT",
"NC", "ND", "NE", "NH", "NJ", "NM", "NV", "OH", "OK", "OR", "PA", "PR", "PW", "RI", "SC", "SD",
"TN", "TX", "UT", "VA", "VI", "VT", "WA", "WI", "WV", "WY", "AA", "AE", "AP"]
},
"postalCode": {"type":"string", "pattern":"^[0-9]{5}(-[0-9]{4})?$"}
},
"properties": {
"country": {"title": "Country", "$ref": "#/definitions/USA/definitions/country"},
"province": {"title": "State", "$ref": "#/definitions/USA/definitions/province"},
"postalCode": {"title": "ZIP Code", "$ref": "#/definitions/USA/definitions/postalCode"}
},
"type":"object",
"additionalProperties": false,
"required": ["country", "province", "postalCode"]
}
},
"properties": {
"name": {
"title": "Name",
"$ref": "#/definitions/name"
},
"co": {
"title": "c/o",
"$ref": "#/definitions/co"
},
"number": {
"title": "Number",
"$ref": "#/definitions/number"
},
"street": {
"title": "Street",
"$ref": "#/definitions/street"
},
"street2": {
"title": "Street extension",
"$ref": "#/definitions/street2"
},
"city": {
"title": "City",
"$ref": "#/definitions/city"
},
"national" : {
"oneOf": [
{"$ref": "#/definitions/CAN"},
{"$ref": "#/definitions/DEU"},
{"$ref": "#/definitions/MEX"},
{"$ref": "#/definitions/USA"}
]
}
},
"type":"object",
"additionalProperties": false,
"required": ["name", "number", "street", "city", "national"]
}, true, true);