Skip to content

Commit dff6a3e

Browse files
authored
Merge pull request #962 from swagger-api/urlConfigOption
Git repo Base URL config option
2 parents 8d616c0 + 7fbe387 commit dff6a3e

File tree

5 files changed

+34
-8
lines changed

5 files changed

+34
-8
lines changed

src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public abstract class DefaultCodegenConfig implements CodegenConfig {
160160
protected Boolean sortParamsByRequiredFlag = true;
161161
protected Boolean ensureUniqueParams = true;
162162
protected Boolean allowUnicodeIdentifiers = false;
163-
protected String gitUserId, gitRepoId, releaseNote;
163+
protected String gitUserId, gitRepoId, releaseNote, gitRepoBaseURL;
164164
protected String httpUserAgent;
165165
protected Boolean hideGenerationTimestamp = true;
166166
protected TemplateEngine templateEngine = new HandlebarTemplateEngine(this);
@@ -3519,6 +3519,26 @@ public String getGitRepoId() {
35193519
return gitRepoId;
35203520
}
35213521

3522+
3523+
/**
3524+
* Git repo Base URL
3525+
*
3526+
* @return Git repo Base URL
3527+
*/
3528+
public String getGitRepoBaseURL() {
3529+
return gitRepoBaseURL;
3530+
}
3531+
3532+
/**
3533+
* Set Git repo Base URL.
3534+
*
3535+
* @param gitRepoBaseURL Git repo Base URL
3536+
*/
3537+
public void setGitRepoBaseURL(String gitRepoBaseURL) {
3538+
this.gitRepoBaseURL = gitRepoBaseURL;
3539+
}
3540+
3541+
35223542
/**
35233543
* Set release note.
35243544
*

src/main/java/io/swagger/codegen/v3/generators/php/AbstractPhpCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public String toSrcPath(String packageName, String basePath) {
251251
}
252252

253253
@Override
254-
public String escapeReservedWord(String name) {
254+
public String escapeReservedWord(String name) {
255255
if(this.reservedWordsMappings().containsKey(name)) {
256256
return this.reservedWordsMappings().get(name);
257257
}

src/main/java/io/swagger/codegen/v3/generators/php/PhpClientCodegen.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ public PhpClientCodegen() {
110110

111111
instantiationTypes.put("array", "array");
112112
instantiationTypes.put("map", "map");
113-
114-
113+
115114
// provide primitives to mustache template
116115
List<String> sortedLanguageSpecificPrimitives= new ArrayList<String>(languageSpecificPrimitives);
117116
Collections.sort(sortedLanguageSpecificPrimitives);
@@ -152,6 +151,7 @@ public PhpClientCodegen() {
152151
cliOptions.add(new CliOption(CodegenConstants.GIT_USER_ID, CodegenConstants.GIT_USER_ID_DESC));
153152
cliOptions.add(new CliOption(COMPOSER_PROJECT_NAME, "The project name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name. e.g. petstore-client. IMPORTANT NOTE (2016/03): composerProjectName will be deprecated and replaced by gitRepoId in the next swagger-codegen release"));
154153
cliOptions.add(new CliOption(CodegenConstants.GIT_REPO_ID, CodegenConstants.GIT_REPO_ID_DESC));
154+
cliOptions.add(new CliOption(CodegenConstants.GIT_REPO_BASE_URL, CodegenConstants.GIT_REPO_BASE_URL_DESC));
155155
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_VERSION, "The version to use in the composer package version field. e.g. 1.2.3"));
156156
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, "hides the timestamp when files were generated")
157157
.defaultValue(Boolean.TRUE.toString()));
@@ -280,6 +280,12 @@ public void processOpts() {
280280
additionalProperties.put(CodegenConstants.GIT_REPO_ID, gitRepoId);
281281
}
282282

283+
if (additionalProperties.containsKey(CodegenConstants.GIT_REPO_BASE_URL)) {
284+
this.setGitRepoBaseURL((String) additionalProperties.get(CodegenConstants.GIT_REPO_BASE_URL));
285+
} else {
286+
additionalProperties.put(CodegenConstants.GIT_REPO_BASE_URL, gitRepoBaseURL);
287+
}
288+
283289
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_VERSION)) {
284290
this.setArtifactVersion((String) additionalProperties.get(CodegenConstants.ARTIFACT_VERSION));
285291
} else {

src/main/resources/handlebars/php/README.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ To install the bindings via [Composer](http://getcomposer.org/), add the followi
3131
"repositories": [
3232
{
3333
"type": "git",
34-
"url": "https://github.com/{{#composerVendorName}}{{.}}{{/composerVendorName}}{{^composerVendorName}}{{gitUserId}}{{/composerVendorName}}/{{#composerProjectName}}{{.}}{{/composerProjectName}}{{^composerProjectName}}{{gitRepoId}}{{/composerProjectName}}.git"
34+
"url": "http://{{gitRepoBaseURL}}.com/{{#composerVendorName}}{{.}}{{/composerVendorName}}{{^composerVendorName}}{{gitUserId}}{{/composerVendorName}}/{{#composerProjectName}}{{.}}{{/composerProjectName}}{{^composerProjectName}}{{gitRepoId}}{{/composerProjectName}}.git"
3535
}
3636
],
3737
"require": {

src/main/resources/handlebars/php/git_push.sh.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ if [ "$git_remote" = "" ]; then # git remote not defined
3737

3838
if [ "$GIT_TOKEN" = "" ]; then
3939
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
40-
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
40+
git remote add origin https://${git_repo_base_url}.com/${git_user_id}/${git_repo_id}.git
4141
else
42-
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
42+
git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_repo_base_url}.com/${git_user_id}/${git_repo_id}.git
4343
fi
4444

4545
fi
4646

4747
git pull origin master
4848

4949
# Pushes (Forces) the changes in the local repository up to the remote repository
50-
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
50+
echo "Git pushing to https://${git_repo_base_url}.com/${git_user_id}/${git_repo_id}.git"
5151
git push origin master 2>&1 | grep -v 'To https'
5252

0 commit comments

Comments
 (0)