Skip to content

[BUG] default values for references enums are not generated correctly #14689

Closed

Description

@robbertvanwaveren

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)

Seen this bug in Java client generation but I think its broken for multiple languages.

Description

properties that set a default but references an enum type using allOf results in incompilable java client code.

openapi-generator version

regression since 6.3.0 (probably since #14130 was merged)

OpenAPI declaration file content or url
openapi: 3.0.2
info:
  title: Bug
  version: 0.0.1
paths:
  /test:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                test:
                  allOf:
                    - $ref: '#/components/schemas/TestEnum'
                  default: Bar
      responses:
        '200':
          description: Ok
components:
  schemas:
    TestEnum:
      enum:
        - Foo
        - Bar
      type: string
Generation Details

openapi-generator-cli generate -i default-for-referenced-enum.yaml -g java -o enum-issue

results in TestPostRequest.java with line 54 being:

private TestEnum test = Bar;

instead of

private TestEnum test = TestEnum.BAR;
Steps to reproduce

see Generation Details

Related issues/PRs

regression since 6.3.0 (probably since #14130 was merged)

Suggest a fix

See linked PR #14692

Activity

  1. wing328 commented on Feb 14, 2023

    @wing328
    Member

    can you pls try the latest master? we've a PR to fix that.

  2. robbertvanwaveren commented on Feb 14, 2023

    @robbertvanwaveren
    ContributorAuthor

    @wing328 I started working from a synced master yesterday, its still seems broken without my fix.

  3. wing328 commented on Mar 6, 2023

    @wing328
    Member

    @robbertvanwaveren I've filed #14882 to fix it in the default codegen. I wonder if you can pull it to give it a try when you've time.

    (I tested with your spec and the result is good)

  4. robbertvanwaveren commented on Mar 6, 2023

    @robbertvanwaveren
    ContributorAuthor

    works like a charm @wing328

  5. Midorina commented on Apr 11, 2024

    @Midorina

    Hi. I have this issue in version 7.4.0.

  6. mostafazakaria commented on Oct 1, 2025

    @mostafazakaria

    @wing328 I am also facing same issue. My project is kotlin based and I am having size issues with my SDK as because of this issue I am forced to generate enums internally and have alot of duplicates which has a huge impact on final artifact size. Any news on fixing this?

    @Midorina any tips on how did you get your problem fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions