ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
136 stars 64 forks source link

Add support to handle copybook with multiple root records. #6895

Closed MohamedSabthar closed 2 months ago

MohamedSabthar commented 2 months ago

Description: The current implementation of the copybook module only converts a copybook file bound to a particular record. When multiple root copybook records are found in the given copybook schema, a targetRecordName is required for each operation, and an error is thrown if the targetRecordName is not provided. There is a requirement to perform all operations without a targetRecordName. In this case, the input and output data for all operations will consider the entire copybook schema, including all root records.

For example for the following schema

01 DFHCOMMAREA.
   05 BROKER-MESSAGE-AREA.
      15 MI-HDR-VERSION                          PIC X(04).
      15 MI-HDR-MSGID                            PIC X(35).
      15 MI-HDR-LOGGINGID                        PIC X(35).
01 DFHCOMMAREA-2.
   05 BROKER-MESSAGE-AREA-2.
      15 MI-HDR-VERSION-2                          PIC X(04).
      15 MI-HDR-MSGID-2                            PIC X(35).
      15 MI-HDR-LOGGINGID-2                        PIC X(35).

and for the following inputData v1.0100 7890V100 v2.1200 7890V100 the fromCopybook(inputData) call should generate the following json output

{
  "DFHCOMMAREA": {
    "BROKER-MESSAGE-AREA": {
      "MI-HDR-VERSION": "v1.0",
      "MI-HDR-MSGID": "100",
      "MI-HDR-LOGGINGID": "7890V100"
    }
  },
  "DFHCOMMAREA-2": {
    "BROKER-MESSAGE-AREA-2": {
      "MI-HDR-VERSION-2": "v2.1",
      "MI-HDR-MSGID-2": "200",
      "MI-HDR-LOGGINGID-2": "7890V100"
    }
  }
}

Describe your problem(s)

Describe your solution(s)

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):