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.79k stars 6.57k forks source link

[BUG] oneOf/required does not work correctly for golang #11314

Open Pisztrang opened 2 years ago

Pisztrang commented 2 years ago

Hi

I have this yaml file:

openapi: 3.0.0
info:
  version: '1.0.0'
  title: 'Test'

paths: {}
components:
  schemas:
    Test:
      type: object
      oneOf:
        - required:
          - test1
        - required:
          - test2
      properties:
        normalField:
          type: string
        test1:
          $ref: '#/components/schemas/Test1'
        test2:
          $ref: '#/components/schemas/Test2'
        normalField2:
          type: string

    Test1: 
      type: object
      required:
        - a
        - b
        - c
      properties:
        a:
          type: int
        b:
          type: string
        c:
          type: string
    Test2:
      type: object
      required:
        - ab
        - bb
        - cc
      properties:
        aa:
          type: int
        bb:
          type: string
        cc:
          type: string

when I execute the generator for golang, then I receive this generated datatype:

// Test - struct for Test 
type Test struct {
    interface{} *interface{}
}

Is it possible to make this better, since basically it gives error and actually the fields are not included at all.

If I remove the oneOf, then it generates the correct datatype, but then I loose the checker functions. thanks Akos

gainsley commented 1 year ago

I'm hitting the same issue. Also if you replace "oneof" with "anyof" above the same problem occurs. Related to: https://github.com/OpenAPITools/openapi-generator/issues/1745 and https://github.com/OpenAPITools/openapi-generator/issues/8086