Skip to content

[Java] Fix #24875: Add missing import for direct enum property reference in parameters - #24918

Open
Harshavardhan2951 wants to merge 1 commit into
OpenAPITools:masterfrom
Harshavardhan2951:fix/24875-enum-parameter-import
Open

[Java] Fix #24875: Add missing import for direct enum property reference in parameters#24918
Harshavardhan2951 wants to merge 1 commit into
OpenAPITools:masterfrom
Harshavardhan2951:fix/24875-enum-parameter-import

Conversation

@Harshavardhan2951

@Harshavardhan2951 Harshavardhan2951 commented Sep 10, 2026

Copy link
Copy Markdown

PR Title

[Java] Fix #24875: Add missing import for direct enum property reference in parameters

Description of the change

Fixes #24875

When a query parameter references a direct enum property via
$ref: "#/components/schemas/Component/properties/field", the required
import statement was missing from the generated API class, causing
compilation failures.

This fix updates DefaultCodegen#fromParameter to add the resolved enum
type to the operation's import set, with a guard against composed/generic
types (containing & or <) that are not valid single-type imports.

PR Checklist

  • Read the contribution guidelines.
  • Pull Request title conforms to conventions.
  • Ran mvn clean install to ensure all unit tests pass.
  • Added unit test in DefaultCodegenTest.java verifying enum imports
    are included when a parameter directly references an enum property.
  • Generated updated samples using ./bin/generate-samples.sh.

Summary by cubic

Fixes generated code missing enum imports when a query parameter directly references an enum property via $ref (issue #24875). Previously the generated API class failed to compile because the resolved enum type wasn't imported; now fromParameter adds it to the operation's imports, skipping composed/generic type strings containing & or <.

Side effect: regenerated JavaScript samples now include import [String] from '../model/[String]' lines, which are invalid JavaScript imports and may break the javascript-apollo, javascript-es6, and javascript-promise-es6 generators.

Written for commit 3ba2cb1. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 9 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="samples/client/petstore/javascript-apollo/src/api/PetApi.js">

<violation number="1" location="samples/client/petstore/javascript-apollo/src/api/PetApi.js:19">
P1: This generated import line is invalid JavaScript: `import [String] ...` throws `SyntaxError: Unexpected token '['`, and there is no `../model/[String]` module to load. It appears for array-of-enum parameters (here `status` in `findPetsByStatus`) because the new `imports.add(codegenParameter.dataType)` guard in `DefaultCodegen.fromParameter` only rejects types containing `&` or `<`, but the array dataType is the bracket-wrapped `[String]`, which passes the guard. The guard must also exclude container types (square brackets), or only add the import when `codegenProperty` is a scalar enum ref and not an array.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

import ApiClient from "../ApiClient";
import ApiResponse from '../model/ApiResponse';
import Pet from '../model/Pet';
import [String] from '../model/[String]';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: This generated import line is invalid JavaScript: import [String] ... throws SyntaxError: Unexpected token '[', and there is no ../model/[String] module to load. It appears for array-of-enum parameters (here status in findPetsByStatus) because the new imports.add(codegenParameter.dataType) guard in DefaultCodegen.fromParameter only rejects types containing & or <, but the array dataType is the bracket-wrapped [String], which passes the guard. The guard must also exclude container types (square brackets), or only add the import when codegenProperty is a scalar enum ref and not an array.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/javascript-apollo/src/api/PetApi.js, line 19:

<comment>This generated import line is invalid JavaScript: `import [String] ...` throws `SyntaxError: Unexpected token '['`, and there is no `../model/[String]` module to load. It appears for array-of-enum parameters (here `status` in `findPetsByStatus`) because the new `imports.add(codegenParameter.dataType)` guard in `DefaultCodegen.fromParameter` only rejects types containing `&` or `<`, but the array dataType is the bracket-wrapped `[String]`, which passes the guard. The guard must also exclude container types (square brackets), or only add the import when `codegenProperty` is a scalar enum ref and not an array.</comment>

<file context>
@@ -16,6 +16,7 @@
 import ApiClient from "../ApiClient";
 import ApiResponse from '../model/ApiResponse';
 import Pet from '../model/Pet';
+import [String] from '../model/[String]';
 
 /**
</file context>

@Harshavardhan2951
Harshavardhan2951 force-pushed the fix/24875-enum-parameter-import branch from 6659404 to 9fb3426 Compare September 10, 2026 03:46
…eference in parameters

DefaultCodegen#fromParameter handles imports for array items but not
for direct scalar enum references. This adds the generated enum
model type to operation imports, guarding against composed/generic
type strings (containing '&' or '<') that aren't valid import targets.

Fixes OpenAPITools#24875
@Harshavardhan2951
Harshavardhan2951 force-pushed the fix/24875-enum-parameter-import branch from 9fb3426 to 3ba2cb1 Compare September 10, 2026 03:58
@Harshavardhan2951

Copy link
Copy Markdown
Author

The JavaScript CI failure is a pre-existing issue on master,
unrelated to this Java fix. The same 6 JS files change when
running ./bin/generate-samples.sh on master branch as well.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant