Skip to content

Commit 174b14b

Browse files
authored
Merge pull request #7426 from swagger-api/2.4.0
Merge 2.4.0 into master
2 parents 6b7b877 + 6db63c7 commit 174b14b

File tree

1,137 files changed

+20602
-11241
lines changed

Some content is hidden

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

1,137 files changed

+20602
-11241
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ On a mac, it's even easier with `brew`:
107107
brew install swagger-codegen
108108
```
109109

110-
To build from source, you need the following installed and available in your $PATH:
110+
To build from source, you need the following installed and available in your `$PATH:`
111111

112112
* [Java 7 or 8](http://java.oracle.com)
113113

@@ -116,7 +116,7 @@ To build from source, you need the following installed and available in your $PA
116116
#### OS X Users
117117
Don't forget to install Java 7 or 8. You probably have 1.6.
118118

119-
Export JAVA_HOME in order to use the supported Java version:
119+
Export `JAVA_HOME` in order to use the supported Java version:
120120
```sh
121121
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
122122
export PATH=${JAVA_HOME}/bin:$PATH
@@ -264,7 +264,7 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
264264
-o samples/client/petstore/java
265265
```
266266

267-
with a number of options. You can get the options with the `help generate` command (below only shows partal results):
267+
with a number of options. You can get the options with the `help generate` command (below only shows partial results):
268268

269269
```
270270
NAME
@@ -340,7 +340,7 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar meta \
340340
-o output/myLibrary -n myClientCodegen -p com.my.company.codegen
341341
```
342342

343-
This will write, in the folder `output/myLibrary`, all the files you need to get started, including a README.md. Once modified and compiled, you can load your library with the codegen and generate clients with your own, custom-rolled logic.
343+
This will write, in the folder `output/myLibrary`, all the files you need to get started, including a `README.md. Once modified and compiled, you can load your library with the codegen and generate clients with your own, custom-rolled logic.
344344

345345
You would then compile your library in the `output/myLibrary` folder with `mvn package` and execute the codegen like such:
346346

@@ -541,7 +541,7 @@ Your config file for Java can look like
541541
For all the unspecified options default values will be used.
542542

543543
Another way to override default options is to extend the config class for the specific language.
544-
To change, for example, the prefix for the Objective-C generated files, simply subclass the ObjcClientCodegen.java:
544+
To change, for example, the prefix for the Objective-C generated files, simply subclass the `ObjcClientCodegen.java`:
545545

