Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/flaskConnexion-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"
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"

rm -rf samples/server/petstore/flaskConnexion-python2/*
java $JAVA_OPTS -Dservice -jar $executable $ags
java $JAVA_OPTS -jar $executable $ags
4 changes: 2 additions & 2 deletions bin/flaskConnexion.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 "
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"

rm -rf samples/server/petstore/flaskConnexion/*
java $JAVA_OPTS -Dservice -jar $executable $ags
java $JAVA_OPTS -jar $executable $ags
4 changes: 2 additions & 2 deletions bin/go-petstore-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ 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 go-server -o samples/server/petstore/go-api-server -DpackageName=petstoreserver --additional-properties hideGenerationTimestamp=true "
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l go-server -o samples/server/petstore/go-api-server -DpackageName=petstoreserver --additional-properties hideGenerationTimestamp=true -Dservice"

java $JAVA_OPTS -Dservice -jar $executable $ags
java $JAVA_OPTS -jar $executable $ags
4 changes: 2 additions & 2 deletions bin/javascript-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ 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/Javascript -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l javascript -o samples/client/petstore/javascript"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/Javascript -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l javascript -o samples/client/petstore/javascript -DappName=PetstoreClient"

java -DappName=PetstoreClient $JAVA_OPTS -jar $executable $ags
java $JAVA_OPTS -jar $executable $ags
11 changes: 7 additions & 4 deletions bin/javascript-promise-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ 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/Javascript \
-i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l javascript \
ags="$@ generate \
-t modules/swagger-codegen/src/main/resources/Javascript \
-i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml \
-l javascript \
-o samples/client/petstore/javascript-promise \
--additional-properties usePromises=true"
--additional-properties usePromises=true \
-DappName=PetstoreClient"

java -DappName=PetstoreClient $JAVA_OPTS -jar $executable $ags
java $JAVA_OPTS -jar $executable $ags
4 changes: 2 additions & 2 deletions bin/nodejs-petstore-google-cloud-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ 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 nodejs-server --additional-properties=googleCloudFunctions=true -o samples/server/petstore/nodejs-google-cloud-functions"
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l nodejs-server --additional-properties=googleCloudFunctions=true -o samples/server/petstore/nodejs-google-cloud-functions -Dservice"

java $JAVA_OPTS -Dservice -jar $executable $ags
java $JAVA_OPTS -jar $executable $ags
4 changes: 2 additions & 2 deletions bin/nodejs-petstore-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ 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 nodejs-server -o samples/server/petstore/nodejs"
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l nodejs-server -o samples/server/petstore/nodejs -Dservice"

java $JAVA_OPTS -Dservice -jar $executable $ags
java $JAVA_OPTS -jar $executable $ags
4 changes: 2 additions & 2 deletions bin/objc-petstore-coredata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ 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/objc -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l objc -DapiDocs=false,modelDocs=false -o samples/client/petstore/objc/core-data --additional-properties coreData=true"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/objc -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l objc -D apiDocs=false -D modelDocs=false -o samples/client/petstore/objc/core-data --additional-properties coreData=true -D appName=PetstoreClient"

java -DappName=PetstoreClient $JAVA_OPTS -jar $executable $ags
java $JAVA_OPTS -jar $executable $ags
4 changes: 2 additions & 2 deletions bin/objc-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ 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/objc -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l objc -o samples/client/petstore/objc/default"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/objc -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l objc -o samples/client/petstore/objc/default -D appName=PetstoreClient"

java -DappName=PetstoreClient $JAVA_OPTS -jar $executable $ags
java $JAVA_OPTS -jar $executable $ags
4 changes: 2 additions & 2 deletions bin/security/javascript-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ 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/Javascript -i modules/swagger-codegen/src/test/resources/2_0/petstore-security-test.yaml -l javascript -o samples/client/petstore-security-test/javascript"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/Javascript -i modules/swagger-codegen/src/test/resources/2_0/petstore-security-test.yaml -l javascript -o samples/client/petstore-security-test/javascript -DappName=PetstoreClient"

java -DappName=PetstoreClient $JAVA_OPTS -jar $executable $ags
java $JAVA_OPTS -jar $executable $ags
4 changes: 2 additions & 2 deletions bin/windows/javascript-petstore.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ If Not Exist %executable% (
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -l javascript -o samples\client\petstore\javascript
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -l javascript -o samples\client\petstore\javascript -DappName=PetstoreClient

java -DappName=PetstoreClient %JAVA_OPTS% -jar %executable% %ags%
java %JAVA_OPTS% -jar %executable% %ags%
4 changes: 2 additions & 2 deletions bin/windows/javascript-promise-petstore.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ If Not Exist %executable% (
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -l javascript -o samples\client\petstore\javascript-promise --additional-properties usePromises=true
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -l javascript -o samples\client\petstore\javascript-promise --additional-properties usePromises=true -DappName=PetstoreClient

java -DappName=PetstoreClient %JAVA_OPTS% -jar %executable% %ags%
java %JAVA_OPTS% -jar %executable% %ags%
4 changes: 2 additions & 2 deletions bin/windows/objc-petstore.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ If Not Exist %executable% (
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l objc -o samples\client\petstore\objc\default
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l objc -o samples\client\petstore\objc\default -DappName=PetstoreClient

java %JAVA_OPTS% -DappName=PetstoreClient -jar %executable% %ags%
java %JAVA_OPTS% -jar %executable% %ags%
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import static io.swagger.codegen.config.CodegenConfiguratorUtils.*;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;

import java.util.ArrayList;
import java.util.List;

/**
* User: lanwen
* Date: 24.03.15
Expand Down Expand Up @@ -48,8 +51,8 @@ public class Generate implements Runnable {
private String auth;

@Option(name = {"-D"}, title = "system properties", description = "sets specified system properties in " +
"the format of name=value,name=value")
private String systemProperties;
"the format of name=value,name=value (or multiple options, each with name=value)")
private List<String> systemProperties = new ArrayList<>();

@Option(name = {"-c", "--config"}, title = "configuration file", description = "Path to json configuration file. " +
"File content should be in a json format {\"optionKey\":\"optionValue\", \"optionKey1\":\"optionValue1\"...} " +
Expand Down Expand Up @@ -229,7 +232,7 @@ public void run() {
configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix);
}

applySystemPropertiesKvp(systemProperties, configurator);
applySystemPropertiesKvpList(systemProperties, configurator);
applyInstantiationTypesKvp(instantiationTypes, configurator);
applyImportMappingsKvp(importMappings, configurator);
applyTypeMappingsKvp(typeMappings, configurator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,57 @@ public void testSystemProperties() throws Exception {
times = 1;
}};

setupAndRunGenericTest("-Dhello=world,foo=bar");

new FullVerifications() {{
configurator.addSystemProperty("hello", "world");
times = 1;
configurator.addSystemProperty("foo", "bar");
times = 1;
}};

setupAndRunGenericTest("-D", "hello=world,key=,foo=bar");

new FullVerifications() {{
configurator.addSystemProperty("hello", "world");
times = 1;
configurator.addSystemProperty("foo", "bar");
times = 1;
configurator.addSystemProperty("key", anyString);
times = 0;
configurator.addSystemProperty("key", "");
times = 1;
}};

setupAndRunGenericTest("-D", "hello=world,key,foo=bar");

new FullVerifications() {{
configurator.addSystemProperty("hello", "world");
times = 1;
configurator.addSystemProperty("foo", "bar");
times = 1;
configurator.addSystemProperty("key", "");
times = 1;
}};

setupAndRunGenericTest("-D", "hello=world", "-D", "key", "-D", "foo=bar");

new FullVerifications() {{
configurator.addSystemProperty("hello", "world");
times = 1;
configurator.addSystemProperty("foo", "bar");
times = 1;
configurator.addSystemProperty("key", "");
times = 1;
}};

setupAndRunGenericTest("-Dhello=world", "-Dkey", "-Dfoo=bar");

new FullVerifications() {{
configurator.addSystemProperty("hello", "world");
times = 1;
configurator.addSystemProperty("foo", "bar");
times = 1;
configurator.addSystemProperty("key", "");
times = 1;
}};
}

Expand Down Expand Up @@ -183,8 +225,8 @@ public void testInstantiationTypes() throws Exception {
times = 1;
configurator.addInstantiationType("foo", "bar");
times = 1;
configurator.addInstantiationType("key", anyString);
times = 0;
configurator.addInstantiationType("key", "");
times = 1;
}};
}

Expand All @@ -197,8 +239,8 @@ public void testTypeMappings() throws Exception {
times = 1;
configurator.addTypeMapping("foo", "bar");
times = 1;
configurator.addTypeMapping("key", anyString);
times = 0;
configurator.addTypeMapping("key", "");
times = 1;
}};
}

Expand All @@ -211,8 +253,8 @@ public void testAdditionalProperties() throws Exception {
times = 1;
configurator.addAdditionalProperty("foo", "bar");
times = 1;
configurator.addAdditionalProperty("key", anyString);
times = 0;
configurator.addAdditionalProperty("key", "");
times = 1;
}};
}

Expand Down Expand Up @@ -241,8 +283,8 @@ public void testImportMappings() throws Exception {
times = 1;
configurator.addImportMapping("foo", "bar");
times = 1;
configurator.addImportMapping("key", anyString);
times = 0;
configurator.addImportMapping("key", "");
times = 1;
}};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import io.swagger.codegen.utils.OptionUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.Test;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static java.util.Arrays.asList;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

Expand All @@ -16,39 +16,40 @@ public class OptionUtilsTest {

@Test
public void splitCommaSeparatedList() throws Exception {
doCommaSeparatedListTest("a,b,c", Arrays.asList("a", "b", "c"));
doCommaSeparatedListTest("a,,c", Arrays.asList("a", "c"));
doCommaSeparatedListTest("", new ArrayList<String>());
doCommaSeparatedListTest(null, new ArrayList<String>());
doCommaSeparatedListTest("a,b,c", asList("a", "b", "c"));
doCommaSeparatedListTest("a,,c", asList("a", "c"));
doCommaSeparatedListTest("", emptyList());
doCommaSeparatedListTest(null, emptyList());
}

@Test
public void testParseCommaSeparatedTuples() throws Exception {
doTupleListTest("a=1,b=2,c=3", Arrays.asList(Pair.of("a", "1"), Pair.of("b", "2"), Pair.of("c", "3")));
doTupleListTest("a=1,,c=3", Arrays.asList(Pair.of("a", "1"), Pair.of("c", "3")));
doTupleListTest("a=1,xyz,c=3", Arrays.asList(Pair.of("a", "1"), Pair.of("c", "3")));
doTupleListTest("a=1,=,c=3", Arrays.asList(Pair.of("a", "1"), Pair.of("c", "3")));
doTupleListTest("", new ArrayList<Pair<String, String>>());
doTupleListTest(null, new ArrayList<Pair<String, String>>());
doTupleListTest("a=1,b=2,c=3", asList(Pair.of("a", "1"), Pair.of("b", "2"), Pair.of("c", "3")));
doTupleListTest("xyz", asList(Pair.of("xyz", "")));
doTupleListTest("a=1,,c=3", asList(Pair.of("a", "1"), Pair.of("c", "3")));
doTupleListTest("a=1,xyz=,c=3", asList(Pair.of("a", "1"), Pair.of("xyz", ""), Pair.of("c", "3")));
doTupleListTest("a=1,xyz,c=3", asList(Pair.of("a", "1"), Pair.of("xyz", ""), Pair.of("c", "3")));
doTupleListTest("a=1,=,c=3", asList(Pair.of("a", "1"), Pair.of("c", "3")));
doTupleListTest("", emptyPairList());
doTupleListTest(null, emptyPairList());
}

private static void doTupleListTest(String input, List<Pair<String, String>> expectedResults) {
final List<Pair<String, String>> result = OptionUtils.parseCommaSeparatedTuples(input);
assertNotNull(result);
assertEquals(result.size(), expectedResults.size());
for (int i = 0; i < expectedResults.size(); i++) {
final Pair<String, String> actualPair = result.get(i);
final Pair<String, String> expected = expectedResults.get(i);
assertEquals(actualPair, expected);
}
assertEquals(result, expectedResults);
}

private static void doCommaSeparatedListTest(String csvStr, List<String> expectedResults) {
final List<String> result = OptionUtils.splitCommaSeparatedList(csvStr);
assertNotNull(result);
assertEquals(result.size(), expectedResults.size());
for (int i = 0; i < expectedResults.size(); i++) {
assertEquals(result.get(i), expectedResults.get(i));
}
assertEquals(result, expectedResults);
}
private static List<Pair<String,String>> emptyPairList() {
return Collections.emptyList();
}

private static List<String> emptyList() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
*/
public final class CodegenConfiguratorUtils {

public static void applySystemPropertiesKvpList(List<String> systemProperties, CodegenConfigurator configurator) {
for(String propString : systemProperties) {
applySystemPropertiesKvp(propString, configurator);
}
}

public static void applySystemPropertiesKvp(String systemProperties, CodegenConfigurator configurator) {
final Map<String, String> map = createMapFromKeyValuePairs(systemProperties);
for (Map.Entry<String, String> entry : map.entrySet()) {
Expand Down Expand Up @@ -81,6 +87,4 @@ private static Map<String, String> createMapFromKeyValuePairs(String commaSepara

return result;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@

import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import joptsimple.internal.Strings;

import static org.apache.commons.lang3.StringUtils.isNotEmpty;

public class OptionUtils {

public static List<Pair<String, String>> parseCommaSeparatedTuples(String input) {
public static List<Pair<String, String>> parseCommaSeparatedTuples(final String input) {

List<Pair<String, String>> results = new ArrayList<Pair<String, String>>();
final List<Pair<String, String>> results = new ArrayList<Pair<String, String>>();

final List<String> tuples = splitCommaSeparatedList(input);

for (String tuple : tuples) {
int ix = tuple.indexOf('=');
if (ix > 0 && ix < tuple.length() - 1) {
if (ix > 0 && ix <= tuple.length() - 1) {
final Pair<String, String> pair = Pair.of(tuple.substring(0, ix), tuple.substring(ix + 1));
results.add(pair);
} else if (ix < 0){
final Pair<String, String> pair = Pair.of(tuple, "");
results.add(pair);
}
}
//Strings.isNullOrEmpty(input)

return results;
}

Expand Down