Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enum not generated when used with anyof #1429

Open
Mo3m3n opened this issue Jan 19, 2024 · 1 comment · May be fixed by #1522
Open

enum not generated when used with anyof #1429

Mo3m3n opened this issue Jan 19, 2024 · 1 comment · May be fixed by #1522
Labels
area:enums area:*of `oneOf`/`anyOf`/`allOf`

Comments

@Mo3m3n
Copy link

Mo3m3n commented Jan 19, 2024

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
@jamietanna
Copy link
Collaborator

Related to #648

@jamietanna jamietanna added area:enums area:*of `oneOf`/`anyOf`/`allOf` labels Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:enums area:*of `oneOf`/`anyOf`/`allOf`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants