Bug Report Checklist
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
-
Save the OpenAPI declaration above as enum-not-imported.yaml.
-
Validate it:
java -jar openapi-generator-cli.jar validate -i enum-not-imported.yaml
-
Generate the Java client with the command above.
-
Compile the generated client:
cd generated
mvn -q -DskipTests compile
Related issues/PRs
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;
Bug Report Checklist
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:
but generates
DefaultApi.javawith unqualified uses ofStockState:DefaultApi.javadoes not contain:Compilation fails five times with:
Expected result
The generated Java client should compile.
DefaultApi.javashould importStockState, or use its fully qualified name.openapi-generator version
7.26.0-SNAPSHOT, built from current master commitb391b2b98c5926ee9842ef3bc863b57c4d824bbe.Also happens in
7.24.0.This has not been bisected to identify the first affected version.
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Save the OpenAPI declaration above as
enum-not-imported.yaml.Validate it:
Generate the Java client with the command above.
Compile the generated client:
cd generated mvn -q -DskipTests compileRelated issues/PRs
Suggest a fix
DefaultCodegen#fromParameterhandles 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: