Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Why JSON Schema support is needed?

...

3) In the Policy command file (*.apex)

    Use  Use Json instead of Avro. For e.g.,
        schema create

Code Block
languagetext
schema create name=CDSRequestCommonHeaderType flavour=Json schema=LS

...


#MACROFILE:"src/main/resources/schemas/CDSRequestCommonHeaderType.json"

...


LE

...

4) Create the schema file containing the JsonSchema.

(Many      Many online tools are available to easily create JSON Schema from JSON event: https://extendsclass.com/json-schema-validator.html ) 
    For  For e.g., CDSRequestCommonHeaderType.json is the file containing the corresponding JsonSchema definition (JSON Schema draft 4 and 7 versions are shown below - both should work fine).
        {
            

Code Block
languageyml
{
  "$schema": "http://json-schema.org/draft-04/schema#",

...


  "type": "object",

...


  "properties":

...

 {
    "originatorId":

...

 {
      "type": "string"

...


    },
    "requestId":

...

 {
      "type": "string"

...


    },
    "subRequestId":

...

 {
      "type": "string"

...


    }
  },
  "required":

...

 [
    "originatorId",

...


    "requestId",

...


    "subRequestId"

...


  ]
}


Code Block
languageyml
{
  "definitions": {},

...


  "$schema": "http://json-schema.org/draft-07/schema#",

...


  "title": "Root",

...


  "type": "object",

...


  "required":

...

 [
    "requestId",

...


    "subRequestId",

...


    "originatorId"

...


  ],
  "properties":

...

 {
    "requestId":

...

 {
      "$id": "#root/requestId",

...


      "title": "Requestid",

...


      "type": "string",

...


      "default": "",

...


      "examples":

...

 [
        "123456-1000"

...


      ],
      "pattern": "^.*$"

...


    },
    "subRequestId":

...

 {
      "$id": "#root/subRequestId",

...


      "title": "Subrequestid",

...


      "type": "string",

...


      "default": "",

...


      "examples":

...

 [
        "sub-123456-1000"

...


      ],
      "pattern": "^.*$"

...


    },
    "originatorId":

...

 {
      "$id": "#root/originatorId",

...


      "title": "Originatorid",

...


      "type": "string",

...


      "default": "",

...


      "examples":

...

 [
        "sdnc"
      ],
      "pattern": "^.*$"

...


    }
  }
}

5) In the logic file

...

  • The extra complexity of using "_DoT_" instead of ".", "_DasH_" instead of "-" and "_ColoN_" instead of ":" will be removed and the field names can be directly used.

...

  • createNewInstance and createNewSubInstance methods will probably not be needed with JsonSchema support. HashMap, ArrayList etc can directly be created and used as these could be mapped straightaway using the JsonSchema validator.

    For e.g., with Avro, to populate the fields, the below lines are needed:
    
    var payloadEntry =    

Code Block
languagejs
var payloadEntry = executor.subject.getOutFieldSchemaHelper("payload").createNewSubInstance("CDSRequestPayloadEntry");

...


payloadEntry.put("create_DasH_subscription_DasH_properties", payloadProperties)

...


var payload = executor.subject.getOutFieldSchemaHelper("payload").createNewInstance();

...


payload.put("create_DasH_subscription_DasH_request", payloadEntry);

    
    This By using JSON Schema, this could be replaced with
    
    var payloadEntry = new as below:

Code Block
languagejs
var payloadEntry = new java.util.HashMap();

...


payloadEntry.put("create-subscription-properties", payloadProperties)

...


var payload = new java.util.HashMap();

...


payload.put("create-subscription-request", payloadEntry);

Summary

JsonSchema support in APEX-PDP has the following advantages:1)

  1. Support for optional fields in events enabling APEX-PDP for more use cases.

...

  1. No naming restrictions unlike Avro and flexibility in usage.