You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So SeparatorConfig has two properties, both of which have default values.
Elsewhere in another object I have a field of type SeparatorConfig, and I'd like to make the entire field optional such that it defaults to an object with the correct default field values as defined above.
Overall this would make specifying default values for objects throughout a schema significantly easier.
The current alternatives are to either specify all the default field values at every level, duplicating a lot of default values (error prone), or not specifying defaults in the schema and manually constructing default structs in code when properties are None (cumbersome).
The text was updated successfully, but these errors were encountered:
jamesthurley
changed the title
Specifying default values for object properties should use objects existing default field values
Specifying default value for an object should use object's existing default field values
Aug 22, 2024
Let's say I have the following object definition in my schema:
So
SeparatorConfig
has two properties, both of which have default values.Elsewhere in another object I have a field of type
SeparatorConfig
, and I'd like to make the entire field optional such that it defaults to an object with the correct default field values as defined above.I could in theory do the following:
However the resulting generated code which produces this default value is:
Which produces:
Rather than the desired default:
A better implementation for creating the default
SeparatorConfig
struct would be to use the existing builders you already generate:We would also have to use the builder functions for defaults which specify only some properties:
Could produce:
rather than the current:
Overall this would make specifying default values for objects throughout a schema significantly easier.
The current alternatives are to either specify all the default field values at every level, duplicating a lot of default values (error prone), or not specifying defaults in the schema and manually constructing default structs in code when properties are
None
(cumbersome).The text was updated successfully, but these errors were encountered: