[Java] Fix #24875: Add missing import for direct enum property reference in parameters - #24918
Conversation
There was a problem hiding this comment.
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]'; |
There was a problem hiding this comment.
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>
6659404 to
9fb3426
Compare
…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
9fb3426 to
3ba2cb1
Compare
|
The JavaScript CI failure is a pre-existing issue on master, |
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 requiredimport statement was missing from the generated API class, causing
compilation failures.
This fix updates
DefaultCodegen#fromParameterto add the resolved enumtype to the operation's import set, with a guard against composed/generic
types (containing
&or<) that are not valid single-type imports.PR Checklist
mvn clean installto ensure all unit tests pass.DefaultCodegenTest.javaverifying enum importsare included when a parameter directly references an enum property.
./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; nowfromParameteradds 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 thejavascript-apollo,javascript-es6, andjavascript-promise-es6generators.Written for commit 3ba2cb1. Summary will update on new commits.