speakeasy icon indicating copy to clipboard operation
speakeasy copied to clipboard

[SPE-2631] How to implement an optional nullable field?

Open teleskop150750 opened this issue 1 year ago • 3 comments

"aarondl/opt" and "aarondl/json" allow me to distinguish between "optional" field and "nullable". "ogen" also allows you to do this.

This is necessary for a "PATCH" request, when not all fields can be passed and at the same time they can take a "NULL" value.

Can I repeat something like this with "speakeasy"?

SPE-2631

teleskop150750 avatar Oct 16 '23 11:10 teleskop150750

Hi @teleskop150750 is this for our go language target?

If so then this is currently a limitation of our generated SDKs, if a field is both optional and nullable we don't have a way of distinguishing this so nullable takes precedence so if an end-user sets the pointer value to nil then the null value will be serialized on the wire in the JSON, instead of being omitted.

We have been thinking of ways to address this without introducing 3rd party dependencies (we tend to try and keep our dependency usage as low as possible) and while also keeping the usage of the generated types as idiomatic as possible.

We are considering introducing our own internal "optional" type that would be used when a field is both optional and nullable at some point in the future.

TristanSpeakEasy avatar Oct 16 '23 11:10 TristanSpeakEasy

@TristanSpeakEasy thank you for your work. I'll be waiting for it to happen.

teleskop150750 avatar Oct 16 '23 11:10 teleskop150750

@TristanSpeakEasy oapi-codegen x-go-type-import can override the type

teleskop150750 avatar Oct 16 '23 11:10 teleskop150750