Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional attribute to spec #6

Merged
merged 3 commits into from
Aug 1, 2023
Merged

Add optional attribute to spec #6

merged 3 commits into from
Aug 1, 2023

Conversation

criccomini
Copy link
Contributor

The current Recap null-field handling is a bit cumbersome. I discussed with
@gwukelic, @adrianisk, and @cpard. We decided to add support for an optional
field to the CST. This will allow us to specify that a field is optional.

See the conversation here:

gabledata/recap#335

Users can now specify an optional field as:

type: struct
fields:
  - name: secondary_phone
    type: string32
    optional: true

This will get treated the same as:

type: struct
fields:
  - name: secondary_phone
    type: "union",
    types: ["null", "string32"],
    default: null

The current Recap null-field handling is a bit cumbersome. I discussed with
@gwukelic, @adrianisk, and @cpard. We decided to add support for an `optional`
field to the CST. This will allow us to specify that a field is optional.

See the conversation here:

gabledata/recap#335

Users can now specify an optional field as:

```yaml
type: struct
fields:
  - name: secondary_phone
    type: string32
    optional: true
```

This will get treated the same as:

```yaml
type: struct
fields:
  - name: secondary_phone
    type: "union",
    types: ["null", "string32"],
    default: null
```
# A union type of null or a 32-bit signed int
type: union
types:
- type: null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work now? I'm worried that null (without quotes) still won't work. If so, we should update the examples to use "null" (with quotes).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good catch. Updated.

YAML coerces `null` to a null literal (None in Python) rather than a string
literal ("null"). The examples should say `"null"` since all type attribues in
Recap have a string literal value.
@criccomini criccomini merged commit 14b167d into main Aug 1, 2023
@criccomini criccomini deleted the add-optional branch August 1, 2023 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants