shuttle-hq / synth

The Declarative Data Generator
https://www.getsynth.com/
Apache License 2.0
1.36k stars 105 forks source link

string format - Support for Conditional Replacements #437

Open arindamghoshal opened 1 year ago

arindamghoshal commented 1 year ago

Required Functionality Construct string values based on conditional replacements as part parsing a parametric format string

Proposed Solution Support for Ternary conditional operator as part of parametric format string. Something like this -

"productId": {
  "type": "string",
  "format": {
    "format": "{productType}_{IF({productType}=='alphabet', {alphabets}, {digits})}",
    "arguments": {
      "productType": {
        "type": "string",
        "categorical": {
          "alphabet": 1,
          "digit": 1 
        }
      },
      "alphabets": {
        "type": "string",
        "categorical": {
          "abc": 3,
          "def": 5,
          "ghi": 2
        }
      },
      "digits": {
        "type": "string",
        "categorical": {
          "123": 3,
          "456": 5,
          "789": 2
        }
      }
    }
  }
}

I have use a function like construct IF(condition, trueValue, falseValue) only to explain the intent.

Use case String based Identify values are quite complex and ability to generate variations based on the value of another dynamic value would make the declarative data model robust.