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 |
---|
|
schema create name=CDSRequestCommonHeaderType flavour=Json schema=LS |
...
#MACROFILE:"src/main/resources/schemas/CDSRequestCommonHeaderType.json" |
...
...
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 |
---|
|
{
"$schema": "http://json-schema.org/draft-04/schema#", |
...
...
...
...
...
...
...
...
...
...
...
...
...
Code Block |
---|
|
{
"definitions": {}, |
...
"$schema": "http://json-schema.org/draft-07/schema#", |
...
...
...
...
...
...
...
...
...
{
"$id": "#root/requestId", |
...
...
...
...
...
...
...
...
{
"$id": "#root/subRequestId", |
...
...
...
...
...
...
...
...
{
"$id": "#root/originatorId", |
...
...
...
...
...
[
"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 |
---|
|
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 |
---|
|
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)
- Support for optional fields in events enabling APEX-PDP for more use cases.
...
- No naming restrictions unlike Avro and flexibility in usage.