Skip to content

Commit d3f26f7

Browse files
committed
Merge pull request #2366 from wing328/git_push_sh
Add git_push.sh and .gitignore to client generators
2 parents 9368fcc + b09d34e commit d3f26f7

File tree

174 files changed

+8767
-2799
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+8767
-2799
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AndroidClientCodegen.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ public String getSwaggerType(Property p) {
157157

158158
@Override
159159
public String toVarName(String name) {
160+
// sanitize name
161+
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
162+
160163
// replace - with _ e.g. created-at => created_at
161164
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
162165

@@ -302,6 +305,8 @@ private void addSupportingFilesForDefault() {
302305
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "ApiException.java"));
303306
supportingFiles.add(new SupportingFile("Pair.mustache",
304307
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "Pair.java"));
308+
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
309+
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
305310
}
306311

307312
private void addSupportingFilesForVolley() {

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ public void processOpts() {
210210
supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "compile-mono.sh"));
211211
supportingFiles.add(new SupportingFile("packages.config.mustache", "vendor" + java.io.File.separator, "packages.config"));
212212
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
213+
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
214+
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
215+
213216

214217
if (optionalAssemblyInfoFlag) {
215218
supportingFiles.add(new SupportingFile("AssemblyInfo.mustache", packageFolder + File.separator + "Properties", "AssemblyInfo.cs"));

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ClojureClientCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ public void preprocessSwagger(Swagger swagger) {
143143
final String baseNamespaceFolder = sourceFolder + File.separator + namespaceToFolder(baseNamespace);
144144
supportingFiles.add(new SupportingFile("project.mustache", "", "project.clj"));
145145
supportingFiles.add(new SupportingFile("core.mustache", baseNamespaceFolder, "core.clj"));
146+
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
147+
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
146148
}
147149

148150
@Override

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/DartClientCodegen.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ public void processOpts() {
150150
supportingFiles.add(new SupportingFile("auth/http_basic_auth.mustache", authFolder, "http_basic_auth.dart"));
151151
supportingFiles.add(new SupportingFile("auth/api_key_auth.mustache", authFolder, "api_key_auth.dart"));
152152
supportingFiles.add(new SupportingFile("auth/oauth.mustache", authFolder, "oauth.dart"));
153+
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
154+
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
155+
153156
}
154157

155158

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FlashClientCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ public void processOpts() {
153153
+ File.separator + "lib" + File.separator + "ext", "flexunit-cilistener-4.1.0_RC2-28-3.5.0.12683.swc"));
154154
supportingFiles.add(new SupportingFile("flexunit-core-flex-4.0.0.2-sdk3.5.0.12683.swc", sourceFolder
155155
+ File.separator + "lib" + File.separator + "ext", "flexunit-core-flex-4.0.0.2-sdk3.5.0.12683.swc"));
156+
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
157+
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
156158
}
157159

158160
private static String dropDots(String str) {

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ public void processOpts() {
129129
apiPackage = packageName;
130130

131131
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
132+
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
133+
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
132134
}
133135

134136
@Override

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ else if ("java8".equals(dateLibrary)) {
301301
importMapping.put("LocalDate", "java.time.LocalDate");
302302
importMapping.put("LocalDateTime", "java.time.LocalDateTime");
303303
}
304+
305+
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
306+
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
307+
304308
}
305309

