datacontract / datacontract-cli

CLI to manage your datacontract.yaml files
https://cli.datacontract.com
Other
352 stars 60 forks source link

datacontract export --format Avro - use 'required' attribute #256

Open gpthome opened 2 weeks ago

gpthome commented 2 weeks ago

Request - use the "required" field in the model to generate AVRO output accordingly. I believe when set to false, use UNION with NULL being first.

If model is defined like this...

      tags:
        type: array
        items: 
          type: string
        default: []
        required: false
      removal_dt:
        type: timestamp
        required: false
      barcode:
        type: string
        required: false

Generate output similar to this...

        {
            "name": "tags",
            "type": [
                "null",
                {
                    "type": "array",
                    "items": "string"
                }
            ],
            "default": null
        },
        {
            "name": "removal_dt",
            "type": [
                "null",
                {
                    "type": "long",
                    "logicalType": "timestamp-millis"
                }
            ]
        },
        {
            "name": "barcode",
            "type": [
                "null",
                {
                    "type": "string",
                }
            ]
        },

Please include other data types like int as well. For the array, I'm not 100% sure if the generated AVRO output "default" should be null or "[ ]"