Kavindu Gimhan Zoysa
Kavindu Gimhan Zoysa

Reputation: 167

Define Ballerina ecord type where fields have a predefined values

type JsonSchema record{|
    string 'type;
    json properties;
|};

type ArraySchema record{|
    string 'type;
    json items;
|};

Please check the above record types. In both records 'type should be "object" and "array" respectively. However, according to the above definition, the user is able to put any string to those fields. How do we constrain this?

Upvotes: 0

Views: 27

Answers (1)

Kavindu Gimhan Zoysa
Kavindu Gimhan Zoysa

Reputation: 167

type JsonSchema record{|
    "object" 'type = "object";
    json properties;
|};

type ArraySchema record{|
    "array" 'type = "array";
    json items;
|};

We can define the field using singleton type and add default value as shown here.

Upvotes: 0

Related Questions