Skip to content

[BUG][JAVA] Direct property enum reference used by parameter omits generated model import #24875

Description

@mricken

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

The Java client generator produces uncompilable code when a query parameter schema directly references an inline enum property of a component schema.

The generator promotes the inline enum to a model enum (StockState), but the generated API class uses that type without importing it.

Actual result

The generator creates:

src/main/java/org/openapitools/client/model/StockState.java

but generates DefaultApi.java with unqualified uses of StockState:

public okhttp3.Call listArchivesCall(
    @javax.annotation.Nullable StockState state,
    final ApiCallback _callback) throws ApiException {

DefaultApi.java does not contain:

import org.openapitools.client.model.StockState;

Compilation fails five times with:

error: cannot find symbol
  symbol:   class StockState
  location: class DefaultApi

Expected result

The generated Java client should compile. DefaultApi.java should import StockState, or use its fully qualified name.

openapi-generator version

7.26.0-SNAPSHOT, built from current master commit b391b2b98c5926ee9842ef3bc863b57c4d824bbe.

Also happens in 7.24.0.

This has not been bisected to identify the first affected version.

OpenAPI declaration file content or url
openapi: 3.1.0
info:
  title: Enum parameter import
  version: 1.0.0
paths:
  /archives:
    get:
      operationId: listArchives
      parameters:
        - name: state
          in: query
          required: false
          schema:
            $ref: "#/components/schemas/Archive/properties/state"
      responses:
        "200":
          description: Success
components:
  schemas:
    Archive:
      type: object
      properties:
        state:
          type: string
          enum:
            - ACTIVE
Generation Details
java -jar openapi-generator-cli.jar generate \
  -g java \
  -i enum-not-imported.yaml \
  -o generated \
  --skip-validate-spec \
  --additional-properties modelNamePrefix=Stock,hideGenerationTimestamp=true
Steps to reproduce
  1. Save the OpenAPI declaration above as enum-not-imported.yaml.

  2. Validate it:

    java -jar openapi-generator-cli.jar validate -i enum-not-imported.yaml
  3. Generate the Java client with the command above.

  4. Compile the generated client:

    cd generated
    mvn -q -DskipTests compile
Related issues/PRs
  • did not find any
Suggest a fix

DefaultCodegen#fromParameter handles imports specially for array parameter items, but the direct scalar enum reference in this reproducer is not added to the API operation's import set.

When a parameter's resolved schema produces a generated enum model type, add that type to the operation imports so the Java API template emits:

import org.openapitools.client.model.StockState;

Activity

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