-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #451 from swagger-api/develop_2.0
Merged from develop_2.0
- Loading branch information
Showing
34 changed files
with
913 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/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 | ||
|
||
root=./modules/swagger-codegen-distribution/pom.xml | ||
|
||
# gets version of swagger-codegen | ||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g') | ||
|
||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.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="$@ -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l async-scala -o samples/client/petstore/async-scala" | ||
|
||
java $JAVA_OPTS -jar $executable $ags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
modules/swagger-codegen-distribution/src/main/resources/logback.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<layout class="ch.qos.logback.classic.PatternLayout"> | ||
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern> | ||
</layout> | ||
</appender> | ||
<logger name="com.wordnik" level="debug"/> | ||
<root level="error"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
194 changes: 194 additions & 0 deletions
194
...-codegen/src/main/java/com/wordnik/swagger/codegen/languages/AsyncScalaClientCodegen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
package com.wordnik.swagger.codegen.languages; | ||
|
||
import com.wordnik.swagger.codegen.*; | ||
import com.wordnik.swagger.models.properties.*; | ||
|
||
import java.util.*; | ||
import java.io.File; | ||
|
||
public class AsyncScalaClientCodegen extends DefaultCodegen implements CodegenConfig { | ||
protected String invokerPackage = "io.swagger.client"; | ||
protected String groupId = "com.wordnik"; | ||
protected String artifactId = "swagger-client"; | ||
protected String artifactVersion = "1.0.0"; | ||
protected String sourceFolder = "src/main/scala"; | ||
protected String clientName = "SwaggerClient"; | ||
protected String authScheme = ""; | ||
protected boolean authPreemptive = false; | ||
protected boolean asyncHttpClient = !authScheme.isEmpty(); | ||
|
||
public CodegenType getTag() { | ||
return CodegenType.CLIENT; | ||
} | ||
|
||
public String getName() { | ||
return "async-scala"; | ||
} | ||
|
||
public String getHelp() { | ||
return "Generates an Asynchronous Scala client library."; | ||
} | ||
|
||
public AsyncScalaClientCodegen() { | ||
super(); | ||
outputFolder = "generated-code/async-scala"; | ||
modelTemplateFiles.put("model.mustache", ".scala"); | ||
apiTemplateFiles.put("api.mustache", ".scala"); | ||
templateDir = "asyncscala"; | ||
apiPackage = "io.swagger.client.api"; | ||
modelPackage = "io.swagger.client.model"; | ||
|
||
reservedWords = new HashSet<String> ( | ||
Arrays.asList( | ||
"abstract", "case", "catch", "class", "def", "do", "else", "extends", | ||
"false", "final", "finally", "for", "forSome", "if", "implicit", | ||
"import", "lazy", "match", "new", "null", "object", "override", "package", | ||
"private", "protected", "return", "sealed", "super", "this", "throw", | ||
"trait", "try", "true", "type", "val", "var", "while", "with", "yield") | ||
); | ||
|
||
additionalProperties.put("invokerPackage", invokerPackage); | ||
additionalProperties.put("groupId", groupId); | ||
additionalProperties.put("artifactId", artifactId); | ||
additionalProperties.put("artifactVersion", artifactVersion); | ||
additionalProperties.put("asyncHttpClient", asyncHttpClient); | ||
additionalProperties.put("authScheme", authScheme); | ||
additionalProperties.put("authPreemptive", authPreemptive); | ||
additionalProperties.put("clientName", clientName); | ||
|
||
supportingFiles.add(new SupportingFile("sbt.mustache", "", "build.sbt")); | ||
supportingFiles.add(new SupportingFile("client.mustache", | ||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), clientName + ".scala")); | ||
|
||
importMapping.remove("List"); | ||
importMapping.remove("Set"); | ||
importMapping.remove("Map"); | ||
|
||
importMapping.put("DateTime", "org.joda.time.DateTime"); | ||
importMapping.put("ListBuffer", "scala.collections.mutable.ListBuffer"); | ||
|
||
typeMapping = new HashMap<String, String>(); | ||
typeMapping.put("enum", "NSString"); | ||
typeMapping.put("array", "List"); | ||
typeMapping.put("set", "Set"); | ||
typeMapping.put("boolean", "Boolean"); | ||
typeMapping.put("string", "String"); | ||
typeMapping.put("int", "Int"); | ||
typeMapping.put("long", "Long"); | ||
typeMapping.put("float", "Float"); | ||
typeMapping.put("byte", "Byte"); | ||
typeMapping.put("short", "Short"); | ||
typeMapping.put("char", "Char"); | ||
typeMapping.put("long", "Long"); | ||
typeMapping.put("double", "Double"); | ||
typeMapping.put("object", "Any"); | ||
typeMapping.put("file", "File"); | ||
|
||
languageSpecificPrimitives = new HashSet<String>( | ||
Arrays.asList( | ||
"String", | ||
"boolean", | ||
"Boolean", | ||
"Double", | ||
"Int", | ||
"Long", | ||
"Float", | ||
"Object", | ||
"List", | ||
"Map") | ||
); | ||
instantiationTypes.put("array", "ListBuffer"); | ||
instantiationTypes.put("map", "HashMap"); | ||
} | ||
|
||
@Override | ||
public String escapeReservedWord(String name) { | ||
return "_" + name; | ||
} | ||
|
||
@Override | ||
public String apiFileFolder() { | ||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar); | ||
} | ||
|
||
public String modelFileFolder() { | ||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar); | ||
} | ||
|
||
@Override | ||
public String getTypeDeclaration(Property p) { | ||
if(p instanceof ArrayProperty) { | ||
ArrayProperty ap = (ArrayProperty) p; | ||
Property inner = ap.getItems(); | ||
return getSwaggerType(p) + "[" + getTypeDeclaration(inner) + "]"; | ||
} | ||
else if (p instanceof MapProperty) { | ||
MapProperty mp = (MapProperty) p; | ||
Property inner = mp.getAdditionalProperties(); | ||
|
||
return getSwaggerType(p) + "[String, " + getTypeDeclaration(inner) + "]"; | ||
} | ||
return super.getTypeDeclaration(p); | ||
} | ||
|
||
@Override | ||
public String getSwaggerType(Property p) { | ||
String swaggerType = super.getSwaggerType(p); | ||
String type = null; | ||
if(typeMapping.containsKey(swaggerType)) { | ||
type = typeMapping.get(swaggerType); | ||
if(languageSpecificPrimitives.contains(type)) | ||
return toModelName(type); | ||
} | ||
else | ||
type = swaggerType; | ||
return toModelName(type); | ||
} | ||
|
||
@Override | ||
public String toInstantiationType(Property p) { | ||
if (p instanceof MapProperty) { | ||
MapProperty ap = (MapProperty) p; | ||
String inner = getSwaggerType(ap.getAdditionalProperties()); | ||
return instantiationTypes.get("map") + "[String, " + inner + "]"; | ||
} | ||
else if (p instanceof ArrayProperty) { | ||
ArrayProperty ap = (ArrayProperty) p; | ||
String inner = getSwaggerType(ap.getItems()); | ||
return instantiationTypes.get("array") + "[" + inner + "]"; | ||
} | ||
else | ||
return null; | ||
} | ||
|
||
public String toDefaultValue(Property p) { | ||
if(p instanceof StringProperty) | ||
return "null"; | ||
else if (p instanceof BooleanProperty) | ||
return "null"; | ||
else if(p instanceof DateProperty) | ||
return "null"; | ||
else if(p instanceof DateTimeProperty) | ||
return "null"; | ||
else if (p instanceof DoubleProperty) | ||
return "null"; | ||
else if (p instanceof FloatProperty) | ||
return "null"; | ||
else if (p instanceof IntegerProperty) | ||
return "null"; | ||
else if (p instanceof LongProperty) | ||
return "null"; | ||
else if (p instanceof MapProperty) { | ||
MapProperty ap = (MapProperty) p; | ||
String inner = getSwaggerType(ap.getAdditionalProperties()); | ||
return "new HashMap[String, " + inner + "]() "; | ||
} | ||
else if (p instanceof ArrayProperty) { | ||
ArrayProperty ap = (ArrayProperty) p; | ||
String inner = getSwaggerType(ap.getItems()); | ||
return "new ListBuffer[" + inner + "]() "; | ||
} | ||
else | ||
return "null"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.