Skip to content

Handle required nullable types. - #329

Merged
jmcarp merged 2 commits into
mainfrom
jmcarp/handle-required-nullable
Sep 26, 2025
Merged

Handle required nullable types.#329
jmcarp merged 2 commits into
mainfrom
jmcarp/handle-required-nullable

Conversation

@jmcarp

@jmcarp jmcarp commented Sep 26, 2025

Copy link
Copy Markdown
Contributor

The omicron api includes fields that are nullable (i.e. may be explicitly set to null) but required (i.e. they can't be omitted). To handle these types in the sdk, we treat them as pointers, and don't set omitempty in the struct tags.

This patch also updates omicron to latest to pull in newly added or updated fields.

The omicron api includes fields that are nullable (i.e. may be explicitly set
to null) but required (i.e. they can't be omitted). To handle these types in
the sdk, we treat them as pointers, and don't set `omitempty` in the struct
tags.

This patch also updates omicron to latest to pull in newly added or updated
fields.
@jmcarp
jmcarp requested a review from a team as a code owner September 26, 2025 13:35
Comment thread oxide/types.go Outdated
Memory ByteCount `json:"memory,omitempty" yaml:"memory,omitempty"`
// Ncpus is the number of CPUs to assign to this instance.
// Ncpus is the number of vCPUs to be allocated to the instance
Ncpus InstanceCpuCount `json:"ncpus,omitempty" yaml:"ncpus,omitempty"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I know this can't be a big problem since it was already like this and these were already required, but why are these omitempty if they can't actually be omitted? Is it that zero isn't a valid value for these fields anyway?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah, I agree. I updated the logic to drop omitempty for these fields, and verified that the terraform provider acceptance tests still pass after making the change. I don't consider this to be a breaking change, so I'm fine with the large diff in the generated code.

@jmcarp
jmcarp force-pushed the jmcarp/handle-required-nullable branch from 2950f7b to 5799db9 Compare September 26, 2025 15:37

@lgfa29 lgfa29 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. I ran a quick test on r16 just in case and everything seems to still work 👍

@sudomateo sudomateo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry for the delay on this. Had a slow start today. I'm glad others noted the omit* issues on types that should no longer be omitted. I noticed that earlier but didn't get a chance to write it down.

I left one comment but otherwise this looks good.

Comment thread internal/generate/types.go Outdated
It doesn't really make sense to omit empty or zero values for fields that are
required by the api. This patch updates the generator to omit the `omitempty`
struct tag for these fields.

h/t @david-crespo
@jmcarp
jmcarp force-pushed the jmcarp/handle-required-nullable branch from 5799db9 to 953698f Compare September 26, 2025 18:14
@jmcarp
jmcarp merged commit b8c3f7e into main Sep 26, 2025
2 checks passed
@jmcarp
jmcarp deleted the jmcarp/handle-required-nullable branch September 26, 2025 18:58
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.

4 participants