oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Discriminators don't work with enum values

Open jmcnevin opened this issue 3 years ago • 0 comments

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.

jmcnevin avatar Oct 03 '22 15:10 jmcnevin