Related
I have a requirement to put a check on value based on certain other attribute value in same object (both of them are inside list ) e.g paymentType is SHOPPING_CARDS, I want to mandate few attributes i.e paymentReference1 , paymentReference2 otherwise not. I have added this check , I am passing paymentType as CASH but still getting false error that required attributes are missing , though paymentId1 is being passed in all the items in list. Can someone please help to find out what I am doing wrong?
Failing Impl
Error
$.paymentReference1: is missing but it is required
Update- As per one comment below , I have moved if/else in schema where this check is required but now issue is it is not raising any alarm when we remove paymentRef.
Json Schema
{
"type": "object",
"required": [
"payment"
],
"properties": {
"payment": {
"$id": "#root/payment",
"title": "Payment",
"type": "object",
"required": [
"requestId",
"requestTimestamp",
"requestType",
"orderNo",
"orderDate",
"enterpriseCode",
"documentType",
"entryType",
"paymentRuleId",
"membershipNo",
"orderTotalAmount",
"priceInfo",
"paymentMethods",
"createServiceId"
],
"properties": {
"requestId": {
"$id": "#root/payment/requestId",
"title": "Requestid",
"type": "string",
"default": "",
"examples": [
"263e9575-09ea-45dc-b1d9-87ec7888d3ff"
],
"pattern": "^.*$"
},
"requestTimestamp": {
"$id": "#root/payment/requestTimestamp",
"title": "Requesttimestamp",
"type": "string",
"default": "",
"examples": [
"2021-12-01T07:16:31Z"
],
"pattern": "^.*$"
},
"requestType": {
"$id": "#root/payment/requestType",
"title": "Requesttype",
"type": "string",
"default": "",
"examples": [
"CREATE_ORDER/ADDITION"
],
"pattern": "^.*$"
},
"orderNo": {
"$id": "#root/payment/orderNo",
"title": "Orderno",
"type": "string",
"default": "",
"examples": [
"9762909359"
],
"pattern": "^.*$"
},
"orderDate": {
"$id": "#root/payment/orderDate",
"title": "Orderdate",
"type": "string",
"default": "",
"examples": [
"2022-05-09T14:01:21.000+0000"
],
"pattern": "^.*$"
},
"enterpriseCode": {
"$id": "#root/payment/enterpriseCode",
"title": "Enterprisecode",
"type": "string",
"default": "",
"examples": [
"SAMS"
],
"pattern": "^.*$"
},
"documentType": {
"$id": "#root/payment/documentType",
"title": "Documenttype",
"type": "string",
"default": "",
"examples": [
"0001"
],
"pattern": "^.*$"
},
"entryType": {
"$id": "#root/payment/entryType",
"title": "Entrytype",
"type": "string",
"default": "",
"examples": [
"ONLINE"
],
"pattern": "^.*$"
},
"paymentRuleId": {
"$id": "#root/payment/paymentRuleId",
"title": "Paymentruleid",
"type": "string",
"default": "",
"examples": [
"SAMS"
],
"pattern": "^.*$"
},
"membershipNo": {
"$id": "#root/payment/membershipNo",
"title": "Membershipno",
"type": "string",
"default": "",
"examples": [
"10142100469959798"
],
"pattern": "^.*$"
},
"orderTotalAmount": {
"$id": "#root/payment/orderTotalAmount",
"title": "Ordertotalamount",
"type": "string",
"default": "",
"examples": [
""
],
"pattern": "^.*$"
},
"priceInfo": {
"$id": "#root/payment/priceInfo",
"title": "Priceinfo",
"type": "object",
"required": [
"currency",
"enterpriseCurrency"
],
"properties": {
"currency": {
"$id": "#root/payment/priceInfo/currency",
"title": "Currency",
"type": "string",
"default": "",
"examples": [
"USD"
],
"pattern": "^.*$"
},
"enterpriseCurrency": {
"$id": "#root/payment/priceInfo/enterpriseCurrency",
"title": "Enterprisecurrency",
"type": "string",
"default": "",
"examples": [
"USD"
],
"pattern": "^.*$"
}
}
},
"paymentMethods": {
"$id": "#root/payment/paymentMethods",
"title": "Paymentmethods",
"type": "array",
"default": [
],
"items": {
"$id": "#root/payment/paymentMethods/items",
"title": "Items",
"type": "object",
"required": [
"sequenceNo",
"customerPONo",
"displaySvcNo",
"maxChargeLimit",
"paymentType",
"svcNo",
"unlimitedCharges",
"paymentDetails"
],
"properties": {
"sequenceNo": {
"$id": "#root/payment/paymentMethods/items/sequenceNo",
"title": "Sequenceno",
"type": "string",
"default": "",
"examples": [
"1"
],
"pattern": "^.*$"
},
"customerPONo": {
"$id": "#root/payment/paymentMethods/items/customerPONo",
"title": "Customerpono",
"type": "string",
"default": "",
"examples": [
"0"
],
"pattern": "^.*$"
},
"displaySvcNo": {
"$id": "#root/payment/paymentMethods/items/displaySvcNo",
"title": "Displaysvcno",
"type": "string",
"default": "",
"examples": [
"719"
],
"pattern": "^.*$"
},
"maxChargeLimit": {
"$id": "#root/payment/paymentMethods/items/maxChargeLimit",
"title": "Maxchargelimit",
"type": "number",
"examples": [
159.27
],
"default": 0.0
},
"paymentId1": {
"$id": "#root/payment/paymentMethods/items/paymentReference1",
"type": "string",
"default": "",
"examples": [
"T4543F/JCgkLnk6OT4qJ/hc+sg=="
],
"pattern": "^.*$"
},
"paymentId2": {
"$id": "#root/payment/paymentMethods/items/paymentReference2",
"title": "Paymentreference2",
"type": "string",
"default": "",
"examples": [
"ebdbbf2f-aec1-414a-a8b7-ec33de993c02"
],
"pattern": "^.*$"
},
"paymentId3": {
"$id": "#root/payment/paymentMethods/items/paymentReference3",
"title": "Paymentreference3",
"type": "string",
"default": "",
"examples": [
"Regular"
],
"pattern": "^.*$"
},
"paymentType": {
"$id": "#root/payment/paymentMethods/items/paymentType",
"title": "Paymenttype",
"type": "string",
"default": "",
"examples": [
"CASH"
],
"pattern": "^.*$"
},
"svcNo": {
"$id": "#root/payment/paymentMethods/items/svcNo",
"title": "Svcno",
"type": "string",
"default": "",
"examples": [
"6194995892193728"
],
"pattern": "^.*$"
},
"unlimitedCharges": {
"$id": "#root/payment/paymentMethods/items/unlimitedCharges",
"title": "Unlimitedcharges",
"type": "string",
"default": "",
"examples": [
"N"
],
"pattern": "^.*$"
},
"paymentDetails": {
"$id": "#root/payment/paymentMethods/items/paymentDetails",
"title": "Paymentdetails",
"type": "object",
"required": [
"internalReturnCode",
"authorizationID",
"authCode",
"internalReturnMessage",
"processedAmount",
"chargeType",
"holdAgainstBook",
"authTime",
"requestAmount",
"authReturnMessage",
"authReturnCode",
"requestId"
],
"properties": {
"internalReturnCode": {
"$id": "#root/payment/paymentMethods/items/paymentDetails/internalReturnCode",
"title": "Internalreturncode",
"type": "string",
"default": "",
"examples": [
""
],
"pattern": "^.*$"
},
"authorizationID": {
"$id": "#root/payment/paymentMethods/items/paymentDetails/authorizationID",
"title": "Authorizationid",
"type": "string",
"default": "",
"examples": [
"940799"
],
"pattern": "^.*$"
},
"authCode": {
"$id": "#root/payment/paymentMethods/items/paymentDetails/authCode",
"title": "Authcode",
"type": "string",
"default": "",
"examples": [
"000"
],
"pattern": "^.*$"
},
"internalReturnMessage": {
"$id": "#root/payment/paymentMethods/items/paymentDetails/internalReturnMessage",
"title": "Internalreturnmessage",
"type": "string",
"default": "",
"examples": [
""
],
"pattern": "^.*$"
},
"processedAmount": {
"$id": "#root/payment/paymentMethods/items/paymentDetails/processedAmount",
"title": "Processedamount",
"type": "string",
"default": "",
"examples": [
"159.27"
],
"pattern": "^.*$"
},
"chargeType": {
"$id": "#root/payment/paymentMethods/items/paymentDetails/chargeType",
"title": "Chargetype",
"type": "string",
"default": "",
"examples": [
"CHARGE"
],
"pattern": "^.*$"
},
"holdAgainstBook": {
"$id": "#root/payment/paymentMethods/items/paymentDetails/holdAgainstBook",
"title": "Holdagainstbook",
"type": "string",
"default": "",
"examples": [
"Y"
],
"pattern": "^.*$"
},
"authTime": {
"$id": "#root/payment/paymentMethods/items/paymentDetails/authTime",
"title": "Authtime",
"type": "string",
"default": "",
"examples": [
"2022-06-08T23:21:49"
],
"pattern": "^.*$"
},
"requestAmount": {
"$id": "#root/payment/paymentMethods/items/paymentDetails/requestAmount",
"title": "Requestamount",
"type": "string",
"default": "",
"examples": [
"159.27"
],
"pattern": "^.*$"
},
"authReturnMessage": {
"$id": "#root/payment/paymentMethods/items/paymentDetails/authReturnMessage",
"title": "Authreturnmessage",
"type": "string",
"default": "",
"examples": [
""
],
"pattern": "^.*$"
},
"authReturnCode": {
"$id": "#root/payment/paymentMethods/items/paymentDetails/authReturnCode",
"title": "Authreturncode",
"type": "string",
"default": "",
"examples": [
"000"
],
"pattern": "^.*$"
},
"requestId": {
"$id": "#root/payment/paymentMethods/items/paymentDetails/requestId",
"title": "Requestid",
"type": "string",
"default": "",
"examples": [
"6bf404e0-d756-4247-9030-669c83d0d825"
],
"pattern": "^.*$"
}
}
}
}
},
"if": {
"properties": {
"paymentType": {
"enum": [
"CASH"
]
}
}
},
"then": {
"required": [
"paymentId1"
]
}
},
"createServiceId": {
"$id": "#root/payment/createServiceId",
"title": "Createserviceid",
"type": "string",
"default": "",
"examples": [
"PRE_FULFILLMENT"
],
"pattern": "^.*$"
}
}
}
}
}
Your use of if/then is fine, it's just in the wrong place. You need to move it into the schema that has the properties you're working with.
{
"type": "object",
"properties": {
"payment": {
"type": "object",
"properties": {
"paymentMethods": {
"type": "array",
"items": {
"type": "object",
"properties": {
"paymentId1": { "type": "string" },
"paymentId2": { "type": "string" },
"paymentType": { "type": "string" }
},
"if": {
"properties": {
"paymentType": { "enum": ["CASH"] }
}
},
"then": { "required": ["paymentId1","paymentId2"] }
}
}
}
}
}
}
I have defined Debezium MySQL source connector with the following configuraion
{
"name": "quickstart-debezium-source1",
"config": {
"connector.class": "io.debezium.connector.mysql.MySqlConnector",
"tasks.max": 1,
"database.hostname": "host.docker.internal",
"database.server.name": "connect_test",
"database.server.id": "5555",
"database.port": "3306",
"database.user": "root",
"database.password": "Fintech1!",
"database.history.kafka.topic": "debezium-source",
"database.history.kafka.bootstrap.servers": "broker:29092",
"include.schema.changes": "true",
"key.converter" : "io.confluent.connect.avro.AvroConverter",
"key.converter.schema.registry.url" : "http://host.docker.internal:8081",
"value.converter":"io.confluent.connect.avro.AvroConverter",
"value.converter.schema.registry.url": "http://host.docker.internal:8081",
"topic.creation.default.replication.factor": -1,
"topic.creation.default.partitions": -1,
"topic.creation.default.cleanup.policy": "compact",
"topic.creation.default.compression.type": "lz4"
Also have the following table in MySql:
I am able to see in Kafka new topic created and also new data that being added/updated to the table.
but, I can't see the new data on the topic (I am using confluent-cloud-center)
On the topic I can see the new data like:
I cant see the values of the columns in the table
Also I am trying to create a KSQLDB table out of this topic and no results are coming.
Hope some1 could help me with that,
I also have schema-registry, and the schema registry of the topic is:
{
"type": "record",
"name": "Envelope",
"namespace": "connect_test.connect_test.test",
"fields": [
{
"name": "before",
"type": [
"null",
{
"type": "record",
"name": "Value",
"fields": [
{
"name": "id",
"type": "long"
},
{
"name": "name",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "email",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "department",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "modified",
"type": {
"type": "string",
"connect.version": 1,
"connect.default": "1970-01-01T00:00:00Z",
"connect.name": "io.debezium.time.ZonedTimestamp"
},
"default": "1970-01-01T00:00:00Z"
}
],
"connect.name": "connect_test.connect_test.test.Value"
}
],
"default": null
},
{
"name": "after",
"type": [
"null",
"Value"
],
"default": null
},
{
"name": "source",
"type": {
"type": "record",
"name": "Source",
"namespace": "io.debezium.connector.mysql",
"fields": [
{
"name": "version",
"type": "string"
},
{
"name": "connector",
"type": "string"
},
{
"name": "name",
"type": "string"
},
{
"name": "ts_ms",
"type": "long"
},
{
"name": "snapshot",
"type": [
{
"type": "string",
"connect.version": 1,
"connect.parameters": {
"allowed": "true,last,false,incremental"
},
"connect.default": "false",
"connect.name": "io.debezium.data.Enum"
},
"null"
],
"default": "false"
},
{
"name": "db",
"type": "string"
},
{
"name": "sequence",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "table",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "server_id",
"type": "long"
},
{
"name": "gtid",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "file",
"type": "string"
},
{
"name": "pos",
"type": "long"
},
{
"name": "row",
"type": "int"
},
{
"name": "thread",
"type": [
"null",
"long"
],
"default": null
},
{
"name": "query",
"type": [
"null",
"string"
],
"default": null
}
],
"connect.name": "io.debezium.connector.mysql.Source"
}
},
{
"name": "op",
"type": "string"
},
{
"name": "ts_ms",
"type": [
"null",
"long"
],
"default": null
},
{
"name": "transaction",
"type": [
"null",
{
"type": "record",
"name": "ConnectDefault",
"namespace": "io.confluent.connect.avro",
"fields": [
{
"name": "id",
"type": "string"
},
{
"name": "total_order",
"type": "long"
},
{
"name": "data_collection_order",
"type": "long"
}
]
}
],
"default": null
}
],
"connect.name": "connect_test.connect_test.test.Envelope"
}
I am trying to add a dependency to a property based on the property value before it. Within my JSON, there is an instances property. If that property is > 2 only then show the StartIndex property. I have tried adding another if-then-else to my pre-existing one (wrapped in an allOf) but that was failing so I decided to take the dependency route.
Here's the JSON Schema with my attempt at adding the dependency withing the StartIndex property:
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": " ",
"required": [
"NetworkProfile",
"GroupEmailAddress",
"FILESTORAGE",
"Memory",
"Instances",
"StartIndex"
],
"properties": {
"Name": {
"$id": "#/properties/Name",
"type": "string",
"title": "Name",
"default": "",
"description": "The first five characters are generated per specs. Specify the next eight characters here and we suggest: Data Center (2), Layer (2-3), Sequential Number (2).",
"examples": [
""
],
"minLength": 0,
"maxLength": 8,
"pattern": "^[a-zA-Z0-9]*$",
"validationMessages": {
"pattern": "Must contain only alphanumeric characters.",
"required": "Must contain only alphanumeric characters."
}
},
"Instances": {
"$id": "#/properties/Instances",
"default": 2,
"examples": [
"2"
],
"pattern": "^(.*)$",
"title": "Number of VM Node",
"description": "Number of VM instance in this request",
"minimum": 1,
"maximum": 5,
"type": "number"
},
"StartIndex": {
"dependencies": {
"Instances": {
"minimum": 2
}
},
"$id": "#/properties/StartIndex",
"default": 1,
"examples": [
"1"
],
"pattern": "^(.*)$",
"title": "Start Index for these VMs",
"description": "The starting sequence number for this set of servers",
"type": "number",
"minimum": 1
},
"Memory": {
"$id": "#/properties/Memory",
"type": "number",
"enum": [
4,
8,
16
],
"title": "RAM (GB)",
"default": 4,
"examples": [
""
],
"pattern": "^(.*)$"
},
"GroupEmailAddress": {
"$id": "#/properties/GroupEmailAddress",
"type": "string",
"title": "Group Email Address",
"default": "",
"description": "This should be an email address for your application group. Security will use this email address to contact when TLS cert needs to be renewed.",
"examples": [
""
]
},
"User": {
"$id": "#/properties/User",
"type": "string",
"title": "Admin Group",
"default": "",
"examples": [
""
],
"description": "The user account that will have access to the vm. Default belong to requester if not specified. Additional users can be added by using a comma(,) as a separator. <br> (e.g. Americas\\firstName_lastName). Only PAC group is accepted for PROD.",
"pattern": "^((Americas|Asia-Pacific|Europe)\\\\.[a-zA-Z0-9_.%]*[*,]?[\\s]*)*$"
},
"NetworkProfile": {
"$id": "#/properties/NetworkProfile",
"type": "string",
"enum": [
"APP",
"WEB"
],
"title": "Server Type/Function",
"description": "Web Server is meant to serve static pages e.g. HTML and CSS, while Application Server is responsible for generating dynamic content by executing server side code.",
"default": "",
"examples": [
""
],
"pattern": "^(.*)$"
},
"eDell": {
"$id": "#/properties/eDell",
"title": "Is the VM related to eDell? ",
"type": "boolean",
"default": false
},
"Disks": {
"$id": "#/properties/Disks",
"type": "array",
"title": "Local (Non-OS) Storage. Default OS Drive (C) size is 60GB. The (D) drive is fixed at 20 GB, can use E-Z for additional storage. Can only add an additional 900GB.",
"items": {
"$id": "#/properties/Disks/items",
"type": "object",
"title": " ",
"required": [
"data"
],
"properties": {
"data": {
"$id": "#/properties/Disks/items/properties/data",
"type": "object",
"title": " ",
"required": [
"capacity",
"initial_location"
],
"properties": {
"capacity": {
"$id": "#/properties/Disks/items/properties/data/properties/capacity",
"type": "number",
"title": "Capacity (GB)",
"default": "",
"examples": [
"20"
],
"minimum": 5,
"maximum": 900
},
"initial_location": {
"$id": "#/properties/Disks/items/properties/data/properties/initial_location",
"type": "string",
"title": "Drive Letter",
"default": "E",
"examples": [
"/u02"
],
"description": "Drive Letter of the partition without colon",
"pattern": "^[eE,fF,gG,hH,iI,jJ,kK,lL,mM,nN,oO,pP,qQ,rR,sS,tT,uU,vV,wW,xX,yY,zZ]{1}$",
"validationMessages": {
"pattern": "C,D are reserved use E-Z.",
"required": "C,D are reserved use E-Z."
}
}
}
}
}
}
},
"FILESTORAGE": {
"$id": "#/FileStorage",
"type": "string",
"enum": [
"YES",
"NO"
],
"title": "Add File Storage",
"default": "NO",
"examples": [
""
],
"pattern": "^(.*)$"
}
},
"if": {
"properties": {
"FILESTORAGE": {
"const": "YES"
}
}
},
"then": {
"properties": {
"NASDisk": {
"$id": "#/properties/NASDisk",
"type": "object",
"title": "File Storage",
"required": [
"AppName",
"SizeGB",
"Protocol",
"ShareOwner",
"Function"
],
"properties": {
"Protocol": {
"$id": "#/properties/NASDisk/properties/Protocol",
"type": "string",
"default": "CIFS",
"options": {
"hidden": "true"
}
},
"Function": {
"$id": "#/properties/NASDisks/properties/Function",
"type": "string",
"enum": [
"File",
"Storage",
"Backup",
"App",
"Log",
"Database",
"Repository"
],
"title": "Choose Function for NAS",
"default": "File",
"examples": [
""
],
"pattern": "^(.*)$"
},
"AppName": {
"$id": "#/properties/NASDisk/properties/AppName",
"type": "string",
"title": "App Name",
"default": "",
"description": "Abbreviation or alias of the application name to be prefix to the share name, limit to 10 letters",
"pattern": "^[a-zA-Z]{1,10}$"
},
"SizeGB": {
"$id": "#/properties/NASDisk/properties/SizeGB",
"type": "number",
"title": "Size (GB)",
"default": 5,
"examples": [
5
],
"minimum": 5,
"maximum": 500
},
"ShareOwner": {
"$id": "#/properties/NASDisk/properties/ShareOwner",
"type": "string",
"title": "Share Owner",
"default": "",
"description": "User account with ownership of the share. Group ownership can be specified using the format DOMAIN\\UserName. <br> (e.g. Americas\\firstName_lastName).",
"examples": [
"adms_c_lawlor"
],
"pattern": "^((Americas|Asia-Pacific|Europe)\\\\.[a-zA-Z0-9_.%]*[*,]?[\\s]*)*$"
},
"FC_Members": {
"$id": "#/properties/NASDisk/properties/FC_Members",
"type": "string",
"description": "Comma separated AD groups that will have full control of share."
},
"RW_Members": {
"$id": "#/properties/NASDisk/properties/RW_Members",
"type": "string",
"description": "Comma separated AD groups that will have read/write control of share."
}
}
}
}
},
"else": {}
}
Here was my allOf attempt:
"allOf": [
{
"if": {
"properties": {
"FILESTORAGE": {
"const": "YES"
}
}
},
"then": {
"properties": {
"NASDisk": {
"$id": "#/properties/NASDisk",
"type": "object",
"title": "File Storage",
"required": [
"AppName",
"SizeGB",
"Protocol",
"ShareOwner",
"Function"
],
"properties": {
"Protocol": {
"$id": "#/properties/NASDisk/properties/Protocol",
"type": "string",
"default": "CIFS",
"options": {
"hidden": "true"
}
},
"Function": {
"$id": "#/properties/NASDisks/properties/Function",
"type": "string",
"enum": [
"File",
"Storage",
"Backup",
"App",
"Log",
"Database",
"Repository"
],
"title": "Choose Function for NAS",
"default": "File",
"examples": [
""
],
"pattern": "^(.*)$"
},
"AppName": {
"$id": "#/properties/NASDisk/properties/AppName",
"type": "string",
"title": "App Name",
"default": "",
"description": "Abbreviation or alias of the application name to be prefix to the share name, limit to 10 letters",
"pattern": "^[a-zA-Z]{1,10}$"
},
"SizeGB": {
"$id": "#/properties/NASDisk/properties/SizeGB",
"type": "number",
"title": "Size (GB)",
"default": 5,
"examples": [
5
],
"minimum": 5,
"maximum": 500
},
"ShareOwner": {
"$id": "#/properties/NASDisk/properties/ShareOwner",
"type": "string",
"title": "Share Owner",
"default": "",
"description": "User account with ownership of the share. Group ownership can be specified using the format DOMAIN\\UserName. <br> (e.g. Americas\\firstName_lastName).",
"examples": [
"adms_c_lawlor"
],
"pattern": "^((Americas|Asia-Pacific|Europe)\\\\.[a-zA-Z0-9_.%]*[*,]?[\\s]*)*$"
},
"FC_Members": {
"$id": "#/properties/NASDisk/properties/FC_Members",
"type": "string",
"description": "Comma separated AD groups that will have full control of share."
},
"RW_Members": {
"$id": "#/properties/NASDisk/properties/RW_Members",
"type": "string",
"description": "Comma separated AD groups that will have read/write control of share."
}
}
}
}
},
"else": {
}
},
{
"if": {
"properties": {
"Instances": {
"minimum": "1"
}
}
},
"then": {
"properties": {
"StartIndex": {
"$id": "#/properties/StartIndex",
"hidden": true,
"default": "1",
"examples": [
"1"
],
"pattern": "^(.*)$",
"title": "Start Index for these VMs",
"description": "The starting sequence number for this set of servers",
"type": "number",
"minimum": 0
}
}
},
"else": {
"properties": {
"StartIndex": {
"$id": "#/properties/StartIndex",
"default": "",
"examples": [
"1"
],
"pattern": "^(.*)$",
"title": "Start Index for these VMs",
"description": "The starting sequence number for this set of servers",
"type": "number",
"minimum": 0
}
}
}
}
]
UPDATE: So I actually figure this out using nested properties as shown here
"isMultiDropdown": {
"title": "",
"$id": "#/properties/isMultiDropdown",
"required": [
"isMulti"
],
"type": "object",
"if": {
"properties": {
"isMulti": {
"const": "YES"
}
}
},
"then": {
"properties": {
"StartIndex": {
"$id": "#/properties/StartIndex",
"default": "",
"examples": [
"1"
],
"pattern": "^(.*)$",
"title": "Start Index for these VMs",
"description": "The starting sequence number for this set of servers",
"type": "number",
"minimum": 0
}
}
},
"properties": {
"isMulti": {
"$id": "#/properties/isMultiDropdown/isMulti",
"enum": [
"YES",
"NO"
],
"title": "Are you provisioning multiple instances?",
"default": "NO",
"examples": [
""
],
"pattern": "^(.*)$",
"type": "string"
}
}
}
```
Using Draft-07
What I got was
valid JSON
What error I expected from audit object was
directory: String length must be greater than or equal to 2
Tried two different validators with same results
https://www.jsonschemavalidator.net/
GoLang https://github.com/xeipuuv/gojsonschema
This is my schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ISAM-Wrapper",
"description": "Validate isam wrapper json",
"type": "object",
"properties": {
"directory": {
"description": "path to location of isam file",
"type": "string",
"minLength": 2
},
"isamFile": {
"description": "isam database file",
"type": "string",
"minLength": 4
},
"isamIndex": {
"description": "isam index file",
"type": "string",
"minLength": 4
},
"port": {
"description": "port number for REST listener",
"type": "integer",
"minimum": 60410,
"maximum": 69999
},
"actions": {
"description": "Which operations are supported",
"type": "object",
"items": {
"properties": {
"create": {
"type": "boolean"
},
"read": {
"type": "boolean"
},
"update": {
"type": "boolean"
},
"delete": {
"type": "boolean"
}
}
},
"required": [
"create",
"read",
"update",
"delete"
]
},
"fields": {
"description": "each object describes one field of the isam file",
"type": "array",
"minItems": 1,
"items": {
"title": "field",
"description": "field schema",
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"ordinal": {
"type": "integer",
"minimum": 0
},
"offset": {
"type": "integer",
"minimum": 0
},
"length": {
"type": "integer",
"minimum": 1
},
"dataType": {
"enum": [
"uchar",
"ulong",
"long",
"uint",
"int",
"ushort",
"short"
]
}
},
"required": [
"name",
"ordinal",
"offset",
"length",
"dataType"
]
}
},
"audit": {
"description": "input needed to enable and configure isam auditing",
"type": "object",
"items": {
"properties": {
"enable": {
"enum": [
true,
false
]
},
"directory": {
"type": "string",
"minLength": 2
},
"fileName": {
"type": "string",
"minLength": 4
},
"workDirectory": {
"type": "string",
"minLength": 2
},
"archiveDirectory": {
"type": "string",
"minLength": 2
},
"interval": {
"type": "integer",
"minimum": 1
},
"byteThreshold": {
"type": "integer",
"minimum": 1048576,
"maximum": 1073741824
}
}
},
"required": [
"enable"
],
"if": {
"not": {
"properties": {
"enable": {
"enum": [
false
]
}
}
}
},
"then": {
"required": [
"directory",
"fileName",
"workDirectory",
"archiveDirectory",
"interval",
"byteThreshold"
]
}
}
},
"required": [
"directory",
"isamFile",
"isamIndex",
"port",
"actions",
"fields",
"audit"
]
}
This is my JSON
{
"directory": "./",
"isamFile": "isam.dat",
"isamIndex": "isam.idx",
"port": 60410,
"actions": {
"create": true,
"read": true,
"update": true,
"delete": true
},
"fields": [
{
"name": "F1",
"ordinal": 0,
"offset": 0,
"length": 4,
"dataType": "ulong"
},
{
"name": "F2",
"ordinal": 1,
"offset": 4,
"length": 4,
"dataType": "ulong"
}
],
"audit": {
"enable": true,
"directory": "",
"fileName": "file",
"workDirectory": "./work",
"archiveDirectory": "./archive",
"interval": 5,
"byteThreshold": 1500000
}
}
This issue you have is that your schema is invalid. For both actions and audit you specify these as objects but you don't provide any properties. What you do do, however, is specify an items key (which does nothing here - that's a key on an array) which contains the properties.
Once you correct this error, the schema behaves as you intend, see https://repl.it/repls/BlankWellmadeFrontpage
I have a json response like below. In the views array may or may not contain actions array.
In the reponse If any of view array contains actions object , then i have to validate that actions data with json schema(schema1.json)
And in the schema i mentioned the action propertes like(type,label,localizedlabel) as required ones.
But when I modify key or value type of this type,label,localizedlabel in the response does not output any errors.
Tested via( https://www.jsonschemavalidator.net/). what wrong with my schema?
How can i validate actions object only whenever it present inside any of view array?
schema1.json
{
"$id": "",
"type": "array",
"items": {
"$id": "/items",
"type": "object",
"properties": {
"name": {
"$id": "/items/properties/name",
"type": "string",
"title": "The Name Schema ",
"default": "",
"examples": [
"Preview"
]
},
"displayOrder": {
"$id": "/items/properties/displayOrder",
"type": "integer",
"title": "The Displayorder Schema ",
"default": 0,
"examples": [
1
]
},
"actions": {
"$id": "/items/properties/actions",
"type": "array",
"items": {
"$id": "/items/properties/actions/items",
"type": "object",
"properties": {
"type": {
"$id": "/items/properties/actions/items/properties/type",
"type": "string",
"title": "The Type Schema ",
"default": "",
"examples": [
"watch"
]
},
"label": {
"$id": "/items/properties/actions/items/properties/label",
"type": "string",
"title": "The Label Schema ",
"default": "",
"examples": [
"Watch"
]
},
"localizedLabel": {
"$id": "/items/properties/actions/items/properties/localizedLabel",
"type": "object",
"properties": {
"ENG": {
"$id": "/items/properties/actions/items/properties/localizedLabel/properties/ENG",
"type": "string",
"title": "The Eng Schema ",
"default": "",
"examples": [
"Watch"
]
},
"ESP": {
"$id": "/items/properties/actions/items/properties/localizedLabel/properties/ESP",
"type": "string",
"title": "The Esp Schema ",
"default": "",
"examples": [
"Ver"
]
}
}
}
},
"required": [
"type",
"label",
"localizedLabel"
]
}
},
"localizedName": {
"$id": "/items/properties/localizedName",
"type": "object",
"properties": {
"ENG": {
"$id": "/items/properties/localizedName/properties/ENG",
"type": "string",
"title": "The Eng Schema ",
"default": "",
"examples": [
"Preview"
]
},
"ESP": {
"$id": "/items/properties/localizedName/properties/ESP",
"type": "string",
"title": "The Esp Schema ",
"default": "",
"examples": [
"Adelanto"
]
}
}
}
},
"required": [
"actions"
]
}
}
response json
[{
"season": 2017,
"teamData": {
"awayTeam": {
"id": 6,
"city": "Dallas",
"name": "Mavericks",
"abbr": "DAL",
"color": "#0B51A1"
},
"homeTeam": {
"id": 8,
"city": "Detroit",
"name": "Pistons",
"abbr": "DET",
"color": "#990300"
}
},
"views": [{
"name": "Preview",
"displayOrder": 1,
"groups": [{
"type": "static",
"displayOrder": 1,
"tiles": [{
"context": "event",
"collection": "event",
"auditType": "pregame-preview",
"displayOrder": 1,
"_id": "5ac58ea21ee2112b33291f1c",
"eventId": 2018040608,
"dimensions": {
"width": 372,
"height": 375
},
"tileId": "36b154e719d7d8397da487cbc4e5f7d1",
"renderTime": "2018-04-05T02:49:05+00:00",
"dataTime": "2018-04-05T02:48:58+00:00",
"dataStamp": 1522896538,
"location": "http://test.com/2018040608/static/pre-event/pregame-preview/1522896538.png",
"tile_type": "static"
}
]
}
],
"actions": [{
"type": "watch",
"label": "Watch",
"localizedLabel": {
"ENG": "Watch",
"ESP": "Ver"
}
}, {
"type": "record",
"label": "Record",
"localizedLabel": {
"ENG": "Record",
"ESP": "Grabar"
}
}, {
"type": "tile_overlay",
"label": "Current Standings",
"tili": {
"context": "event",
"collection": "event",
"auditType": "full-standings",
"_id": "5ac6f9de2ccaf768d092c918",
"eventId": 2018040608,
"dimensions": {
"width": 1140,
"height": 660
},
"tileId": "852f92537e68dc99b54f1228459ec9ef",
"renderTime": "2018-04-06T04:38:54+00:00",
"dataTime": "2018-04-06T04:38:52+00:00",
"dataStamp": 1522989532,
"location": "http://test.com/2018040608/static/pre-event/full-standings/1522989532.png"
},
"localizedLabel": {
"ENG": "Current Standings",
"ESP": "Posición actual"
}
}, {
"type": "favorite",
"label": "Favorite",
"localizedLabel": {
"ENG": "Favorite",
"ESP": "Favorito"
}
}
],
"localizedName": {
"ENG": "Preview",
"ESP": "Adelanto"
}
}, {
"name": "Team Stats",
"displayOrder": 2,
"groups": [{
"type": "static",
"displayOrder": 1,
"tiles": [{
"context": "event",
"collection": "event",
"auditType": "pregame-team_stats",
"displayOrder": 1,
"_id": "5ac6755a4f82eb58a5eae6a6",
"eventId": 2018040608,
"dimensions": {
"width": 372,
"height": 510
},
"tileId": "1302dc16c9fe68c3e6edadd98afce2bc",
"renderTime": "2018-04-05T19:13:30+00:00",
"dataTime": "2018-04-05T19:13:28+00:00",
"dataStamp": 1522955608,
"location": "http://test.com/2018040608/static/pre-event/pregame-team_stats/1522955608.png",
"tile_type": "static"
}
]
}
],
"localizedName": {
"ENG": "Team Stats",
"ESP": "Estadísticas del equipo"
}
}, {
"name": "Leaders",
"displayOrder": 3,
"groups": [{
"type": "static",
"displayOrder": 1,
"tiles": [{
"context": "event",
"collection": "event",
"auditType": "pregame-leaders",
"displayOrder": 1,
"_id": "5ac26eb31ee2112b3328b00c",
"eventId": 2018040608,
"dimensions": {
"width": 372,
"height": 510
},
"tileId": "96abc24c47d61327426ef2b24281acbf",
"renderTime": "2018-04-02T17:55:57+00:00",
"dataTime": "2018-04-02T17:55:54+00:00",
"dataStamp": 1522691754,
"location": "http://test.com/2018040608/static/pre-event/pregame-leaders/1522691754.png",
"tile_type": "static"
}
]
}
],
"localizedName": {
"ENG": "Leaders",
"ESP": "Líderes"
}
}
]
}
]
There's nothing wrong with your schema. It should do what you need if used properly. Because it only describes the "views" part of the schema you would need to iterate through your response and pass just the "views" part of each item to the validator one at a time.
Or, you could add enough of the response structure to the schema to validate everything at once. Then you could just pass your whole response to the validator.
{
"type": "array",
"items": {
"type": "object",
"properties": {
"views": { "$ref": "schema1.json" }
}
}
}