[BUG][GO] Some errors with `oneOf` type
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] Have you tested with the latest master to confirm the issue still exists?
- [x] Have you searched for related issues/PRs?
- [x] What's the actual output vs expected output?
- [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
We are generating client specs for go using 5g 3gpp swagger specs found here (https://raw.githubusercontent.com/jdegre/5GC_APIs/master/TS29522_TrafficInfluence.yaml)
java openapi-generator-cli-6.0.0.jar generate -i https://raw.githubusercontent.com/jdegre/5GC_APIs/master/TS29522_TrafficInfluence.yaml -g go -o ./client_trafficInfluence
Running gofmt you will see the files have some errors
gofmt -s -w .
specs/client_trafficInfluence/model_ip_addr.go:20:11: expected type, found '{'
specs/client_trafficInfluence/model_ip_addr.go:25:2: expected declaration, found 'return'
specs/client_trafficInfluence/model_ip_addr.go:34:2: expected declaration, found match
specs/client_trafficInfluence/model_route_to_location.go:20:2: expected '}', found 'interface'
specs/client_trafficInfluence/model_route_to_location.go:27:2: expected declaration, found 'if'
For example the type Interface{} is used twice on the definition. While t should define a sere of properies.
// IpAddr - Contains an IP adresse.
type IpAddr struct {
Interface{} *interface{}
}
// interface{}AsIpAddr is a convenience function that returns interface{} wrapped in IpAddr
func Interface{}AsIpAddr(v *interface{}) IpAddr {
return IpAddr{
Interface{}: v,
}
}
This is how it should look like (extracted from the server case)
// IpAddr - Contains an IP adresse.
type IpAddr struct {
// String identifying a IPv4 address formatted in the 'dotted decimal' notation as defined in RFC 1166.
Ipv4Addr string `json:"ipv4Addr,omitempty"`
Ipv6Addr Ipv6Addr1 `json:"ipv6Addr,omitempty"`
Ipv6Prefix Ipv6Prefix `json:"ipv6Prefix,omitempty"`
}
openapi-generator version
6.0.0
Generation Details
java openapi-generator-cli-6.0.0.jar generate -i https://raw.githubusercontent.com/jdegre/5GC_APIs/master/TS29522_TrafficInfluence.yaml -g go -o ./client_trafficInfluence
Steps to reproduce
Just run that command and it will generate the files
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/12955
Suggest a fix
Using the same command I also can see that complex constructions with anyOf is not supported properly. For example, on that schema I mentioned we have something like
TrafficInfluSub:
allOf:
- oneOf:
- required:
- afAppId
- required:
- trafficFilters
- required:
- ethTrafficFilters
- oneOf:
- required:
- ipv4Addr
- required:
- ipv6Addr
- required:
- macAddr
- required:
- gpsi
- required:
- externalGroupId
- required:
- anyUeInd
anyOf:
- not:
required:
- subscribedEvents
- required:
- notificationDestination
But when we generated the client with go we get the following object
// TrafficInfluSub Represents a traffic influence subscription.
type TrafficInfluSub struct {
OneOfAnyTypeAnyTypeAnyType *OneOfAnyTypeAnyTypeAnyType
OneOfAnyTypeAnyTypeAnyTypeAnyTypeAnyTypeAnyType *OneOfAnyTypeAnyTypeAnyTypeAnyTypeAnyTypeAnyType
}