Related
Im trying to create a json schema for following object models. But im getting following error when trying to validate data against the schemas.
should be valid to one and only one of schema, but more than one are valid: {"$ref":"#/$defs/drug-treatment"}{"$ref":"#/$defs/surgery-treatment"}
below is my schema
{
"$id": "someid",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"description": "JSON Schema for treatments",
"oneOf" : [
{ "$ref" : "#/$defs/drug-treatment" },
{ "$ref" : "#/$defs/surgery-treatment" }
],
"$defs": {
"base": {
"type": "object",
"properties": {
"type-tag": {
"enum": [ "SURGERY", "DRUGTREATMENT", "RADIOLOGY", "PHYSIOTHERAPY" ]
},
"id": {
"type": "string",
"format": "uuid"
},
"patient-id": {
"type": "string",
"format": "uuid"
},
"patient-name": {
"type": "string"
},
"provider-id": {
"type": "string",
"format": "uuid"
},
"provider-name": {
"type": "string"
},
"diagnosis": {
"type": "string"
},
"followup-treatments": {
"type" : "array",
"items" : { "$ref" : "#" }
}
},
"required": [
"id",
"type-tag",
"patient-id",
"patient-name",
"provider-id",
"provider-name",
"diagnosis",
"followup-treatments"
]
},
"drug-treatment": {
"allOf": [
{ "$ref" : "#/$defs/base" }
],
"properties": {
"drug": {
"type": "string"
},
"dosage": {
"type": "number"
},
"start-date": {
"type": "string",
"format": "date"
},
"end-date": {
"type": "string",
"format": "date"
},
"frequency": "integer"
},
"required": [
"drug",
"dosage",
"start-date",
"end-date",
"frequency"
],
"unevaluatedProperties" : false
},
"surgery-treatment": {
"allOf": [
{ "$ref" : "#/$defs/base" }
],
"properties": {
"surgery-date": {
"type": "string",
"format": "date"
},
"discharge-instructions": {
"type": "string"
},
"required": [
"surgery-date",
"discharge-instructions"
],
"unevaluatedProperties" : false
}
},
}
}
Here is sample data that im validating agains the schema.
"treatments": [
{
"type-tag": "DRUGTREATMENT",
"drug": "fdsds",
"dosage": 2.0,
"start-date": "2222-02-12",
"end-date": "2222-02-12",
"frequency": 2,
"id": "aa7da984-0252-45b1-b0cd-f1dbe98662e2",
"patient-id": "ab62420e-0bd8-4e39-8e0b-36e464b7abb2",
"patient-name": "Tom",
"provider-id": "154523b2-7598-4ed4-aab1-b2ef1692109c",
"provider-name": "gdsfdsd",
"diagnosis": "sfdsfds",
"followup-treatments": []
},
{
"type-tag": "SURGERY",
"surgery-date": "2222-02-12",
"discharge-instructions": "dsfdsfdsfds",
"id": "12d2e565-8966-4029-840b-1959277b37f6",
"patient-id": "ab62420e-0bd8-4e39-8e0b-36e464b7abb2",
"patient-name": "Tom",
"provider-id": "154523b2-7598-4ed4-aab1-b2ef1692109c",
"provider-name": "gdsfdsd",
"diagnosis": "fdsfds",
"followup-treatments": [],
}
]
but when im validating the type "DRUGTREATMENT" its giving me the error
should be valid to one and only one of schema, but more than one are valid: {"$ref":"#/$defs/drug-treatment"}{"$ref":"#/$defs/surgery-treatment"}
any idea whats Im missing here ?
I made some corrections to your schema but this should work for the sample data from your question. Your schema has some syntax errors and wrongly placed keywords:
{
"$id": "someid",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"description": "JSON schema generated with JSONBuddy https://www.json-buddy.com",
"type": "object",
"properties": {
"treatments": {
"type": "array",
"items": {
"$ref": "#/$defs/treatment-item"
}
}
},
"$defs": {
"treatment-item": {
"oneOf": [
{
"$ref": "#/$defs/drug-treatment"
},
{
"$ref": "#/$defs/surgery-treatment"
}
]
},
"base": {
"type": "object",
"properties": {
"type-tag": {
"enum": [
"SURGERY",
"DRUGTREATMENT",
"RADIOLOGY",
"PHYSIOTHERAPY"
]
},
"id": {
"type": "string",
"format": "uuid"
},
"patient-id": {
"type": "string",
"format": "uuid"
},
"patient-name": {
"type": "string"
},
"provider-id": {
"type": "string",
"format": "uuid"
},
"provider-name": {
"type": "string"
},
"diagnosis": {
"type": "string"
},
"followup-treatments": {
"type": "array",
"items": {
"$ref": "#/$defs/treatment-item"
},
"minItems": 0
}
},
"required": [
"id",
"type-tag",
"patient-id",
"patient-name",
"provider-id",
"provider-name",
"diagnosis",
"followup-treatments"
]
},
"drug-treatment": {
"allOf": [ { "$ref": "#/$defs/base" } ],
"properties": {
"drug": {
"type": "string"
},
"dosage": {
"type": "number"
},
"start-date": {
"type": "string",
"format": "date"
},
"end-date": {
"type": "string",
"format": "date"
},
"frequency": {
"type": "integer"
}
},
"required": [
"drug",
"dosage",
"start-date",
"end-date",
"frequency"
],
"unevaluatedProperties": false
},
"surgery-treatment": {
"allOf": [ { "$ref": "#/$defs/base" } ],
"properties": {
"surgery-date": {
"type": "string",
"format": "date"
},
"discharge-instructions": {
"type": "string"
},
"unevaluatedProperties": false
},
"required": [ "surgery-date", "discharge-instructions" ]
}
}
}
Edit: Showing error message with an arbitrary additional property.
I am trying to define a json schema which has a common enum type for a number of objects and then depending on which enum is selected, define the possible combinations of enums and also additional elements that are needed.
The example has FurnitureData with {IDNumber, Color, Furniture Type} and then depending on the Type selected from a enum list, gets a function assigned with different enums. I also put in an example of "Person assigned" as an extra element.
I think I did this correctly using anyof and const. But, when I test with XMLSpy Pro 2020, it generates invalid json examples and also when I try to validate an invalid example, it passes.... so, 1) did I express this well ? 2) what am I doing wrong ? 3) is there a better way ? 4) Is it the tool or the json schema ?
Please help.
JSON Schema :
{
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Comment describing your JSON Schema",
"type": "object",
"properties": {
"FurnitureData": {
"type": "array",
"items": {
"type": "object",
"properties": {
"IDNumber": {
"type": "object",
"description": "Unique identifier",
"required": [
"value"
],
"properties": {
"value": {
"type": "string",
"maxLength": 16
},
"readOnly": {
"type": "boolean",
"default": true
}
}
},
"Color": {
"type": "object",
"description": "Preferred color",
"required": [
"value"
],
"properties": {
"value": {
"type": "string",
"default": "WOOD",
"enum": [
"BLUE",
"WOOD",
"GREEN"
]
},
"custom value": {
"type": "string",
"maxLength": 32
}
}
},
"Furniture Type": {
"type": "object",
"description": "Kind of Furniture",
"required": [
"value"
],
"properties": {
"value": {
"type": "string",
"default": "CHAIR",
"enum": [
"LAMP",
"TABLE",
"CHAIR"
]
},
"custom value": {
"type": "string",
"maxLength": 32
}
}
}
},
"required": [
"IDNumber",
"Color",
"Furniture Type"
],
"anyOf": [
{
"properties": {
"Furniture Type": {
"value": {
"const": "LAMP"
}
},
"Function": {
"type": "object",
"description": "Lighting arrangement",
"required": [
"value"
],
"properties": {
"value": {
"type": "string",
"enum": [
"LIGHT ON",
"LIGHT OFF"
]
}
}
}
},
"required": [
"Furniture Type",
"Function"
]
},
{
"properties": {
"Furniture Type": {
"value": {
"const": "TABLE"
}
},
"Function": {
"type": "object",
"description": "Size of table",
"required": [
"value"
],
"properties": {
"value": {
"type": "string",
"enum": [
"3' x 4'",
"6' x 4'",
"12' x 4'",
"10' round"
]
}
}
}
},
"required": [
"Furniture Type",
"Function"
]
},
{
"properties": {
"Furniture Type": {
"value": {
"const": "CHAIR"
}
},
"Function": {
"type": "object",
"description": "Planned use",
"required": [
"value"
],
"properties": {
"value": {
"type": "string",
"enum": [
"WORKSPACE SEAT",
"SPARE SEAT"
]
}
}
},
"Person assigned": {
"type": "object",
"description": "Seating assignment",
"required": [
"value"
],
"properties": {
"value": {
"type": "string"
}
}
}
},
"required": [
"Furniture Type",
"Function",
"Person assigned"
]
}
]
}
}
},
"required": [
"FurnitureData"
]
}
Invalid JSON Example that XMLSpy validates as okay: (it is linked to my schema in the info page)
Lamps should not allow 6x4 as a function...
{
"FurnitureData": [
{
"Color": {
"value": "WOOD",
"readOnly": "a",
"custom value": "a"
},
"IDNumber": {
"value": "a",
"readOnly": true
},
"Furniture Type": {
"value": "LAMP",
"custom value": "a"
},
"Function": {
"value": "6' x 4'",
"custom value": "a"
}
}
]
}
Another Invalid example... Chairs have "Person assigned" and the wrong type value is shown but this validates too...
{
"FurnitureData": [
{
"Color": {
"value": "WOOD",
"readOnly": "a",
"custom value": "a"
},
"IDNumber": {
"value": "a",
"readOnly": true
},
"Furniture Type": {
"value": "CHAIR",
"custom value": "a"
},
"Function": {
"value": "6' x 4'",
"custom value": "a"
}
}
]
}
This is following the recommendation in
See enum section using anyof
Maybe I must use an if-then construct ? Here, I tried with if-then in the any-of but I also get validations of json that allow enums from the other furniture types...
{
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Comment describing your JSON Schema",
"type": "object",
"properties": {
"FurnitureData": {
"type": "array",
"items": {
"type": "object",
"properties": {
"IDNumber": {
"type": "object",
"description": "Unique identifier",
"required": [
"value"
],
"properties": {
"value": {
"type": "string",
"maxLength": 16
},
"readOnly": {
"type": "boolean",
"default": true
}
}
},
"Color": {
"type": "object",
"description": "Preferred color",
"required": [
"value",
"readOnly"
],
"properties": {
"value": {
"type": "string",
"default": "WOOD",
"enum": [
"BLUE",
"WOOD",
"GREEN"
]
},
"custom value": {
"type": "string",
"maxLength": 32
}
}
},
"Furniture Type": {
"type": "object",
"description": "Kind of Furniture",
"required": [
"value"
],
"properties": {
"value": {
"type": "string",
"default": "CHAIR",
"enum": [
"LAMP",
"TABLE",
"CHAIR"
]
},
"custom value": {
"type": "string",
"maxLength": 32
}
}
}
},
"required": [
"IDNumber",
"Color",
"Furniture Type"
],
"anyOf": [
{
"if": {
"properties": {
"Furniture Type": {
"value": {
"const": "LAMP"
}
}
}
},
"then": {
"properties": {
"Function": {
"type": "object",
"description": "Lighting arrangement",
"required": [
"value"
],
"properties": {
"value": {
"type": "string",
"enum": [
"LIGHT ON",
"LIGHT OFF"
]
}
}
}
},
"required": [
"Function"
]
}
},
{
"if": {
"properties": {
"Furniture Type": {
"value": {
"const": "TABLE"
}
}
}
},
"then": {
"properties": {
"Function": {
"type": "object",
"description": "Size of table",
"required": [
"value"
],
"properties": {
"value": {
"type": "string",
"enum": [
"3' x 4'",
"6' x 4'",
"12' x 4'",
"10' round"
]
}
}
}
},
"required": [
"Function"
]
}
},
{
"if": {
"properties": {
"Furniture Type": {
"value": {
"const": "CHAIR"
}
}
}
},
"then": {
"properties": {
"Function": {
"type": "object",
"description": "Planned use",
"required": [
"value"
],
"properties": {
"value": {
"type": "string",
"enum": [
"WORKSPACE SEAT",
"SPARE SEAT"
]
}
}
},
"Person assigned": {
"type": "object",
"description": "Seating assignment",
"required": [
"value"
],
"properties": {
"value": {
"type": "string"
}
}
}
},
"required": [
"Function",
"Person assigned"
]
}
}
]
}
}
},
"required": [
"FurnitureData"
]
}
The values of a JSON Schema properties object are subschemas (JSON Schemas in their own right).
Knowing that, if you take your subschema at properties.FurnitureData.anyOf[1].properties['Furniture Type'], and you take that as a schema... it actually doesn't express any constraints.
The subschema at that location from your schema is...
{
"value": {
"const": "TABLE"
}
}
whereas it needs to be...
{
"properties":{
"value": {
"const": "TABLE"
}
}
}
The easiest way to debug this sort of issue is test your assumptions.
You assumed that allOf[1] and allOf[2] should fail, so replace those subschemas with false (booleans are valid schemas).
In doing so, you find out the assumption is wrong, and allOf[1] is valid. Of course you expect the const to be picked up, and therefore this subschema to fail, but it isn't picked up because you were missing properties and value isn't a valid JSON Schema keyword.
You can run these sort of quick tests using https://jsonschema.dev/s/Xt1Yi
How can I make few fields as "required" based on condition?
For example; in below case if status==Failed then i want only four fields as required ("orgId",
"subunitId",
"fundOutType",
"status")
but any other value of status will change the required field list: ("transactionId",
"orgId",
"subunitId",
"fundOutType",
"fundOutAmount",
"status")
My below solution is not working. Please help.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"versionId": "1.0",
"javaInterfaces": [
"java.io.Serializable"
],
"type": "object",
"properties": {
"transactionId": {
"type": "string"
},
"orgId": {
"type": "string"
},
"subunitId": {
"type": "string"
},
"fundOutType": {
"type": "string"
},
"fundOutAmount": {
"type": "string"
},
"status": {
"type": "string"
},
"lang": {
"type": "string"
},
"transactionCreatedDateTime": {
"type": "integer",
"format": "date-time"
},
"userId": {
"type": "string"
}
},
"if": {
"properties": {
"status": {
"const": "Failed"
}
},
"required": [ "status" ]
},
"then": {
"required": [
"orgId",
"subunitId",
"fundOutType",
"status"
]
},
"else": {
"required": [
"transactionId",
"orgId",
"subunitId",
"fundOutType",
"fundOutAmount",
"status"
]
}
}
You can use the oneOf clause instead of the if/else:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"versionId": "1.0",
"javaInterfaces": [
"java.io.Serializable"
],
"type": "object",
"properties": {
"transactionId": {
"type": "string"
},
"orgId": {
"type": "string"
},
"subunitId": {
"type": "string"
},
"fundOutType": {
"type": "string"
},
"fundOutAmount": {
"type": "string"
},
"status": {
"type": "string"
},
"lang": {
"type": "string"
},
"transactionCreatedDateTime": {
"type": "integer",
"format": "date-time"
},
"userId": {
"type": "string"
}
},
"oneOf": [
{
"properties": {
"status": {
"const": "Failed"
}
},
"required": [
"orgId",
"subunitId",
"fundOutType",
"status"
]
},
{
"required": [
"transactionId",
"orgId",
"subunitId",
"fundOutType",
"fundOutAmount",
"status"
]
}
]
}
See documentation https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.9.2.1
Is it possible to make a field required/non-required depending on other field value in JSON schema?
JSON schema contains mode field. If it equals to 'release' or 'debug', the file_path is not required. If it equals to 'custom' it is required.
"mode": {
"enum": [
"debug",
"release",
"custom"
],
"id": "mode",
"required": true,
"type": "string"
},
"file_path": {
"id": "file_path",
"required": false,
"type": "string"
}
There is a solution for JSON Schema draft 7:
{
"build": {
"type": "object",
"id": "build",
"oneOf": [
{
"$ref": "#/definitions/ReleaseDebug"
},
{
"$ref": "#/definitions/Custom"
}
]
}
},
"definitions": {
"ReleaseDebug": {
"required": ["mode"],
"properties": {
"mode": {
"type": "string",
"enum": [
"debug",
"release"
],
"id": "mode"
}
}
},
"Custom": {
"required": ["mode", "file_path"],
"properties": {
"mode": {
"type": "string",
"enum": [
"custom"
],
"id": "mode"
},
"file_path": {
"type": "string",
"id": "file_path"
},
}
}
}
I am running into more children objects that are not validating correctly (object.actor, object.verb, object.object). I tried looking for any empty schema after changing my if/then structures in the object schema to if/then/else adding the false value for each else. I did not find anything obvious.
JSON -Should fail but doesn't
{
"actor": {
"objectType": "Agent",
"name": "xAPI account",
"mbox": "mailto:xapi#adlnet.gov"
},
"verb": {
"id": "http://adlnet.gov/expapi/verbs/attended",
"display": {
"en-GB": "attended",
"en-US": "attended"
}
},
"object": {
"objectType": "SubStatement",
"actor": {
"objectType": "should fail",
"name": "xAPI mbox",
"mbox": "mailto:should fail"
},
"verb": {
"id": "http://adlnet.gov/expapi/verbs/reported",
"display": {
"should fail": "reported",
"en-US": "reported"
}
},
"object": {
"objectType": "Activity",
"id": "should fail"
}
}
}
JSON - Fails at the root level only; substatement values are not checked. assuming empty schema coming from somewhere.
{
"actor": {
"objectType": "Agent",
"name": "xAPI account",
"mbox": "this fails"
},
"verb": {
"id": "http://adlnet.gov/expapi/verbs/attended",
"display": {
"this fails": "attended",
"en-US": "attended"
}
},
"object": {
"objectType": "SubStatement",
"actor": {
"objectType": "should fail",
"name": "xAPI mbox",
"mbox": "mailto:should fail"
},
"verb": {
"id": "http://adlnet.gov/expapi/verbs/reported",
"display": {
"should fail": "reported",
"en-US": "reported"
}
},
"object": {
"objectType": "Activity",
"id": "should fail"
}
}
}
JSON SCHEMA (stripped to the bone)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "xAPIValidator",
"description": "Validation schema for xAPI tests",
"type": "object",
"allOf": [
{
"$ref": "#/definitions/Statement"
},
{
"statements": [
{
"$ref": "#/definitions/Statement"
}
]
}
],
"definitions": {
"Statement": {
"additionalProperties": false,
"properties": {
"objectType": {
"type:": "string",
"enum": [
"Agent",
"Activity",
"Group",
"SubStatement",
"StatementRef"
]
},
"id": {
"allOf": [
{
"$ref": "#/definitions/uuid"
}
]
},
"actor": {
"$id": "#actor",
"allOf": [
{
"$ref": "#/definitions/allOfAgentGroup"
}
]
},
"verb": {
"$id": "#verb",
"type": "object",
"properties": {
"id": {
"allOf": [
{
"$ref": "#/definitions/URI"
}
]
},
"display": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/lang5646"
}
]
}
}
},
"object": {
"$id": "#object",
"type": "object",
"properties": {
"objectType": {
"type:": "string",
"enum": [
"Activity",
"Agent",
"Group",
"SubStatement",
"StatementRef"
]
}
},
"oneOf": [
{
"if": {
"properties": {
"objectType": {
"const": "SubStatement"
}
}
},
"then": {
"$comment": "Substatement object type",
"allOf": [
{
"$ref": "#/definitions/Statement"
}
],
"allOf": [
{
"not": {
"required": [
"id"
]
}
},
{
"not": {
"required": [
"authority"
]
}
},
{
"not": {
"required": [
"stored"
]
}
},
{"required":["actor","verb","object"]}
]
},
"else": false
}
]
}
},
"required": [
"actor",
"verb",
"object"
]
},
"Agent": {
"$id": "#Agent",
"maxProperties": 3,
"allOf": [
{
"$ref": "#/definitions/IFI"
}
]
},
"AnonGroup": {
"$id": "#AnonGroup",
"maxProperties": 3,
"properties": {
"member": {
"type": "array",
"items": [
{
"allOf": [
{
"$ref": "#/definitions/allOfAgentGroup"
}
]
}
]
}
},
"dependencies": {
"objectType": [
"member"
]
},
"required": [
"member"
],
"not": {
"required": [
"mbox"
]
},
"not": {
"required": [
"mbox_sha1sum"
]
},
"not": {
"required": [
"openid"
]
},
"not": {
"required": [
"account"
]
}
},
"IdGroup": {
"$id": "#IdGroup",
"maxProperties": 4,
"properties": {
"member": {
"type": "array",
"items": [
{
"oneOf": [
{
"$ref": "#/definitions/allOfAgentGroup"
}
]
}
]
}
},
"oneOf": [
{
"$ref": "#/definitions/IFI"
}
]
},
"allOfAgentGroup": {
"properties": {
"objectType": {
"type": "string",
"enum": [
"Agent",
"Group"
]
},
"name": {
"type": "string"
}
},
"oneOf": [
{
"if": {
"properties": {
"objectType": {
"const": "Agent"
}
}
},
"then": {
"allOf": [
{
"$ref": "#/definitions/Agent"
}
]
},
"else": false
},
{
"if": {
"properties": {
"objectType": {
"const": "Group"
}
}
},
"then": {
"oneOf": [
{
"allOf": [
{
"$ref": "#/definitions/IdGroup"
}
]
},
{
"allOf": [
{
"$ref": "#/definitions/AnonGroup"
}
]
}
]
},
"else": false
}
]
},
"IFI": {
"oneOf": [
{
"properties": {
"mbox": {
"allOf": [
{
"$ref": "#/definitions/mailto"
}
]
}
},
"required": [
"mbox"
]
},
{
"properties": {
"mbox_sha1sum": {
"type": "string",
"pattern": "\\b[0-9a-f]{5,40}\\b"
}
},
"required": [
"mbox_sha1sum"
]
},
{
"properties": {
"account": {
"properties": {
"homePage": {
"allOf": [
{
"$ref": "#/definitions/URI"
}
]
},
"name": {
"type": "string"
}
},
"required": [
"homePage",
"name"
]
}
},
"required": [
"account"
]
},
{
"properties": {
"openid": {
"allOf": [
{
"$ref": "#/definitions/URI"
}
]
}
},
"required": [
"openid"
]
}
]
},
"mailto": {
"type": "string",
"pattern": "(mailto:)(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")#(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"
},
"URI": {
"type": "string",
"pattern": "^(https?|ftp|file)://[-a-zA-Z0-9+&##/%?=~_|!:,.;]*[-a-zA-Z0-9+&##/%=~_|]"
},
"uuid": {
"type": "string",
"pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
},
"lang5646": {
"type": "object",
"patternProperties": {
"^((?:(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?:([A-Za-z]{2,3}(-(?:[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?:[A-Za-z]{4}))?(-(?:[A-Za-z]{2}|[0-9]{3}))?(-(?:[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-(?:[0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))*(-(?:x(-[A-Za-z0-9]{1,8})+))?)|(?:x(-[A-Za-z0-9]{1,8})+))$": {
"type": "string"
}
},
"additionalProperties": false
},
"lang5646string": {
"type": "string",
"pattern": "^((?:(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?:([A-Za-z]{2,3}(-(?:[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?:[A-Za-z]{4}))?(-(?:[A-Za-z]{2}|[0-9]{3}))?(-(?:[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-(?:[0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))*(-(?:x(-[A-Za-z0-9]{1,8})+))?)|(?:x(-[A-Za-z0-9]{1,8})+))$"
}
}
}
In "$id": "#object" > oneOf > then, you define allOf twice in that JSON object.
The behaviour of duplicate keys in JSON is undefined.
Often the way it's handled is just to take the last occurrence of each key for an object.
You can see this working by having the following schema and an empty object instance: {}
Schema :
{
"allOf": [
false
],
"allOf": [
true
]
}
The JSON library will likely ignore the first allOf, taking the last occurrence, resulting in allways pass validation. Swap the true and false to double confirm.
Any time you've used a specific *of keyword more than once in the same object in the schema (or any key more than once in an object), you'll need to fix it.