Skip to content

Commit

Permalink
Fix #14645 Permit to customize more composer.json parts (#16012)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugofintecture committed Jul 12, 2023
1 parent 3325edc commit 9aa6e25
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ public class CodegenConstants {
public static final String PACKAGE_COMPANY_DESC = "Specifies an AssemblyCompany for the .NET Framework global assembly attributes stored in the AssemblyInfo file.";
public static final String PACKAGE_AUTHORS = "packageAuthors";
public static final String PACKAGE_AUTHORS_DESC = "Specifies Authors property in the .NET Core project file.";
public static final String PACKAGE_AUTHORS_URL = "packageAuthorsUrl";
public static final String PACKAGE_AUTHORS_URL_DESC = "Specifies Authors URL property in the PHP composer.json file.";
public static final String PACKAGE_COPYRIGHT = "packageCopyright";
public static final String PACKAGE_COPYRIGHT_DESC = "Specifies an AssemblyCopyright for the .NET Framework global assembly attributes stored in the AssemblyInfo file.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
protected String invokerPackage = "php";
protected String packageName = "php-base";
protected String artifactVersion = null;
protected String artifactUrl = "https://openapi-generator.tech";
protected String licenseName = "unlicense";
protected String developerOrganization = "OpenAPI";
protected String developerOrganizationUrl = "https://openapi-generator.tech";
protected String srcBasePath = "lib";
protected String testBasePath = "test";
protected String docsBasePath = "docs";
Expand Down Expand Up @@ -147,6 +151,10 @@ public AbstractPhpCodegen() {
cliOptions.add(new CliOption(PACKAGE_NAME, "The main package name for classes. e.g. GeneratedPetstore"));
cliOptions.add(new CliOption(SRC_BASE_PATH, "The directory to serve as source root."));
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_VERSION, "The version to use in the composer package version field. e.g. 1.2.3"));
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_URL, CodegenConstants.ARTIFACT_URL_DESC));
cliOptions.add(new CliOption(CodegenConstants.LICENSE_NAME, CodegenConstants.LICENSE_NAME_DESC));
cliOptions.add(new CliOption(CodegenConstants.DEVELOPER_ORGANIZATION, CodegenConstants.DEVELOPER_ORGANIZATION_DESC));
cliOptions.add(new CliOption(CodegenConstants.DEVELOPER_ORGANIZATION_URL, CodegenConstants.DEVELOPER_ORGANIZATION_URL_DESC));
}

@Override
Expand Down Expand Up @@ -192,12 +200,41 @@ public void processOpts() {
}
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);

// {{artifactVersion}}
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_VERSION)) {
this.setArtifactVersion((String) additionalProperties.get(CodegenConstants.ARTIFACT_VERSION));
} else {
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
}

// {{artifactUrl}}
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_URL)) {
this.setArtifactUrl((String) additionalProperties.get(CodegenConstants.ARTIFACT_URL));
} else {
additionalProperties.put(CodegenConstants.ARTIFACT_URL, artifactUrl);
}

// {{licenseName}}
if (additionalProperties.containsKey(CodegenConstants.LICENSE_NAME)) {
this.setLicenseName((String) additionalProperties.get(CodegenConstants.LICENSE_NAME));
} else {
additionalProperties.put(CodegenConstants.LICENSE_NAME, licenseName);
}

// {{developerOrganization}}
if (additionalProperties.containsKey(CodegenConstants.DEVELOPER_ORGANIZATION)) {
this.setDeveloperOrganization((String) additionalProperties.get(CodegenConstants.DEVELOPER_ORGANIZATION));
} else {
additionalProperties.put(CodegenConstants.DEVELOPER_ORGANIZATION, developerOrganization);
}

// {{developerOrganizationUrl}}
if (additionalProperties.containsKey(CodegenConstants.DEVELOPER_ORGANIZATION_URL)) {
this.setDeveloperOrganizationUrl((String) additionalProperties.get(CodegenConstants.DEVELOPER_ORGANIZATION_URL));
} else {
additionalProperties.put(CodegenConstants.DEVELOPER_ORGANIZATION_URL, developerOrganizationUrl);
}

if (additionalProperties.containsKey(VARIABLE_NAMING_CONVENTION)) {
this.setParameterNamingConvention((String) additionalProperties.get(VARIABLE_NAMING_CONVENTION));
}
Expand Down Expand Up @@ -380,10 +417,6 @@ public String getSchemaType(Schema p) {
return toModelName(type);
}

public String getInvokerPackage() {
return invokerPackage;
}

public void setInvokerPackage(String invokerPackage) {
this.invokerPackage = invokerPackage;
}
Expand All @@ -392,6 +425,22 @@ public void setArtifactVersion(String artifactVersion) {
this.artifactVersion = artifactVersion;
}

public void setArtifactUrl(String artifactUrl) {
this.artifactUrl = artifactUrl;
}

public void setLicenseName(String licenseName) {
this.licenseName = licenseName;
}

public void setDeveloperOrganization(String developerOrganization) {
this.developerOrganization = developerOrganization;
}

public void setDeveloperOrganizationUrl(String developerOrganizationUrl) {
this.developerOrganizationUrl = developerOrganizationUrl;
}

public void setPackageName(String packageName) {
this.packageName = packageName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
"rest",
"api"
],
"homepage": "https://openapi-generator.tech",
"license": "unlicense",
"homepage": "{{artifactUrl}}",
"license": "{{licenseName}}",
"authors": [
{
"name": "OpenAPI-Generator contributors",
"homepage": "https://openapi-generator.tech"
"name": "{{developerOrganization}}",
"homepage": "{{developerOrganizationUrl}}"
}
],
"require": {
Expand Down

0 comments on commit 9aa6e25

Please sign in to comment.