[php-nextgen] Respect composerPackageName Config Option - #24943
Conversation
There was a problem hiding this comment.
2 issues found across 1 file
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="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java:336">
P3: The new config-override path in `getComposerPackageName()` has no test. `AbstractPhpCodegenTest.testGetComposerPackageName` only exercises the git-derived fallback, so a future refactor that drops the `composerPackageName` branch would not be caught. Add a data-provider row (or a dedicated test) that sets `composerPackageName` alongside git ids and asserts the configured value wins, and that an empty configured value falls back to git info.</violation>
<violation number="2" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java:1052">
P2: An explicitly configured `composerPackageName` is emitted verbatim into the generated `composer.json` `name` field without the validation the git-derived path enforces. The derived branch rejects values via `Pattern.matches("^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$", ...)` (lowercase vendor/project only), but the new early-return path accepts anything non-empty, including uppercase, spaces, or invalid separators, producing an invalid `composer.json` that fails `composer validate`/`composer install`. Before this PR the option was never read, so invalid values couldn't reach the template. Validate the explicit value (and trim it) before returning it, and fall back to the derived name when it doesn't match composer's naming rules.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| if (this.composerPackageName != null && !this.composerPackageName.isEmpty()) { | ||
| return this.composerPackageName; | ||
| } |
There was a problem hiding this comment.
P2: An explicitly configured composerPackageName is emitted verbatim into the generated composer.json name field without the validation the git-derived path enforces. The derived branch rejects values via Pattern.matches("^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$", ...) (lowercase vendor/project only), but the new early-return path accepts anything non-empty, including uppercase, spaces, or invalid separators, producing an invalid composer.json that fails composer validate/composer install. Before this PR the option was never read, so invalid values couldn't reach the template. Validate the explicit value (and trim it) before returning it, and fall back to the derived name when it doesn't match composer's naming rules.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java, line 1052:
<comment>An explicitly configured `composerPackageName` is emitted verbatim into the generated `composer.json` `name` field without the validation the git-derived path enforces. The derived branch rejects values via `Pattern.matches("^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$", ...)` (lowercase vendor/project only), but the new early-return path accepts anything non-empty, including uppercase, spaces, or invalid separators, producing an invalid `composer.json` that fails `composer validate`/`composer install`. Before this PR the option was never read, so invalid values couldn't reach the template. Validate the explicit value (and trim it) before returning it, and fall back to the derived name when it doesn't match composer's naming rules.</comment>
<file context>
@@ -1038,11 +1043,15 @@ public void postProcessFile(File file, String fileType) {
* @return package name or empty string on fail
*/
public String getComposerPackageName() {
+ if (this.composerPackageName != null && !this.composerPackageName.isEmpty()) {
+ return this.composerPackageName;
+ }
</file context>
| if (this.composerPackageName != null && !this.composerPackageName.isEmpty()) { | |
| return this.composerPackageName; | |
| } | |
| if (this.composerPackageName != null | |
| && !this.composerPackageName.trim().isEmpty() | |
| && Pattern.matches("^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$", this.composerPackageName)) { | |
| return this.composerPackageName; | |
| } |
| this.setGitRepoId((String) additionalProperties.get(CodegenConstants.GIT_REPO_ID)); | ||
| } | ||
|
|
||
| if (additionalProperties.containsKey(CodegenConstants.COMPOSER_PACKAGE_NAME)) { |
There was a problem hiding this comment.
P3: The new config-override path in getComposerPackageName() has no test. AbstractPhpCodegenTest.testGetComposerPackageName only exercises the git-derived fallback, so a future refactor that drops the composerPackageName branch would not be caught. Add a data-provider row (or a dedicated test) that sets composerPackageName alongside git ids and asserts the configured value wins, and that an empty configured value falls back to git info.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java, line 336:
<comment>The new config-override path in `getComposerPackageName()` has no test. `AbstractPhpCodegenTest.testGetComposerPackageName` only exercises the git-derived fallback, so a future refactor that drops the `composerPackageName` branch would not be caught. Add a data-provider row (or a dedicated test) that sets `composerPackageName` alongside git ids and asserts the configured value wins, and that an empty configured value falls back to git info.</comment>
<file context>
@@ -332,6 +333,10 @@ public void processOpts() {
this.setGitRepoId((String) additionalProperties.get(CodegenConstants.GIT_REPO_ID));
}
+ if (additionalProperties.containsKey(CodegenConstants.COMPOSER_PACKAGE_NAME)) {
+ this.setComposerPackageName((String) additionalProperties.get(CodegenConstants.COMPOSER_PACKAGE_NAME));
+ }
</file context>
Currently,
getComposerPackageName()doesn't respect thecomposerPackageNameconfig variable and derives the value solely fromgitUserId/gitRepoId. This PR fixes that by first looking for a non-null, non-emptycomposerPackageNameand then falling back to the git info.PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
@jebentier (2017/07), @dkarlovi (2017/07), @mandrean (2017/08), @jfastnacht (2017/09), @ybelenko (2018/07), @renepardon (2018/12)
Summary by cubic
Fixes the PHP generator's
getComposerPackageName()to honor thecomposerPackageNameconfig option. It now returns the configured value when set, and only falls back to deriving fromgitUserId/gitRepoIdwhen it's missing or empty.Written for commit d6ef73d. Summary will update on new commits.