oapi-codegen
oapi-codegen copied to clipboard
Discriminators don't work with enum values
In testing 96482c12b, I've found that the From... and Merge... methods generated by discriminator usage do not use the type generated from usage of enum in the spec.
For example, my discriminator is a property named protocol, with type: string with enum values of "HTTPS, TCP, UDP". The generator creates a custom type for the protocol field in structs like LoadBalancerHTTPSProtocol.
type LoadBalancerHttpsProtocol string
const (
LoadBalancerHttpsProtocolHTTPS LoadBalancerHttpsProtocol = "HTTPS"
LoadBalancerHttpsProtocolTCP LoadBalancerHttpsProtocol = "TCP"
LoadBalancerHttpsProtocolUDP LoadBalancerHttpsProtocol = "UDP"
)
Later, in generated Merge... and From... methods, we can see lines like v.Protocol = "HTTPS", which will not compile, because "HTTPS" needs to use the proper type.