OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.3k stars 6.44k forks source link

[BUG][GO] Some errors with `oneOf` type #12920

Open uri200 opened 2 years ago

uri200 commented 2 years ago

Bug Report Checklist

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
uri200 commented 2 years ago

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
}