546546
```java
547547
package com.mycompany.swagger.codegen;
@@ -790,7 +790,7 @@ Here are some companies/projects using Swagger Codegen in production. To add you
790790
- [Hewlett Packard Enterprise](https://hpe.com)
791791
- [High Technologies Center](http://htc-cs.com)
792792
- [Hootsuite](https://hootsuite.com/)
793-
- [Huawei Cloud](https://www.huaweicloud.com) - [Cloud Stream Service](http://www.huaweicloud.com/en-us/product/cs.html)
793+
- [Huawei Cloud](http://www.huaweicloud.com/en-us/product/cs.html)
794794
- [IBM](https://www.ibm.com)
795795
- [IMS Health](http://www.imshealth.com/en/solution-areas/technology-and-applications)
796796
- [Individual Standard IVS](http://www.individual-standard.com)

bin/java-play-framework-petstore-server-all.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
./bin/java-play-framework-petstore-server-no-interface.sh
88
./bin/java-play-framework-petstore-server-no-swagger-ui.sh
99
./bin/java-play-framework-petstore-server-no-wrap-calls.sh
10-
./bin/java-play-framework-petstore-server-fake-endpoints.sh
10+
./bin/java-play-framework-petstore-server-fake-endpoints.sh
11+
./bin/java-play-framework-petstore-server-api-package-override.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
5+
while [ -h "$SCRIPT" ] ; do
6+
ls=`ls -ld "$SCRIPT"`
7+
link=`expr "$ls" : '.*-> \(.*\)$'`
8+
if expr "$link" : '/.*' > /dev/null; then
9+
SCRIPT="$link"
10+
else
11+
SCRIPT=`dirname "$SCRIPT"`/"$link"
12+
fi
13+
done
14+
15+
if [ ! -d "${APP_DIR}" ]; then
16+
APP_DIR=`dirname "$SCRIPT"`/..
17+
APP_DIR=`cd "${APP_DIR}"; pwd`
18+
fi
19+
20+
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
21+
22+
if [ ! -f "$executable" ]
23+
then
24+
mvn clean package
25+
fi
26+
27+
# if you've executed sbt assembly previously it will use that instead.
28+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
29+
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaPlayFramework -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l java-play-framework -o samples/server/petstore/java-play-framework-api-package-override -DhideGenerationTimestamp=true,apiPackage=com.puppies.store.apis"
30+
31+
java $JAVA_OPTS -jar $executable $ags

bin/scala-gatling-petstore.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
5+
while [ -h "$SCRIPT" ] ; do
6+
ls=`ls -ld "$SCRIPT"`
7+
link=`expr "$ls" : '.*-> \(.*\)$'`
8+
if expr "$link" : '/.*' > /dev/null; then
9+
SCRIPT="$link"
10+
else
11+
SCRIPT=`dirname "$SCRIPT"`/"$link"
12+
fi
13+
done
14+
15+
if [ ! -d "${APP_DIR}" ]; then
16+
APP_DIR=`dirname "$SCRIPT"`/..
17+
APP_DIR=`cd "${APP_DIR}"; pwd`
18+
fi
19+
20+
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
21+
22+
if [ ! -f "$executable" ]
23+
then
24+
mvn clean package
25+
fi
26+
27+
# if you've executed sbt assembly previously it will use that instead.
28+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
29+
ags="$@ generate -t modules/swagger-codegen/src/main/resources/scala-gatling -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l scala-gatling -o samples/client/petstore/scala-gatling"
30+
31+
java $JAVA_OPTS -jar $executable $ags

bin/windows/scala-gatling-petstore.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
2+
3+
If Not Exist %executable% (
4+
mvn clean package
5+
)
6+
7+
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
8+
set ags=generate -t modules\swagger-codegen\src\main\resources\scala-gatling -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l scala-gatling -o samples\client\petstore\scala-gatling
9+
10+
java %JAVA_OPTS% -jar %executable% %ags%

circle.yml

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ test:
4141
## test with jdk7
4242
- sudo update-java-alternatives -s java-1.7.0-openjdk-amd64
4343
- java -version
44+
- cp pom.xml.circleci.java7 pom.xml # use jdk7 pom
4445
- mvn clean install
4546
- mvn -q verify -Psamples
4647
# skip the rest if previous mvn task fails

modules/swagger-codegen-cli/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>io.swagger</groupId>
55
<artifactId>swagger-codegen-project</artifactId>
6-
<version>2.3.1</version>
6+
<version>2.4.0-SNAPSHOT</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>

modules/swagger-codegen-maven-plugin/pom.xml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3-
43
<modelVersion>4.0.0</modelVersion>
5-
64
<parent>
75
<groupId>io.swagger</groupId>
86
<artifactId>swagger-codegen-project</artifactId>
9-
<version>2.3.1</version>
7+
<version>2.4.0-SNAPSHOT</version>
108
<relativePath>../..</relativePath>
119
</parent>
1210
<artifactId>swagger-codegen-maven-plugin</artifactId>

modules/swagger-codegen/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>io.swagger</groupId>
55
<artifactId>swagger-codegen-project</artifactId>
6-
<version>2.3.1</version>
6+
<version>2.4.0-SNAPSHOT</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>

modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java

+3
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,7 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
222222

223223
public static final String REMOVE_OPERATION_ID_PREFIX = "removeOperationIdPrefix";
224224
public static final String REMOVE_OPERATION_ID_PREFIX_DESC = "Remove prefix of operationId, e.g. config_getId => getId";
225+
226+
public static final String STRIP_PACKAGE_NAME = "stripPackageName";
227+
public static final String STRIP_PACKAGE_NAME_DESC = "Whether to strip leading dot-separated packages from generated model classes";
225228
}

modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public boolean getHasExamples() {
111111
* @return true if act as Restful index method, false otherwise
112112
*/
113113
public boolean isRestfulIndex() {
114-
return "GET".equals(httpMethod) && "".equals(pathWithoutBaseName());
114+
return "GET".equalsIgnoreCase(httpMethod) && "".equals(pathWithoutBaseName());
115115
}
116116

117117
/**

modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenSecurity.java

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class CodegenSecurity {
77
public String name;
88
public String type;
99
public Boolean hasMore, isBasic, isOAuth, isApiKey;
10+
public Map<String, Object> vendorExtensions;
1011
// ApiKey specific
1112
public String keyParamName;
1213
public Boolean isKeyInQuery, isKeyInHeader;
@@ -39,6 +40,8 @@ public boolean equals(Object o) {
3940
return false;
4041
if (isApiKey != null ? !isApiKey.equals(that.isApiKey) : that.isApiKey != null)
4142
return false;
43+
if (vendorExtensions != null ? !vendorExtensions.equals(that.vendorExtensions) : that.vendorExtensions != null)
44+
return false;
4245
if (keyParamName != null ? !keyParamName.equals(that.keyParamName) : that.keyParamName != null)
4346
return false;
4447
if (isKeyInQuery != null ? !isKeyInQuery.equals(that.isKeyInQuery) : that.isKeyInQuery != null)
@@ -71,6 +74,7 @@ public int hashCode() {
7174
result = 31 * result + (isBasic != null ? isBasic.hashCode() : 0);
7275
result = 31 * result + (isOAuth != null ? isOAuth.hashCode() : 0);
7376
result = 31 * result + (isApiKey != null ? isApiKey.hashCode() : 0);
77+
result = 31 * result + (vendorExtensions != null ? vendorExtensions.hashCode() : 0);
7478
result = 31 * result + (keyParamName != null ? keyParamName.hashCode() : 0);
7579
result = 31 * result + (isKeyInQuery != null ? isKeyInQuery.hashCode() : 0);
7680
result = 31 * result + (isKeyInHeader != null ? isKeyInHeader.hashCode() : 0);

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void processOpts() {
152152
}
153153

154154
if (additionalProperties.containsKey(CodegenConstants.REMOVE_OPERATION_ID_PREFIX)) {
155-
this.setSortParamsByRequiredFlag(Boolean.valueOf(additionalProperties
155+
this.setRemoveOperationIdPrefix(Boolean.valueOf(additionalProperties
156156
.get(CodegenConstants.REMOVE_OPERATION_ID_PREFIX).toString()));
157157
}
158158
}
@@ -2756,6 +2756,7 @@ public List<CodegenSecurity> fromSecurity(Map<String, SecuritySchemeDefinition>
27562756
sec.name = entry.getKey();
27572757
sec.type = schemeDefinition.getType();
27582758
sec.isCode = sec.isPassword = sec.isApplication = sec.isImplicit = false;
2759+
sec.vendorExtensions = schemeDefinition.getVendorExtensions();
27592760

27602761
if (schemeDefinition instanceof ApiKeyAuthDefinition) {
27612762
final ApiKeyAuthDefinition apiKeyDefinition = (ApiKeyAuthDefinition) schemeDefinition;

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,15 @@ public String toParamName(String name) {
152152
public String toModelName(String name) {
153153
// camelize the model name
154154
// phone_number => PhoneNumber
155-
return camelize(toModelFilename(name));
155+
return camelize(toModel(name));
156156
}
157157

158158
@Override
159159
public String toModelFilename(String name) {
160+
return toModel("model_" + name);
161+
}
162+
163+
public String toModel(String name) {
160164
if (!StringUtils.isEmpty(modelNamePrefix)) {
161165
name = modelNamePrefix + "_" + name;
162166
}
@@ -188,7 +192,7 @@ public String toApiFilename(String name) {
188192
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
189193

190194
// e.g. PetApi.go => pet_api.go
191-
return underscore(name) + "_api";
195+
return "api_" + underscore(name);
192196
}
193197

194198
/**

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

+16-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
2929
protected String modelPropertyNaming = "camelCase";
3030
protected String invokerPackage = "io.swagger.client";
3131
protected String sourceFolder = "src/main/scala";
32+
protected boolean stripPackageName = true;
3233

3334
public AbstractScalaCodegen() {
3435
super();
@@ -102,6 +103,13 @@ public void processOpts() {
102103
if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) {
103104
this.setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER));
104105
}
106+
if (additionalProperties.containsKey(CodegenConstants.STRIP_PACKAGE_NAME) &&
107+
"false".equalsIgnoreCase(additionalProperties.get(CodegenConstants.STRIP_PACKAGE_NAME).toString())) {
108+
this.stripPackageName = false;
109+
additionalProperties.put(CodegenConstants.STRIP_PACKAGE_NAME, false);
110+
LOGGER.warn("stripPackageName=false. Compilation errors may occur if API type names clash with types " +
111+
"in the default imports");
112+
}
105113
}
106114

107115
public void setSourceFolder(String sourceFolder) {
@@ -265,10 +273,16 @@ protected String formatIdentifier(String name, boolean capitalized) {
265273
}
266274

267275
protected String stripPackageName(String input) {
268-
if (StringUtils.isEmpty(input) || input.lastIndexOf(".") < 0)
276+
if (!stripPackageName || StringUtils.isEmpty(input) || input.lastIndexOf(".") < 0)
269277
return input;
270278

271279
int lastIndexOfDot = input.lastIndexOf(".");
272280
return input.substring(lastIndexOfDot + 1);
273281
}
274-
}
282+
283+
@Override
284+
public String escapeQuotationMark(String input) {
285+
// remove " to avoid code injection
286+
return input.replace("\"", "");
287+
}
288+
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public void processOpts() {
9292
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
9393
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
9494
supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.go"));
95-
supportingFiles.add(new SupportingFile("api_client.mustache", "", "api_client.go"));
96-
supportingFiles.add(new SupportingFile("api_response.mustache", "", "api_response.go"));
95+
supportingFiles.add(new SupportingFile("client.mustache", "", "client.go"));
96+
supportingFiles.add(new SupportingFile("response.mustache", "", "response.go"));
9797
supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
9898
}
9999

0 commit comments

Comments
 (0)