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
When you define a oneOf type that has shared fields (e.g. ID) and you want to access this field, regardless of the underlying type, you need to perform a switch. If we had a method to return the underlying type as an interface it would make code less brittle as a new type being added to the spec would not need the switch to be updated in these circumstances.
typeAnythingstruct {
TypeAnythingType// switch on this fieldFooFooBarBarBazBaz
}
// This is the method I'd like to see generated.func (aAnything) GetValue() any {
switcha.Type {
caseFooAnything:
returna.FoocaseBarAnything:
returna.BarcaseBazAnything:
returna.Bazdefault:
returnnil
}
}
Right now we cannot get around being very explicit such as the example below, with the added issue of it breaking if another type is added to the spec.
Description
When you define a oneOf type that has shared fields (e.g. ID) and you want to access this field, regardless of the underlying type, you need to perform a switch. If we had a method to return the underlying type as an interface it would make code less brittle as a new type being added to the spec would not need the switch to be updated in these circumstances.
See the example below:
This would allow code like this:
Right now we cannot get around being very explicit such as the example below, with the added issue of it breaking if another type is added to the spec.
References
The text was updated successfully, but these errors were encountered: