Skip to content

Commit

Permalink
Merge branch 'master' into pool-on-demand
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk authored Nov 6, 2018
2 parents 8833143 + 9409f83 commit 3d7d731
Show file tree
Hide file tree
Showing 396 changed files with 34,053 additions and 5,711 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ script:

after_success:
# push a snapshot version to maven repo
- if [ $SONATYPE_USERNAME ] && [ -z $TRAVIS_TAG ] && [ "$TRAVIS_BRANCH" = "master" ]; then
mvn clean deploy --settings .travis/settings.xml;
echo "Finished mvn clean deploy for $TRAVIS_BRANCH";
fi;
#- if [ $SONATYPE_USERNAME ] && [ -z $TRAVIS_TAG ] && [ "$TRAVIS_BRANCH" = "master" ]; then
# mvn clean deploy --settings .travis/settings.xml;
# echo "Finished mvn clean deploy for $TRAVIS_BRANCH";
# fi;

env:
- DOCKER_GENERATOR_IMAGE_NAME=swaggerapi/swagger-generator DOCKER_CODEGEN_CLI_IMAGE_NAME=swaggerapi/swagger-codegen-cli
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli generate \
-o /local/out/go
```

(On Windows replace `${PWD}` with `%CD%`)

The generated code will be located under `./out/go` in the current directory.

## Getting Started
Expand Down
49 changes: 49 additions & 0 deletions bin/dart-jaguar-petstore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/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"

# Generate client
ags="$@ generate -t modules/swagger-codegen/src/main/resources/dart-jaguar -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l dart-jaguar -o samples/client/petstore/dart-jaguar/swagger -DhideGenerationTimestamp=true"
java $JAVA_OPTS -jar $executable $ags

# Generate non-browserClient and put it to the flutter sample app
ags="$@ generate -t modules/swagger-codegen/src/main/resources/dart-jaguar -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l dart-jaguar -o samples/client/petstore/dart-jaguar/flutter_petstore/swagger -DhideGenerationTimestamp=true"
java $JAVA_OPTS -jar $executable $ags

# There is a proposal to allow importing different libraries depending on the environment:
# https://github.com/munificent/dep-interface-libraries
# When this is implemented there will only be one library.

# The current petstore test will then work for both: the browser library and the vm library.

cd samples/client/petstore/dart-jaguar/swagger
pub get
pub run build_runner build --delete-conflicting-outputs
cd ../flutter_petstore/swagger
pub get
pub run build_runner build --delete-conflicting-outputs
2 changes: 1 addition & 1 deletion bin/python-flask-petstore-python2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ 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 -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l python-flask -o samples/server/petstore/flaskConnexion-python2 -DsupportPython2=true"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/flaskConnexion -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l python-flask -o samples/server/petstore/flaskConnexion-python2 -c bin/supportPython2.json -D service"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/flaskConnexion -i modules/swagger-codegen/src/test/resources/2_0/petstore-flask.yaml -l python-flask -o samples/server/petstore/flaskConnexion-python2 -c bin/supportPython2.json -D service"

rm -rf samples/server/petstore/flaskConnexion-python2/*
java $JAVA_OPTS -jar $executable $ags
2 changes: 1 addition & 1 deletion bin/python-flask-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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/flaskConnexion -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l python-flask -o samples/server/petstore/flaskConnexion -Dservice"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/flaskConnexion -i modules/swagger-codegen/src/test/resources/2_0/petstore-flask.yaml -l python-flask -o samples/server/petstore/flaskConnexion -Dservice"

rm -rf samples/server/petstore/flaskConnexion/*
java $JAVA_OPTS -jar $executable $ags
12 changes: 12 additions & 0 deletions bin/windows/dart-client-petstore.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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 -DloggerPath=conf/log4j.properties
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l dart-jaguar -o samples\client\petstore\dart-jaguar\swagger -DhideGenerationTimestamp=true -DbrowserClient=false
java %JAVA_OPTS% -jar %executable% %ags%

set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l dart-jaguar -o samples\client\petstore\dart-jaguar\flutter_petstore\swagger -DhideGenerationTimestamp=true
java %JAVA_OPTS% -jar %executable% %ags%
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
</dependencies>

<properties>
<swagger-annotations-version>1.5.20</swagger-annotations-version>
<swagger-annotations-version>1.5.21</swagger-annotations-version>
<jersey-version>2.25.1</jersey-version>
<jackson-version>2.9.5</jackson-version>
<jodatime-version>2.7</jodatime-version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CodegenOperation {
isResponseBinary = false, isResponseFile = false, hasReference = false,
isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
isRestful, isDeprecated;
public String path, operationId, returnType, httpMethod, returnBaseType,
public String path, testPath, operationId, returnType, httpMethod, returnBaseType,
returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse, discriminator;
public List<Map<String, String>> consumes, produces, prioritizedContentTypes;
public CodegenParameter bodyParam;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class CodegenParameter {
collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName;

public String example; // example value (x-example)
public String testExample;
public String jsonSchema;
public boolean isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid;
public boolean isListContainer, isMapContainer;
Expand Down Expand Up @@ -116,6 +117,7 @@ public CodegenParameter copy() {
output.jsonSchema = this.jsonSchema;
output.defaultValue = this.defaultValue;
output.example = this.example;
output.testExample = this.testExample;
output.isEnum = this.isEnum;
if (this._enum != null) {
output._enum = new ArrayList<String>(this._enum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,7 @@ public CodegenOperation fromOperation(String path,
op.returnBaseType = cm.baseType;
}
}
op.examples = new ExampleGenerator(definitions).generate(methodResponse.getExamples(), operation.getProduces(), responseProperty);
op.examples = getExamples(definitions, methodResponse.getExamples(), operation.getProduces(), responseProperty);
op.defaultResponse = toDefaultValue(responseProperty);
op.returnType = cm.datatype;
op.hasReference = definitions != null && definitions.containsKey(op.returnBaseType);
Expand Down Expand Up @@ -2272,7 +2272,7 @@ public CodegenOperation fromOperation(String path,
bodyParam = p;
bodyParams.add(p.copy());
if(definitions != null) {
op.requestBodyExamples = new ExampleGenerator(definitions).generate(null, operation.getConsumes(), bodyParam.dataType);
op.requestBodyExamples = getExamples(definitions, null, consumes, bodyParam.dataType);
}
} else if (param instanceof FormParameter) {
formParams.add(p.copy());
Expand Down Expand Up @@ -2332,6 +2332,8 @@ public int compare(CodegenParameter one, CodegenParameter another) {
op.isRestfulDestroy = op.isRestfulDestroy();
op.isRestful = op.isRestful();

configureDataForTestTemplate(op);

return op;
}

Expand Down Expand Up @@ -3816,6 +3818,15 @@ public boolean convertPropertyToBoolean(String propertyKey) {
return booleanValue;
}

protected List<Map<String, String>> getExamples(Map<String, Model> definitions, Map<String, Object> examples, List<String> mediaTypes, Object object) {
if (object instanceof Property) {
Property responseProperty = (Property) object;
return new ExampleGenerator(definitions).generate(examples, mediaTypes, responseProperty);
}
// this must be a model name instead
return new ExampleGenerator(definitions).generate(examples, mediaTypes, object.toString());
}

public void writePropertyBack(String propertyKey, boolean value) {
additionalProperties.put(propertyKey, value);
}
Expand All @@ -3837,4 +3848,54 @@ protected void addSwitch(String key, String description, Boolean defaultValue) {
option.defaultValue(defaultValue.toString());
cliOptions.add(option);
}

protected void configureDataForTestTemplate(CodegenOperation codegenOperation) {
final String httpMethod = codegenOperation.httpMethod;
String path = codegenOperation.path;
if ("GET".equalsIgnoreCase(httpMethod)) {
codegenOperation.vendorExtensions.put("x-is-get-method", Boolean.TRUE);
}
if ("POST".equalsIgnoreCase(httpMethod)) {
codegenOperation.vendorExtensions.put("x-is-post-method", Boolean.TRUE);
}
if ("PUT".equalsIgnoreCase(httpMethod)) {
codegenOperation.vendorExtensions.put("x-is-put-method", Boolean.TRUE);
}
if ("DELETE".equalsIgnoreCase(httpMethod)) {
codegenOperation.vendorExtensions.put("x-is-delete-method", Boolean.TRUE);
}
if ("HEAD".equalsIgnoreCase(httpMethod)) {
codegenOperation.vendorExtensions.put("x-is-head-method", Boolean.TRUE);
}
if ("TRACE".equalsIgnoreCase(httpMethod)) {
codegenOperation.vendorExtensions.put("x-is-trace-method", Boolean.TRUE);
}
if ("PATCH".equalsIgnoreCase(httpMethod)) {
codegenOperation.vendorExtensions.put("x-is-head-method", Boolean.TRUE);
}
if ("OPTIONS".equalsIgnoreCase(httpMethod)) {
codegenOperation.vendorExtensions.put("x-is-options-method", Boolean.TRUE);
}
if (path.contains("{")) {
while(path.contains("{")) {
final String pathParam = path.substring(path.indexOf("{"), path.indexOf("}") + 1);
final String paramName = pathParam.replace("{", StringUtils.EMPTY).replace("}", StringUtils.EMPTY);

CodegenParameter codegenParameter = null;

for (CodegenParameter parameter : codegenOperation.pathParams) {
if (parameter.baseName.equalsIgnoreCase(paramName)) {
codegenParameter = parameter;
break;
}
}

if (codegenParameter == null || codegenParameter.testExample == null) {
return;
}
path = path.replace(pathParam, codegenParameter.testExample);
}
}
codegenOperation.testPath = path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ public void setParameterExampleValue(CodegenParameter p) {
if (example == null) {
example = p.paramName + "_example";
}
p.testExample = example;
example = "\"" + escapeText(example) + "\"";
} else if ("Integer".equals(type) || "Short".equals(type)) {
if (example == null) {
Expand All @@ -788,15 +789,18 @@ public void setParameterExampleValue(CodegenParameter p) {
if (example == null) {
example = "56";
}
p.testExample = example;
example = example + "L";
} else if ("Float".equals(type)) {
if (example == null) {
example = "3.4";
}
p.testExample = example;
example = example + "F";
} else if ("Double".equals(type)) {
example = "3.4";
example = example + "D";
p.testExample = example;
} else if ("Boolean".equals(type)) {
if (example == null) {
example = "true";
Expand All @@ -813,6 +817,10 @@ public void setParameterExampleValue(CodegenParameter p) {
example = "new " + type + "()";
}

if (p.testExample == null) {
p.testExample = example;
}

if (example == null) {
example = "null";
} else if (Boolean.TRUE.equals(p.isListContainer)) {
Expand Down
Loading

0 comments on commit 3d7d731

Please sign in to comment.