Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
@Setter protected String developerOrganizationUrl = "https://openapi-generator.tech";
@Setter protected String srcBasePath = "lib";
@Setter protected String testBasePath = "test";
@Setter protected String composerPackageName = null;
protected String docsBasePath = "docs";
protected String apiDirName = "Api";
protected String modelDirName = "Model";
Expand Down Expand Up @@ -332,6 +333,10 @@ public void processOpts() {
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>

this.setComposerPackageName((String) additionalProperties.get(CodegenConstants.COMPOSER_PACKAGE_NAME));
}

if (!this.getComposerPackageName().isEmpty()) {
additionalProperties.put("composerPackageName", this.getComposerPackageName());
}
Expand Down Expand Up @@ -1038,11 +1043,15 @@ public void postProcessFile(File file, String fileType) {
}

/**
* Get Composer package name based on GIT_USER_ID and GIT_REPO_ID.
* Get Composer package name. Returns the explicitly configured value if set, otherwise
* derives it from GIT_USER_ID and GIT_REPO_ID.
*
* @return package name or empty string on fail
*/
public String getComposerPackageName() {
if (this.composerPackageName != null && !this.composerPackageName.isEmpty()) {
return this.composerPackageName;
}
Comment on lines +1052 to +1054

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;
}

String packageName = this.getGitUserId() + "/" + this.getGitRepoId();
if (
packageName.contentEquals("/")
Expand Down
Loading