Skip to content

Commit

Permalink
Merge pull request #7426 from swagger-api/2.4.0
Browse files Browse the repository at this point in the history
Merge 2.4.0 into master
  • Loading branch information
wing328 committed Jan 21, 2018
2 parents 6b7b877 + 6db63c7 commit 174b14b
Show file tree
Hide file tree
Showing 1,137 changed files with 20,602 additions and 11,241 deletions.
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -107,7 +107,7 @@ On a mac, it's even easier with `brew`:
brew install swagger-codegen
```

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

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

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

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

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

```
NAME
Expand Down Expand Up @@ -340,7 +340,7 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar meta \
-o output/myLibrary -n myClientCodegen -p com.my.company.codegen
```

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.
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.

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

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

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

```java
package com.mycompany.swagger.codegen;
Expand Down Expand Up @@ -790,7 +790,7 @@ Here are some companies/projects using Swagger Codegen in production. To add you
- [Hewlett Packard Enterprise](https://hpe.com)
- [High Technologies Center](http://htc-cs.com)
- [Hootsuite](https://hootsuite.com/)
- [Huawei Cloud](https://www.huaweicloud.com) - [Cloud Stream Service](http://www.huaweicloud.com/en-us/product/cs.html)
- [Huawei Cloud](http://www.huaweicloud.com/en-us/product/cs.html)
- [IBM](https://www.ibm.com)
- [IMS Health](http://www.imshealth.com/en/solution-areas/technology-and-applications)
- [Individual Standard IVS](http://www.individual-standard.com)
Expand Down
3 changes: 2 additions & 1 deletion bin/java-play-framework-petstore-server-all.sh
Expand Up @@ -7,4 +7,5 @@
./bin/java-play-framework-petstore-server-no-interface.sh
./bin/java-play-framework-petstore-server-no-swagger-ui.sh
./bin/java-play-framework-petstore-server-no-wrap-calls.sh
./bin/java-play-framework-petstore-server-fake-endpoints.sh
./bin/java-play-framework-petstore-server-fake-endpoints.sh
./bin/java-play-framework-petstore-server-api-package-override.sh
31 changes: 31 additions & 0 deletions bin/java-play-framework-petstore-server-api-package-override.sh
@@ -0,0 +1,31 @@
#!/bin/sh

SCRIPT="$0"

while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done

if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi

executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"

if [ ! -f "$executable" ]
then
mvn clean package
fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
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"

java $JAVA_OPTS -jar $executable $ags
31 changes: 31 additions & 0 deletions bin/scala-gatling-petstore.sh
@@ -0,0 +1,31 @@
#!/bin/sh

SCRIPT="$0"

while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done

if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi

executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"

if [ ! -f "$executable" ]
then
mvn clean package
fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
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"

java $JAVA_OPTS -jar $executable $ags
10 changes: 10 additions & 0 deletions bin/windows/scala-gatling-petstore.sh
@@ -0,0 +1,10 @@
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar

If Not Exist %executable% (
mvn clean package
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
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

java %JAVA_OPTS% -jar %executable% %ags%
1 change: 1 addition & 0 deletions circle.yml
Expand Up @@ -41,6 +41,7 @@ test:
## test with jdk7
- sudo update-java-alternatives -s java-1.7.0-openjdk-amd64
- java -version
- cp pom.xml.circleci.java7 pom.xml # use jdk7 pom
- mvn clean install
- mvn -q verify -Psamples
# skip the rest if previous mvn task fails
Expand Down
2 changes: 1 addition & 1 deletion modules/swagger-codegen-cli/pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-project</artifactId>
<version>2.3.1</version>
<version>2.4.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
4 changes: 1 addition & 3 deletions modules/swagger-codegen-maven-plugin/pom.xml
@@ -1,12 +1,10 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-project</artifactId>
<version>2.3.1</version>
<version>2.4.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<artifactId>swagger-codegen-maven-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion modules/swagger-codegen/pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-project</artifactId>
<version>2.3.1</version>
<version>2.4.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Expand Up @@ -222,4 +222,7 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,

public static final String REMOVE_OPERATION_ID_PREFIX = "removeOperationIdPrefix";
public static final String REMOVE_OPERATION_ID_PREFIX_DESC = "Remove prefix of operationId, e.g. config_getId => getId";

public static final String STRIP_PACKAGE_NAME = "stripPackageName";
public static final String STRIP_PACKAGE_NAME_DESC = "Whether to strip leading dot-separated packages from generated model classes";
}
Expand Up @@ -111,7 +111,7 @@ public boolean getHasExamples() {
* @return true if act as Restful index method, false otherwise
*/
public boolean isRestfulIndex() {
return "GET".equals(httpMethod) && "".equals(pathWithoutBaseName());
return "GET".equalsIgnoreCase(httpMethod) && "".equals(pathWithoutBaseName());
}

/**
Expand Down
Expand Up @@ -7,6 +7,7 @@ public class CodegenSecurity {
public String name;
public String type;
public Boolean hasMore, isBasic, isOAuth, isApiKey;
public Map<String, Object> vendorExtensions;
// ApiKey specific
public String keyParamName;
public Boolean isKeyInQuery, isKeyInHeader;
Expand Down Expand Up @@ -39,6 +40,8 @@ public boolean equals(Object o) {
return false;
if (isApiKey != null ? !isApiKey.equals(that.isApiKey) : that.isApiKey != null)
return false;
if (vendorExtensions != null ? !vendorExtensions.equals(that.vendorExtensions) : that.vendorExtensions != null)
return false;
if (keyParamName != null ? !keyParamName.equals(that.keyParamName) : that.keyParamName != null)
return false;
if (isKeyInQuery != null ? !isKeyInQuery.equals(that.isKeyInQuery) : that.isKeyInQuery != null)
Expand Down Expand Up @@ -71,6 +74,7 @@ public int hashCode() {
result = 31 * result + (isBasic != null ? isBasic.hashCode() : 0);
result = 31 * result + (isOAuth != null ? isOAuth.hashCode() : 0);
result = 31 * result + (isApiKey != null ? isApiKey.hashCode() : 0);
result = 31 * result + (vendorExtensions != null ? vendorExtensions.hashCode() : 0);
result = 31 * result + (keyParamName != null ? keyParamName.hashCode() : 0);
result = 31 * result + (isKeyInQuery != null ? isKeyInQuery.hashCode() : 0);
result = 31 * result + (isKeyInHeader != null ? isKeyInHeader.hashCode() : 0);
Expand Down
Expand Up @@ -152,7 +152,7 @@ public void processOpts() {
}

if (additionalProperties.containsKey(CodegenConstants.REMOVE_OPERATION_ID_PREFIX)) {
this.setSortParamsByRequiredFlag(Boolean.valueOf(additionalProperties
this.setRemoveOperationIdPrefix(Boolean.valueOf(additionalProperties
.get(CodegenConstants.REMOVE_OPERATION_ID_PREFIX).toString()));
}
}
Expand Down Expand Up @@ -2756,6 +2756,7 @@ public List<CodegenSecurity> fromSecurity(Map<String, SecuritySchemeDefinition>
sec.name = entry.getKey();
sec.type = schemeDefinition.getType();
sec.isCode = sec.isPassword = sec.isApplication = sec.isImplicit = false;
sec.vendorExtensions = schemeDefinition.getVendorExtensions();

if (schemeDefinition instanceof ApiKeyAuthDefinition) {
final ApiKeyAuthDefinition apiKeyDefinition = (ApiKeyAuthDefinition) schemeDefinition;
Expand Down
Expand Up @@ -152,11 +152,15 @@ public String toParamName(String name) {
public String toModelName(String name) {
// camelize the model name
// phone_number => PhoneNumber
return camelize(toModelFilename(name));
return camelize(toModel(name));
}

@Override
public String toModelFilename(String name) {
return toModel("model_" + name);
}

public String toModel(String name) {
if (!StringUtils.isEmpty(modelNamePrefix)) {
name = modelNamePrefix + "_" + name;
}
Expand Down Expand Up @@ -188,7 +192,7 @@ public String toApiFilename(String name) {
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.

// e.g. PetApi.go => pet_api.go
return underscore(name) + "_api";
return "api_" + underscore(name);
}

/**
Expand Down
Expand Up @@ -29,6 +29,7 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
protected String modelPropertyNaming = "camelCase";
protected String invokerPackage = "io.swagger.client";
protected String sourceFolder = "src/main/scala";
protected boolean stripPackageName = true;

public AbstractScalaCodegen() {
super();
Expand Down Expand Up @@ -102,6 +103,13 @@ public void processOpts() {
if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) {
this.setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER));
}
if (additionalProperties.containsKey(CodegenConstants.STRIP_PACKAGE_NAME) &&
"false".equalsIgnoreCase(additionalProperties.get(CodegenConstants.STRIP_PACKAGE_NAME).toString())) {
this.stripPackageName = false;
additionalProperties.put(CodegenConstants.STRIP_PACKAGE_NAME, false);
LOGGER.warn("stripPackageName=false. Compilation errors may occur if API type names clash with types " +
"in the default imports");
}
}

public void setSourceFolder(String sourceFolder) {
Expand Down Expand Up @@ -265,10 +273,16 @@ protected String formatIdentifier(String name, boolean capitalized) {
}

protected String stripPackageName(String input) {
if (StringUtils.isEmpty(input) || input.lastIndexOf(".") < 0)
if (!stripPackageName || StringUtils.isEmpty(input) || input.lastIndexOf(".") < 0)
return input;

int lastIndexOfDot = input.lastIndexOf(".");
return input.substring(lastIndexOfDot + 1);
}
}

@Override
public String escapeQuotationMark(String input) {
// remove " to avoid code injection
return input.replace("\"", "");
}
}
Expand Up @@ -92,8 +92,8 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.go"));
supportingFiles.add(new SupportingFile("api_client.mustache", "", "api_client.go"));
supportingFiles.add(new SupportingFile("api_response.mustache", "", "api_response.go"));
supportingFiles.add(new SupportingFile("client.mustache", "", "client.go"));
supportingFiles.add(new SupportingFile("response.mustache", "", "response.go"));
supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
}

Expand Down

0 comments on commit 174b14b

Please sign in to comment.