Skip to content

enum not generated when used with anyof #1429

@Mo3m3n

Description

@Mo3m3n

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions