speakeasy
speakeasy copied to clipboard
[SPE-2631] How to implement an optional nullable field?
"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"?
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 thank you for your work. I'll be waiting for it to happen.
@TristanSpeakEasy oapi-codegen x-go-type-import
can override the type