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

enum not generated when used with anyof

Open Mo3m3n opened this issue 2 years ago • 1 comments

The types generated from the following spec sample will not generate the enum definition:

openapi: 3.0.0
paths:
  /test:
    get:
      operationId: Test
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/test'
components:
  schemas:
    test:
      type: object
      anyOf:
        - properties:
            fieldA:
              type: string
        - properties:
            fieldA:
              type: string
              enum:
                - foo
                - bar

resulting in undefined: Test1FieldA with the following generated code

// Code generated by github.com/deepmap/oapi-codegen/v2 version v2.0.0 DO NOT EDIT.

// Test defines model for test.
type Test struct {
	union json.RawMessage
}

// Test0 defines model for .
type Test0 struct {
	FieldA *string `json:"fieldA,omitempty"`
}

// Test1 defines model for .
type Test1 struct {
	FieldA *Test1FieldA `json:"fieldA,omitempty"`
}

I have seen that a similar issue was fixed before but it deals with a different usecase:

components:
  schemas:
    test:
      properties:
        fieldA:
          anyOf:
            - type: string
            - type: string
              enum:
                - foo
                - bar

Mo3m3n avatar Jan 19 '24 13:01 Mo3m3n

Related to #648

jamietanna avatar Jan 23 '24 09:01 jamietanna