Skip to content

[php-nextgen] Respect composerPackageName Config Option - #24943

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
ckoegel:php-nextgen-name
Sep 15, 2026
Merged

wing328 merged 1 commit into
OpenAPITools:masterfrom
ckoegel:php-nextgen-name

Conversation

@ckoegel

@ckoegel ckoegel commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Currently, getComposerPackageName() doesn't respect the composerPackageName config variable and derives the value solely from gitUserId/gitRepoId. This PR fixes that by first looking for a non-null, non-empty composerPackageName and then falling back to the git info.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@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 the composerPackageName config option. It now returns the configured value when set, and only falls back to deriving from gitUserId/gitRepoId when it's missing or empty.

Written for commit d6ef73d. 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.

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

Comment on lines +1052 to +1054
if (this.composerPackageName != null && !this.composerPackageName.isEmpty()) {
return this.composerPackageName;
}

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.

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>
Suggested change
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)) {

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.

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>

@wing328
wing328 merged commit 46b136c into OpenAPITools:master Sep 15, 2026
15 checks passed
@wing328 wing328 added this to the 7.26.0 milestone Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants