Skip to content

[BUG] [Java] Object defaults with enum properties generate invalid fluent builder expressions #24298

Closed

Description

@nh-ive

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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)
Description

When a schema defines a default value for an object that contains an enum property, the Java generator generates an invalid fluent builder expression.

Expected output:

private OutputFormat format = new OutputFormat().order(OutputFormat.OrderEnum.SIMILARITY).limit(10);

Actual output:

private OutputFormat format = new OutputFormat().order("SIMILARITY").limit(10);
openapi-generator version

7.24.0-SNAPSHOT (latest master)

OpenAPI declaration file content or url
openapi: "3.1.0"
info:
  title: Enum Default Issue Demo
  version: 1.0.0

components:
  schemas:
    OutputFormat:
      type: object
      properties:
        order:
          type: string
          enum:
            - IMPORTANCE
            - SIMILARITY
        limit:
          type: integer
      default:
        order: SIMILARITY
        limit: 10

    Formatter:
      type: object
      properties:
        format:
          $ref: '#/components/schemas/OutputFormat'
Generation Details
<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>7.24.0-SNAPSHOT</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${project.basedir}/src/main/resources/api/OpenApi.yaml</inputSpec>
                <generatorName>java</generatorName>
                <library>native</library>
                <skipValidateSpec>true</skipValidateSpec>
                <generateApiTests>false</generateApiTests>
                <generateModelTests>false</generateModelTests>
                <configOptions>
                    <useJakartaEe>true</useJakartaEe>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>
Steps to reproduce
Related issues/PRs
Suggest a fix

The issue seems to be that the if statement in the method toObjectDefaultValue of the class AbstractJavaCodegen is missing a case for enums.

Activity

  1. added a commit that references this issue on Jul 30, 2026
    095eeda
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