306310
private boolean usesAnyRetrofitLibrary() {

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClientCodegen.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ public void preprocessSwagger(Swagger swagger) {
241241
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
242242
supportingFiles.add(new SupportingFile("index.mustache", sourceFolder, "index.js"));
243243
supportingFiles.add(new SupportingFile("ApiClient.mustache", sourceFolder, "ApiClient.js"));
244+
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
244245
}
245246

246247
@Override

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ObjcClientCodegen.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ public void processOpts() {
220220
supportingFiles.add(new SupportingFile("Configuration-header.mustache", swaggerFolder, classPrefix + "Configuration.h"));
221221
supportingFiles.add(new SupportingFile("podspec.mustache", "", podName + ".podspec"));
222222
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
223+
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
224+
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
225+
226+
223227
}
224228

225229
@Override

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ public void processOpts() {
225225
supportingFiles.add(new SupportingFile("autoload.mustache", getPackagePath(), "autoload.php"));
226226
supportingFiles.add(new SupportingFile("README.mustache", getPackagePath(), "README.md"));
227227
supportingFiles.add(new SupportingFile(".travis.yml", getPackagePath(), ".travis.yml"));
228+
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
229+
228230
}
229231

230232
@Override

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ public void processOpts() {
110110
supportingFiles.add(new SupportingFile("__init__package.mustache", swaggerFolder, "__init__.py"));
111111
supportingFiles.add(new SupportingFile("__init__model.mustache", modelPackage, "__init__.py"));
112112
supportingFiles.add(new SupportingFile("__init__api.mustache", apiPackage, "__init__.py"));
113+
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
114+
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
113115
}
114116

115117
private static String dropDots(String str) {

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ public void processOpts() {
220220
supportingFiles.add(new SupportingFile("configuration.mustache", gemFolder, "configuration.rb"));
221221
supportingFiles.add(new SupportingFile("version.mustache", gemFolder, "version.rb"));
222222
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
223+
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
223224
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
224225
}
225226

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ScalaClientCodegen.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public ScalaClientCodegen() {
7272
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
7373
supportingFiles.add(new SupportingFile("apiInvoker.mustache",
7474
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ApiInvoker.scala"));
75+
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
76+
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
7577

7678
importMapping.remove("List");
7779
importMapping.remove("Set");
@@ -110,6 +112,7 @@ public ScalaClientCodegen() {
110112
"Long",
111113
"Float",
112114
"Object",
115+
"Any",
113116
"List",
114117
"Map")
115118
);
@@ -255,4 +258,60 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
255258
return objs;
256259
}
257260

261+
@Override
262+
public String toVarName(String name) {
263+
// sanitize name
264+
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
265+
266+
if("_".equals(name)) {
267+
name = "_u";
268+
}
269+
270+
// if it's all uppper case, do nothing
271+
if (name.matches("^[A-Z_]*$")) {
272+
return name;
273+
}
274+
275+
// camelize (lower first character) the variable name
276+
// pet_id => petId
277+
name = camelize(name, true);
278+
279+
// for reserved word or word starting with number, append _
280+
if (isReservedWord(name) || name.matches("^\\d.*")) {
281+
name = escapeReservedWord(name);
282+
}
283+
284+
return name;
285+
}
286+
287+
@Override
288+
public String toParamName(String name) {
289+
// should be the same as variable name
290+
return toVarName(name);
291+
}
292+
293+
@Override
294+
public String toModelName(final String name) {
295+
final String sanitizedName = sanitizeName(modelNamePrefix + name + modelNameSuffix);
296+
297+
// camelize the model name
298+
// phone_number => PhoneNumber
299+
final String camelizedName = camelize(sanitizedName);
300+
301+
// model name cannot use reserved keyword, e.g. return
302+
if (isReservedWord(camelizedName)) {
303+
final String modelName = "Model" + camelizedName;
304+
LOGGER.warn(camelizedName + " (reserved word) cannot be used as model name. Renamed to " + modelName);
305+
return modelName;
306+
}
307+
308+
return camelizedName;
309+
}
310+
311+
@Override
312+
public String toModelFilename(String name) {
313+
// should be the same as the model name
314+
return toModelName(name);
315+
}
316+
258317
}

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ public void processOpts() {
195195
supportingFiles.add(new SupportingFile("Extensions.mustache", sourceFolder, "Extensions.swift"));
196196
supportingFiles.add(new SupportingFile("Models.mustache", sourceFolder, "Models.swift"));
197197
supportingFiles.add(new SupportingFile("APIs.mustache", sourceFolder, "APIs.swift"));
198+
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
199+
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
200+
198201
}
199202

200203
@Override

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public String getHelp() {
1919
public void processOpts() {
2020
super.processOpts();
2121
supportingFiles.add(new SupportingFile("api.d.mustache", apiPackage().replace('.', File.separatorChar), "api.d.ts"));
22+
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
23+
//supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
24+
25+
2226
}
2327

2428
public TypeScriptAngularClientCodegen() {

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptNodeClientCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public String getHelp() {
1818
public void processOpts() {
1919
super.processOpts();
2020
supportingFiles.add(new SupportingFile("api.mustache", null, "api.ts"));
21+
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
22+
//supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
2123
}
2224

2325
public TypeScriptNodeClientCodegen() {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
3+
#
4+
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
5+
6+
git_user_id=$1
7+
git_repo_id=$2
8+
release_note=$3
9+
10+
if [ "$git_user_id" = "" ]; then
11+
git_user_id="{{{gitUserId}}}"
12+
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
13+
fi
14+
15+
if [ "$git_repo_id" = "" ]; then
16+
git_repo_id="{{{gitRepoId}}}"
17+
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
18+
fi
19+
20+
if [ "$release_note" = "" ]; then
21+
release_note="{{{releaseNote}}}"
22+
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
23+
fi
24+
25+
# Initialize the local directory as a Git repository
26+
git init
27+
28+
# Adds the files in the local repository and stages them for commit.
29+
git add .
30+
31+
# Commits the tracked changes and prepares them to be pushed to a remote repository.
32+
git commit -m "$release_note"
33+
34+
# Sets the new remote
35+
git_remote=`git remote`
36+
if [ "$git_remote" = "" ]; then # git remote not defined
37+
38+
if [ "$GIT_TOKEN" = "" ]; then
39+
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment."
40+
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
41+
else
42+
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
43+
fi
44+
45+
fi
46+
47+
git pull origin master
48+
49+
# 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"
51+
git push origin master 2>&1 | grep -v 'To https'
52+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.class
2+
3+
# Mobile Tools for Java (J2ME)
4+
.mtj.tmp/
5+
6+
# Package Files #
7+
*.jar
8+
*.war
9+
*.ear
10+
11+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12+
hs_err_pid*
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
3+
#
4+
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
5+
6+
git_user_id=$1
7+
git_repo_id=$2
8+
release_note=$3
9+
10+
if [ "$git_user_id" = "" ]; then
11+
git_user_id="{{{gitUserId}}}"
12+
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
13+
fi
14+
15+
if [ "$git_repo_id" = "" ]; then
16+
git_repo_id="{{{gitRepoId}}}"
17+
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
18+
fi
19+
20+
if [ "$release_note" = "" ]; then
21+
release_note="{{{releaseNote}}}"
22+
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
23+
fi
24+
25+
# Initialize the local directory as a Git repository
26+
git init
27+
28+
# Adds the files in the local repository and stages them for commit.
29+
git add .
30+
31+
# Commits the tracked changes and prepares them to be pushed to a remote repository.
32+
git commit -m "$release_note"
33+
34+
# Sets the new remote
35+
git_remote=`git remote`
36+
if [ "$git_remote" = "" ]; then # git remote not defined
37+
38+
if [ "$GIT_TOKEN" = "" ]; then
39+
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment."
40+
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
41+
else
42+
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
43+
fi
44+
45+
fi
46+
47+
git pull origin master
48+
49+
# 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"
51+
git push origin master 2>&1 | grep -v 'To https'
52+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
11+
# Directory for instrumented libs generated by jscoverage/JSCover
12+
lib-cov
13+
14+
# Coverage directory used by tools like istanbul
15+
coverage
16+
17+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
18+
.grunt
19+
20+
# node-waf configuration
21+
.lock-wscript
22+
23+
# Compiled binary addons (http://nodejs.org/api/addons.html)
24+
build/Release
25+
26+
# Dependency directory
27+
node_modules
28+
29+
# Optional npm cache directory
30+
.npm
31+
32+
# Optional REPL history
33+
.node_repl_history

0 commit comments

Comments
 (0)