mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
Merge branches 'develop_2.0' and 'maven-plugin-configuration-improvements' of https://github.com/swagger-api/swagger-codegen into maven-plugin-configuration-improvements
Conflicts: modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java
This commit is contained in:
commit
b956d47a9d
47
.dockerignore
Normal file
47
.dockerignore
Normal file
@ -0,0 +1,47 @@
|
||||
*.iml
|
||||
out/
|
||||
*.ipr
|
||||
*.iws
|
||||
classpath.txt
|
||||
version.properties
|
||||
.project
|
||||
.classpath
|
||||
lib/*
|
||||
build/*
|
||||
generated-files/*
|
||||
generated-sources/*
|
||||
generated-code/*
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
/target
|
||||
/generated-files
|
||||
/nbactions.xml
|
||||
*.pyc
|
||||
__pycache__
|
||||
samples/server-generator/scalatra/output
|
||||
samples/server-generator/node/output/node_modules
|
||||
samples/server-generator/scalatra/target
|
||||
samples/server-generator/scalatra/output/.history
|
||||
samples/client/petstore/qt5cpp/PetStore/moc_*
|
||||
samples/client/petstore/qt5cpp/PetStore/*.o
|
||||
samples/client/petstore/objc/PetstoreClient.xcworkspace/xcuserdata
|
||||
samples/client/petstore/qt5cpp/build-*
|
||||
samples/client/petstore/qt5cpp/PetStore/PetStore
|
||||
samples/client/petstore/qt5cpp/PetStore/Makefile
|
||||
samples/client/petstore/java/hello.txt
|
||||
samples/client/petstore/android-java/hello.txt
|
||||
samples/client/petstore/objc/Build
|
||||
samples/client/petstore/objc/Pods
|
||||
samples/server/petstore/nodejs/node_modules
|
||||
target
|
||||
.idea
|
||||
.lib
|
||||
atlassian-ide-plugin.xml
|
||||
.DS_Store
|
||||
|
||||
samples/client/petstore/php/SwaggerClient-php/composer.lock
|
||||
samples/client/petstore/php/SwaggerClient-php/vendor/
|
||||
|
||||
samples/client/petstore/silex/SwaggerServer/composer.lock
|
||||
samples/client/petstore/silex/SwaggerServer/venodr/
|
9
.gitignore
vendored
9
.gitignore
vendored
@ -31,8 +31,10 @@ samples/client/petstore/qt5cpp/PetStore/PetStore
|
||||
samples/client/petstore/qt5cpp/PetStore/Makefile
|
||||
samples/client/petstore/java/hello.txt
|
||||
samples/client/petstore/android-java/hello.txt
|
||||
samples/client/petstore/objc/Build
|
||||
samples/client/petstore/objc/Pods
|
||||
samples/client/petstore/objc/SwaggerClientTests/Build
|
||||
samples/client/petstore/objc/SwaggerClientTests/Pods
|
||||
samples/client/petstore/objc/SwaggerClientTests/SwaggerClient.xcworkspace
|
||||
samples/client/petstore/objc/SwaggerClientTests/Podfile.lock
|
||||
samples/server/petstore/nodejs/node_modules
|
||||
target
|
||||
.idea
|
||||
@ -45,3 +47,6 @@ samples/client/petstore/php/SwaggerClient-php/vendor/
|
||||
|
||||
samples/client/petstore/silex/SwaggerServer/composer.lock
|
||||
samples/client/petstore/silex/SwaggerServer/venodr/
|
||||
|
||||
samples/client/petstore/python/.projectile
|
||||
samples/client/petstore/python/.venv/
|
||||
|
13
Dockerfile
Normal file
13
Dockerfile
Normal file
@ -0,0 +1,13 @@
|
||||
FROM maven:3.3-jdk-7
|
||||
|
||||
WORKDIR /src
|
||||
VOLUME /src
|
||||
VOLUME /root/.m2/repository
|
||||
|
||||
ADD . /opt/swagger-codegen
|
||||
|
||||
RUN cd /opt/swagger-codegen && mvn package
|
||||
|
||||
ENTRYPOINT ["java", "-jar", "/opt/swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"]
|
||||
|
||||
CMD ["help"]
|
26
README.md
26
README.md
@ -7,6 +7,24 @@ This is the swagger codegen project, which allows generation of client libraries
|
||||
|
||||
Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additional information about the Swagger project, including additional libraries with support for other languages and more.
|
||||
|
||||
## Build and run using docker
|
||||
|
||||
```
|
||||
git clone https://github.com/swagger-api/swagger-codegen
|
||||
|
||||
cd swagger-codegen
|
||||
|
||||
./run-in-docker.sh mvn package
|
||||
```
|
||||
|
||||
Build a nodejs server stub:
|
||||
|
||||
```
|
||||
./run-in-docker.sh generate \
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-l nodejs \
|
||||
-o samples/server/petstore/nodejs
|
||||
```
|
||||
|
||||
## Compatibility
|
||||
The Swagger Specification has undergone 3 revisions since initial creation in 2010. The swagger-codegen project has the following compatibilies with the swagger specification:
|
||||
@ -73,6 +91,7 @@ SYNOPSIS
|
||||
[(-o <output directory> | --output <output directory>)]
|
||||
[(-t <template directory> | --template-dir <template directory>)]
|
||||
[(-v | --verbose)]
|
||||
[(-s | --skip-overwrite)]
|
||||
|
||||
OPTIONS
|
||||
-a <authorization>, --auth <authorization>
|
||||
@ -105,6 +124,10 @@ OPTIONS
|
||||
|
||||
-v, --verbose
|
||||
verbose mode
|
||||
|
||||
-s , --skip-overwrite
|
||||
specifies if the existing files should be overwritten during
|
||||
the generation
|
||||
```
|
||||
|
||||
You can then compile and run the client, as well as unit tests against it:
|
||||
@ -165,6 +188,7 @@ AkkaScalaClientCodegen.java
|
||||
AndroidClientCodegen.java
|
||||
AsyncScalaClientCodegen.java
|
||||
CSharpClientCodegen.java
|
||||
FlashClientCodegen.java
|
||||
JavaClientCodegen.java
|
||||
JaxRSServerCodegen.java
|
||||
NodeJSServerCodegen.java
|
||||
@ -183,7 +207,7 @@ StaticDocCodegen.java
|
||||
StaticHtmlGenerator.java
|
||||
SwaggerGenerator.java
|
||||
SwaggerYamlGenerator.java
|
||||
SwiftGenerator.java
|
||||
SwiftCodegen.java
|
||||
TizenClientCodegen.java
|
||||
```
|
||||
|
||||
|
@ -18,20 +18,28 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
./bin/akka-scala-petstore.sh
|
||||
./bin/android-java-petstore.sh
|
||||
./bin/csharp-petstore.sh
|
||||
./bin/dynamic-html.sh
|
||||
./bin/html-petstore.sh
|
||||
./bin/jaxrs-petstore-server.sh
|
||||
./bin/java-petstore.sh
|
||||
./bin/qt5-petstore.sh
|
||||
./bin/jaxrs-petstore-server.sh
|
||||
./bin/nodejs-petstore-server.sh
|
||||
./bin/objc-petstore.sh
|
||||
./bin/perl-petstore.sh
|
||||
./bin/php-petstore.sh
|
||||
./bin/python-petstore.sh
|
||||
./bin/python3-petstore.sh
|
||||
./bin/qt5-petstore.sh
|
||||
./bin/retrofit-petstore.sh
|
||||
./bin/ruby-petstore.sh
|
||||
./bin/objc-petstore.sh
|
||||
./bin/scala-async-petstore.sh
|
||||
./bin/scala-petstore.sh
|
||||
./bin/scalatra-petstore-server.sh
|
||||
./bin/silex-petstore-server.sh
|
||||
./bin/spring-mvc-petstore-server.sh
|
||||
./bin/swift-petstore.sh
|
||||
./bin/tizen-petstore.sh
|
||||
./bin/typescript-angular-petstore.sh
|
||||
./bin/typescript-node-petstore.sh
|
||||
|
31
bin/csharp-dotnet2-petstore.sh
Executable file
31
bin/csharp-dotnet2-petstore.sh
Executable file
@ -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 -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l CsharpDotNet2 -o samples/client/petstore/csharp-dotnet2/SwaggerClientTest/Lib/SwaggerClient"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -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.json -l csharp -o samples/client/petstore/csharp"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l csharp -o samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
31
bin/flash-petstore.sh
Executable file
31
bin/flash-petstore.sh
Executable file
@ -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/flash -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l flash -o samples/client/petstore/flash"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
31
bin/java-inflector-petstore-server.sh
Executable file
31
bin/java-inflector-petstore-server.sh
Executable file
@ -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/JavaInflector -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l inflector -o samples/server/petstore/java-inflector"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
5
bin/ruby-petstore.json
Normal file
5
bin/ruby-petstore.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"gemName": "petstore",
|
||||
"moduleName": "Petstore",
|
||||
"gemVersion": "1.0.0"
|
||||
}
|
@ -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/ruby -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l ruby -o samples/client/petstore/ruby"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/ruby -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l ruby -c bin/ruby-petstore.json -o samples/client/petstore/ruby"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -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/silex -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l silex -o samples/client/petstore/silex"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/silex -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l silex -o samples/server/petstore/silex"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
31
bin/sinatra-petstore-server.sh
Executable file
31
bin/sinatra-petstore-server.sh
Executable file
@ -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/sinatra -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l sinatra -o samples/server/petstore/sinatra"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
4
bin/swift-petstore.json
Normal file
4
bin/swift-petstore.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"projectName": "PetstoreClient",
|
||||
"responseAs": "PromiseKit"
|
||||
}
|
@ -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/swift -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l swift -o samples/client/petstore/swift"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/swift -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l swift -c ./bin/swift-petstore.json -o samples/client/petstore/swift"
|
||||
|
||||
java -DappName=PetstoreClient $JAVA_OPTS -jar $executable $ags
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
31
bin/typescript-angular-petstore.sh
Executable file
31
bin/typescript-angular-petstore.sh
Executable file
@ -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 -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-angular -o samples/client/petstore/typescript-angular"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
31
bin/typescript-node-petstore.sh
Executable file
31
bin/typescript-node-petstore.sh
Executable file
@ -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 -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-node -o samples/client/petstore/typescript-node"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -41,7 +41,7 @@
|
||||
<version>2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>reduced-pom</id>
|
||||
<id>process-resources</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
@ -52,15 +52,6 @@
|
||||
<dependencyReducedPomLocation>
|
||||
${java.io.tmpdir}/dependency-reduced-pom.xml
|
||||
</dependencyReducedPomLocation>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>process-resources</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
|
||||
@ -99,6 +90,13 @@
|
||||
<version>${slf4j-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -66,6 +66,10 @@ public class Generate implements Runnable {
|
||||
"Supported options can be different for each language. Run config-help -l {lang} command for language specific config options.")
|
||||
private String configFile;
|
||||
|
||||
@Option(name = {"-s", "--skip-overwrite"}, title = "skip overwrite", description = "specifies if the existing files should be " +
|
||||
"overwritten during the generation.")
|
||||
private boolean skipOverwrite;
|
||||
|
||||
/**
|
||||
* Tries to load config class with SPI first, then with class name directly from classpath
|
||||
*
|
||||
@ -118,6 +122,7 @@ public class Generate implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
config.setSkipOverwrite(skipOverwrite);
|
||||
input.setConfig(config);
|
||||
|
||||
Swagger swagger = new SwaggerParser().read(spec, input.getAuthorizationValues(), true);
|
||||
|
@ -0,0 +1,73 @@
|
||||
package io.swagger.codegen;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GenerateTest {
|
||||
|
||||
private static final String TEST_SKIP_OVERWRITE = "testSkipOverwrite";
|
||||
private static final String POM_FILE = "pom.xml";
|
||||
private static final String MODEL_ORDER_FILE = "/src/main/java/io/swagger/client/model/Order.java";
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void testSkipOverwrite() throws IOException {
|
||||
final File output = folder.getRoot();
|
||||
|
||||
String[] args = {"generate", "-i", "src/test/resources/petstore.json", "-l", "java", "-o", output.getAbsolutePath()};
|
||||
String[] argsWithSparam = Arrays.copyOf(args, args.length + 1);
|
||||
argsWithSparam[args.length] = "-s";
|
||||
|
||||
//generate content first time without -s flag, so all generated files should be recorded
|
||||
SwaggerCodegen.main(args);
|
||||
final File order = new File(output, MODEL_ORDER_FILE);
|
||||
assertTrue(order.exists());
|
||||
|
||||
//change content of one file
|
||||
changeContent(order);
|
||||
|
||||
//generate content second time without -s flag, so changed file should be rewritten
|
||||
SwaggerCodegen.main(args);
|
||||
//order = new File(output, MODEL_ORDER_FILE);
|
||||
assertTrue(!TEST_SKIP_OVERWRITE.equals(FileUtils.readFileToString(order, StandardCharsets.UTF_8)));
|
||||
|
||||
//change content again
|
||||
changeContent(order);
|
||||
//delete file
|
||||
final File pom = new File(output, POM_FILE);
|
||||
if (!pom.delete()) {
|
||||
fail();
|
||||
}
|
||||
|
||||
//generate content third time with -s flag, so changed file should not be rewritten
|
||||
//and deleted file should be recorded
|
||||
SwaggerCodegen.main(argsWithSparam);
|
||||
assertEquals(FileUtils.readFileToString(order, StandardCharsets.UTF_8), TEST_SKIP_OVERWRITE);
|
||||
assertTrue(pom.exists());
|
||||
}
|
||||
|
||||
private void changeContent(File file) throws IOException {
|
||||
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), UTF_8));
|
||||
out.write(TEST_SKIP_OVERWRITE);
|
||||
out.close();
|
||||
}
|
||||
}
|
977
modules/swagger-codegen-cli/src/test/resources/petstore.json
Normal file
977
modules/swagger-codegen-cli/src/test/resources/petstore.json
Normal file
@ -0,0 +1,977 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters",
|
||||
"version": "1.0.0",
|
||||
"title": "Swagger Petstore",
|
||||
"termsOfService": "http://swagger.io/terms/",
|
||||
"contact": {
|
||||
"email": "apiteam@swagger.io"
|
||||
},
|
||||
"license": {
|
||||
"name": "Apache 2.0",
|
||||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
}
|
||||
},
|
||||
"host": "petstore.swagger.io",
|
||||
"basePath": "/v2",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"paths": {
|
||||
"/pet": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Add a new pet to the store",
|
||||
"description": "",
|
||||
"operationId": "addPet",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "Pet object that needs to be added to the store",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"405": {
|
||||
"description": "Invalid input"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write:pets",
|
||||
"read:pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"put": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Update an existing pet",
|
||||
"description": "",
|
||||
"operationId": "updatePet",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "Pet object that needs to be added to the store",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"405": {
|
||||
"description": "Validation exception"
|
||||
},
|
||||
"404": {
|
||||
"description": "Pet not found"
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid ID supplied"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write:pets",
|
||||
"read:pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pet/findByStatus": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Finds Pets by status",
|
||||
"description": "Multiple status values can be provided with comma seperated strings",
|
||||
"operationId": "findPetsByStatus",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "status",
|
||||
"in": "query",
|
||||
"description": "Status values that need to be considered for filter",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"collectionFormat": "multi",
|
||||
"default": "available"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid status value"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write:pets",
|
||||
"read:pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pet/findByTags": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Finds Pets by tags",
|
||||
"description": "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
|
||||
"operationId": "findPetsByTags",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "tags",
|
||||
"in": "query",
|
||||
"description": "Tags to filter by",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"collectionFormat": "multi"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid tag value"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write:pets",
|
||||
"read:pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pet/{petId}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Find pet by ID",
|
||||
"description": "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions",
|
||||
"operationId": "getPetById",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "petId",
|
||||
"in": "path",
|
||||
"description": "ID of pet that needs to be fetched",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"404": {
|
||||
"description": "Pet not found"
|
||||
},
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid ID supplied"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"api_key": []
|
||||
},
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write:pets",
|
||||
"read:pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"post": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Updates a pet in the store with form data",
|
||||
"description": "",
|
||||
"operationId": "updatePetWithForm",
|
||||
"consumes": [
|
||||
"application/x-www-form-urlencoded"
|
||||
],
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "petId",
|
||||
"in": "path",
|
||||
"description": "ID of pet that needs to be updated",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
"in": "formData",
|
||||
"description": "Updated name of the pet",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "status",
|
||||
"in": "formData",
|
||||
"description": "Updated status of the pet",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"405": {
|
||||
"description": "Invalid input"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write:pets",
|
||||
"read:pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"delete": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Deletes a pet",
|
||||
"description": "",
|
||||
"operationId": "deletePet",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "api_key",
|
||||
"in": "header",
|
||||
"description": "",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "petId",
|
||||
"in": "path",
|
||||
"description": "Pet id to delete",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"400": {
|
||||
"description": "Invalid pet value"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write:pets",
|
||||
"read:pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pet/{petId}/uploadImage": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "uploads an image",
|
||||
"description": "",
|
||||
"operationId": "uploadFile",
|
||||
"consumes": [
|
||||
"multipart/form-data"
|
||||
],
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "petId",
|
||||
"in": "path",
|
||||
"description": "ID of pet to update",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
{
|
||||
"name": "additionalMetadata",
|
||||
"in": "formData",
|
||||
"description": "Additional data to pass to server",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "file",
|
||||
"in": "formData",
|
||||
"description": "file to upload",
|
||||
"required": false,
|
||||
"type": "file"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"default": {
|
||||
"description": "successful operation"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write:pets",
|
||||
"read:pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/store/inventory": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"store"
|
||||
],
|
||||
"summary": "Returns pet inventories by status",
|
||||
"description": "Returns a map of status codes to quantities",
|
||||
"operationId": "getInventory",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"api_key": []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/store/order": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"store"
|
||||
],
|
||||
"summary": "Place an order for a pet",
|
||||
"description": "",
|
||||
"operationId": "placeOrder",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "order placed for purchasing the pet",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Order"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Order"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid Order"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/store/order/{orderId}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"store"
|
||||
],
|
||||
"summary": "Find purchase order by ID",
|
||||
"description": "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
|
||||
"operationId": "getOrderById",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "orderId",
|
||||
"in": "path",
|
||||
"description": "ID of pet that needs to be fetched",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"404": {
|
||||
"description": "Order not found"
|
||||
},
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Order"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid ID supplied"
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"tags": [
|
||||
"store"
|
||||
],
|
||||
"summary": "Delete purchase order by ID",
|
||||
"description": "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
|
||||
"operationId": "deleteOrder",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "orderId",
|
||||
"in": "path",
|
||||
"description": "ID of the order that needs to be deleted",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"404": {
|
||||
"description": "Order not found"
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid ID supplied"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/user": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Create user",
|
||||
"description": "This can only be done by the logged in user.",
|
||||
"operationId": "createUser",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "Created user object",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/User"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"default": {
|
||||
"description": "successful operation"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/user/createWithArray": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Creates list of users with given input array",
|
||||
"description": "",
|
||||
"operationId": "createUsersWithArrayInput",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "List of user object",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/User"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"default": {
|
||||
"description": "successful operation"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/user/createWithList": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Creates list of users with given input array",
|
||||
"description": "",
|
||||
"operationId": "createUsersWithListInput",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "List of user object",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/User"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"default": {
|
||||
"description": "successful operation"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/user/login": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Logs user into the system",
|
||||
"description": "",
|
||||
"operationId": "loginUser",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "username",
|
||||
"in": "query",
|
||||
"description": "The user name for login",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "password",
|
||||
"in": "query",
|
||||
"description": "The password for login in clear text",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid username/password supplied"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/user/logout": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Logs out current logged in user session",
|
||||
"description": "",
|
||||
"operationId": "logoutUser",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"responses": {
|
||||
"default": {
|
||||
"description": "successful operation"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/user/{username}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Get user by user name",
|
||||
"description": "",
|
||||
"operationId": "getUserByName",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "username",
|
||||
"in": "path",
|
||||
"description": "The name that needs to be fetched. Use user1 for testing. ",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"404": {
|
||||
"description": "User not found"
|
||||
},
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/User"
|
||||
},
|
||||
"examples": {
|
||||
"application/json": {
|
||||
"id": 1,
|
||||
"username": "johnp",
|
||||
"firstName": "John",
|
||||
"lastName": "Public",
|
||||
"email": "johnp@swagger.io",
|
||||
"password": "-secret-",
|
||||
"phone": "0123456789",
|
||||
"userStatus": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid username supplied"
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Updated user",
|
||||
"description": "This can only be done by the logged in user.",
|
||||
"operationId": "updateUser",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "username",
|
||||
"in": "path",
|
||||
"description": "name that need to be deleted",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "Updated user object",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/User"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"404": {
|
||||
"description": "User not found"
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid user supplied"
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Delete user",
|
||||
"description": "This can only be done by the logged in user.",
|
||||
"operationId": "deleteUser",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "username",
|
||||
"in": "path",
|
||||
"description": "The name that needs to be deleted",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"404": {
|
||||
"description": "User not found"
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid username supplied"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
"api_key": {
|
||||
"type": "apiKey",
|
||||
"name": "api_key",
|
||||
"in": "header"
|
||||
},
|
||||
"petstore_auth": {
|
||||
"type": "oauth2",
|
||||
"authorizationUrl": "http://petstore.swagger.io/api/oauth/dialog",
|
||||
"flow": "implicit",
|
||||
"scopes": {
|
||||
"write:pets": "modify pets in your account",
|
||||
"read:pets": "read your pets"
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"User": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
},
|
||||
"firstName": {
|
||||
"type": "string"
|
||||
},
|
||||
"lastName": {
|
||||
"type": "string"
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"phone": {
|
||||
"type": "string"
|
||||
},
|
||||
"userStatus": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"description": "User Status"
|
||||
}
|
||||
},
|
||||
"xml": {
|
||||
"name": "User"
|
||||
}
|
||||
},
|
||||
"Category": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"xml": {
|
||||
"name": "Category"
|
||||
}
|
||||
},
|
||||
"Pet": {
|
||||
"required": [
|
||||
"name",
|
||||
"photoUrls"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"category": {
|
||||
"$ref": "#/definitions/Category"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"example": "doggie"
|
||||
},
|
||||
"photoUrls": {
|
||||
"type": "array",
|
||||
"xml": {
|
||||
"name": "photoUrl",
|
||||
"wrapped": true
|
||||
},
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"tags": {
|
||||
"type": "array",
|
||||
"xml": {
|
||||
"name": "tag",
|
||||
"wrapped": true
|
||||
},
|
||||
"items": {
|
||||
"$ref": "#/definitions/Tag"
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"description": "pet status in the store",
|
||||
"enum": [
|
||||
"available",
|
||||
"pending",
|
||||
"sold"
|
||||
]
|
||||
}
|
||||
},
|
||||
"xml": {
|
||||
"name": "Pet"
|
||||
}
|
||||
},
|
||||
"Tag": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"xml": {
|
||||
"name": "Tag"
|
||||
}
|
||||
},
|
||||
"Order": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"petId": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"quantity": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"shipDate": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"description": "Order Status",
|
||||
"enum": [
|
||||
"placed",
|
||||
"approved",
|
||||
"delivered"
|
||||
]
|
||||
},
|
||||
"complete": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"xml": {
|
||||
"name": "Order"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.DefaultGenerator;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
@ -30,6 +31,9 @@ import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import config.Config;
|
||||
import config.ConfigParser;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
@ -88,6 +92,11 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
@Parameter(name = "language", required = true)
|
||||
private String language;
|
||||
|
||||
/**
|
||||
* Path to json configuration file.
|
||||
*/
|
||||
@Parameter(name = "configurationFile", required = false)
|
||||
private String configurationFile;
|
||||
/**
|
||||
* A map of language-specific parameters as passed with the -c option to the command line
|
||||
*/
|
||||
@ -138,6 +147,21 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
}
|
||||
|
||||
ClientOptInput input = new ClientOptInput().opts(clientOpts).swagger(swagger);
|
||||
|
||||
if (null != configurationFile) {
|
||||
Config genConfig = ConfigParser.read(configurationFile);
|
||||
if (null != genConfig) {
|
||||
for (CliOption langCliOption : config.cliOptions()) {
|
||||
if (genConfig.hasOption(langCliOption.getOpt())) {
|
||||
config.additionalProperties().put(langCliOption.getOpt(), genConfig.getOption(langCliOption.getOpt()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("Unable to read configuration file");
|
||||
}
|
||||
}
|
||||
|
||||
ClientOptInput input = new ClientOptInput().opts(new ClientOpts()).swagger(swagger);
|
||||
input.setConfig(config);
|
||||
new DefaultGenerator().opts(input).generate();
|
||||
|
||||
|
@ -83,9 +83,7 @@
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<configuration>
|
||||
<recompileMode>incremental</recompileMode>
|
||||
</configuration>
|
||||
<recompileMode>incremental</recompileMode>
|
||||
<jvmArgs>
|
||||
<jvmArg>-Xmx384m</jvmArg>
|
||||
</jvmArgs>
|
||||
@ -149,14 +147,6 @@
|
||||
<artifactId>scala-maven-plugin</artifactId>
|
||||
<version>${scala-maven-plugin-version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<configuration>
|
||||
<releaseProfiles>release</releaseProfiles>
|
||||
<goals>sign</goals>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
@ -180,7 +170,7 @@
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<scala-version>${scala-version}</scala-version>
|
||||
<scalaVersion>${scala-version}</scalaVersion>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -65,6 +65,8 @@ public interface CodegenConfig {
|
||||
|
||||
CodegenModel fromModel(String name, Model model);
|
||||
|
||||
CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions);
|
||||
|
||||
CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map<String, Model> definitions);
|
||||
|
||||
List<CodegenSecurity> fromSecurity(Map<String, SecuritySchemeDefinition> schemes);
|
||||
@ -102,4 +104,8 @@ public interface CodegenConfig {
|
||||
String apiFilename(String templateName, String tag);
|
||||
|
||||
boolean shouldOverwrite(String filename);
|
||||
|
||||
boolean isSkipOverwrite();
|
||||
|
||||
void setSkipOverwrite(boolean skipOverwrite);
|
||||
}
|
||||
|
@ -30,6 +30,23 @@ public class CodegenOperation {
|
||||
public List<Map<String, String>> examples;
|
||||
public ExternalDocs externalDocs;
|
||||
|
||||
private boolean nonempty(List<CodegenParameter> params)
|
||||
{
|
||||
return params != null && params.size() > 0;
|
||||
}
|
||||
public boolean getHasBodyParam() {
|
||||
return nonempty(bodyParams);
|
||||
}
|
||||
public boolean getHasQueryParams() {
|
||||
return nonempty(bodyParams);
|
||||
}
|
||||
public boolean getHasHeaderParams() {
|
||||
return nonempty(bodyParams);
|
||||
}
|
||||
public boolean getHasPathParams() {
|
||||
return nonempty(bodyParams);
|
||||
}
|
||||
|
||||
// legacy support
|
||||
public String nickname;
|
||||
}
|
||||
|
@ -1,10 +1,18 @@
|
||||
package io.swagger.codegen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
public class CodegenParameter {
|
||||
public Boolean isFormParam, isQueryParam, isPathParam, isHeaderParam,
|
||||
isCookieParam, isBodyParam, isFile, notFile, hasMore, isContainer, secondaryParam;
|
||||
public String baseName, paramName, dataType, collectionFormat, description, baseType, defaultValue;
|
||||
public String jsonSchema;
|
||||
public boolean isEnum;
|
||||
public List<String> _enum;
|
||||
public Map<String, Object> allowableValues;
|
||||
|
||||
/**
|
||||
* Determines whether this parameter is mandatory. If the parameter is in "path",
|
||||
@ -35,6 +43,13 @@ public class CodegenParameter {
|
||||
output.required = this.required;
|
||||
output.jsonSchema = this.jsonSchema;
|
||||
output.defaultValue = this.defaultValue;
|
||||
output.isEnum = this.isEnum;
|
||||
if (this._enum != null) {
|
||||
output._enum = new ArrayList<String>(this._enum);
|
||||
}
|
||||
if (this.allowableValues != null) {
|
||||
output.allowableValues = new HashMap<String, Object>(this.allowableValues);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@ -34,4 +34,108 @@ public class CodegenProperty {
|
||||
public boolean isEnum;
|
||||
public List<String> _enum;
|
||||
public Map<String, Object> allowableValues;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final CodegenProperty other = (CodegenProperty) obj;
|
||||
if ((this.baseName == null) ? (other.baseName != null) : !this.baseName.equals(other.baseName)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.complexType == null) ? (other.complexType != null) : !this.complexType.equals(other.complexType)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.getter == null) ? (other.getter != null) : !this.getter.equals(other.getter)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.setter == null) ? (other.setter != null) : !this.setter.equals(other.setter)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.description == null) ? (other.description != null) : !this.description.equals(other.description)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.datatype == null) ? (other.datatype != null) : !this.datatype.equals(other.datatype)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.datatypeWithEnum == null) ? (other.datatypeWithEnum != null) : !this.datatypeWithEnum.equals(other.datatypeWithEnum)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.min == null) ? (other.min != null) : !this.min.equals(other.min)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.max == null) ? (other.max != null) : !this.max.equals(other.max)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.defaultValue == null) ? (other.defaultValue != null) : !this.defaultValue.equals(other.defaultValue)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.baseType == null) ? (other.baseType != null) : !this.baseType.equals(other.baseType)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.containerType == null) ? (other.containerType != null) : !this.containerType.equals(other.containerType)) {
|
||||
return false;
|
||||
}
|
||||
if (this.maxLength != other.maxLength && (this.maxLength == null || !this.maxLength.equals(other.maxLength))) {
|
||||
return false;
|
||||
}
|
||||
if (this.minLength != other.minLength && (this.minLength == null || !this.minLength.equals(other.minLength))) {
|
||||
return false;
|
||||
}
|
||||
if ((this.pattern == null) ? (other.pattern != null) : !this.pattern.equals(other.pattern)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.example == null) ? (other.example != null) : !this.example.equals(other.example)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.jsonSchema == null) ? (other.jsonSchema != null) : !this.jsonSchema.equals(other.jsonSchema)) {
|
||||
return false;
|
||||
}
|
||||
if (this.minimum != other.minimum && (this.minimum == null || !this.minimum.equals(other.minimum))) {
|
||||
return false;
|
||||
}
|
||||
if (this.maximum != other.maximum && (this.maximum == null || !this.maximum.equals(other.maximum))) {
|
||||
return false;
|
||||
}
|
||||
if (this.exclusiveMinimum != other.exclusiveMinimum && (this.exclusiveMinimum == null || !this.exclusiveMinimum.equals(other.exclusiveMinimum))) {
|
||||
return false;
|
||||
}
|
||||
if (this.exclusiveMaximum != other.exclusiveMaximum && (this.exclusiveMaximum == null || !this.exclusiveMaximum.equals(other.exclusiveMaximum))) {
|
||||
return false;
|
||||
}
|
||||
if (this.required != other.required && (this.required == null || !this.required.equals(other.required))) {
|
||||
return false;
|
||||
}
|
||||
if (this.secondaryParam != other.secondaryParam && (this.secondaryParam == null || !this.secondaryParam.equals(other.secondaryParam))) {
|
||||
return false;
|
||||
}
|
||||
if (this.isPrimitiveType != other.isPrimitiveType && (this.isPrimitiveType == null || !this.isPrimitiveType.equals(other.isPrimitiveType))) {
|
||||
return false;
|
||||
}
|
||||
if (this.isContainer != other.isContainer && (this.isContainer == null || !this.isContainer.equals(other.isContainer))) {
|
||||
return false;
|
||||
}
|
||||
if (this.isNotContainer != other.isNotContainer && (this.isNotContainer == null || !this.isNotContainer.equals(other.isNotContainer))) {
|
||||
return false;
|
||||
}
|
||||
if (this.isEnum != other.isEnum) {
|
||||
return false;
|
||||
}
|
||||
if (this._enum != other._enum && (this._enum == null || !this._enum.equals(other._enum))) {
|
||||
return false;
|
||||
}
|
||||
if (this.allowableValues != other.allowableValues && (this.allowableValues == null || !this.allowableValues.equals(other.allowableValues))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.swagger.codegen;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class CodegenSecurity {
|
||||
public String name;
|
||||
public String type;
|
||||
@ -7,4 +9,7 @@ public class CodegenSecurity {
|
||||
// ApiKey specific
|
||||
public String keyParamName;
|
||||
public Boolean isKeyInQuery, isKeyInHeader;
|
||||
// Oauth specific
|
||||
public String flow, authorizationUrl, tokenUrl;
|
||||
public Set<String> scopes;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import io.swagger.models.Swagger;
|
||||
import io.swagger.models.auth.ApiKeyAuthDefinition;
|
||||
import io.swagger.models.auth.BasicAuthDefinition;
|
||||
import io.swagger.models.auth.In;
|
||||
import io.swagger.models.auth.OAuth2Definition;
|
||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||
import io.swagger.models.parameters.BodyParameter;
|
||||
import io.swagger.models.parameters.CookieParameter;
|
||||
@ -36,6 +37,7 @@ import io.swagger.models.properties.LongProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.PropertyBuilder;
|
||||
import io.swagger.models.properties.PropertyBuilder.PropertyId;
|
||||
import io.swagger.models.properties.RefProperty;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
import io.swagger.util.Json;
|
||||
@ -49,6 +51,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@ -60,7 +63,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public class DefaultCodegen {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);
|
||||
protected static final Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);
|
||||
|
||||
protected String outputFolder = "";
|
||||
protected Set<String> defaultIncludes = new HashSet<String>();
|
||||
@ -76,6 +79,8 @@ public class DefaultCodegen {
|
||||
protected Map<String, Object> additionalProperties = new HashMap<String, Object>();
|
||||
protected List<SupportingFile> supportingFiles = new ArrayList<SupportingFile>();
|
||||
protected List<CliOption> cliOptions = new ArrayList<CliOption>();
|
||||
protected boolean skipOverwrite;
|
||||
protected boolean supportsInheritance = false;
|
||||
|
||||
public List<CliOption> cliOptions() {
|
||||
return cliOptions;
|
||||
@ -225,6 +230,11 @@ public class DefaultCodegen {
|
||||
}
|
||||
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
return operationId;
|
||||
}
|
||||
|
||||
@ -422,14 +432,6 @@ public class DefaultCodegen {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
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 ArrayList<" + inner + ">() ";
|
||||
} else {
|
||||
return "null";
|
||||
}
|
||||
@ -506,6 +508,10 @@ public class DefaultCodegen {
|
||||
}
|
||||
|
||||
public CodegenModel fromModel(String name, Model model) {
|
||||
return fromModel(name, model, null);
|
||||
}
|
||||
|
||||
public CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions) {
|
||||
CodegenModel m = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
|
||||
if (reservedWords.contains(name)) {
|
||||
m.name = escapeReservedWord(name);
|
||||
@ -525,12 +531,59 @@ public class DefaultCodegen {
|
||||
// TODO
|
||||
} else if (model instanceof ComposedModel) {
|
||||
final ComposedModel composed = (ComposedModel) model;
|
||||
Map<String, Property> properties = new HashMap<String, Property>();
|
||||
List<String> required = new ArrayList<String>();
|
||||
// parent model
|
||||
final RefModel parent = (RefModel) composed.getParent();
|
||||
final String parentModel = toModelName(parent.getSimpleRef());
|
||||
m.parent = parentModel;
|
||||
addImport(m, parentModel);
|
||||
final ModelImpl child = (ModelImpl) composed.getChild();
|
||||
addVars(m, child.getProperties(), child.getRequired());
|
||||
if (parent != null) {
|
||||
final String parentRef = toModelName(parent.getSimpleRef());
|
||||
m.parent = parentRef;
|
||||
addImport(m, parentRef);
|
||||
if (!supportsInheritance && allDefinitions != null) {
|
||||
final Model parentModel = allDefinitions.get(parentRef);
|
||||
if (parentModel instanceof ModelImpl) {
|
||||
final ModelImpl _parent = (ModelImpl) parentModel;
|
||||
if (_parent.getProperties() != null) {
|
||||
properties.putAll(_parent.getProperties());
|
||||
}
|
||||
if (_parent.getRequired() != null) {
|
||||
required.addAll(_parent.getRequired());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// interfaces (intermediate models)
|
||||
if (allDefinitions != null) {
|
||||
for (RefModel _interface : composed.getInterfaces()) {
|
||||
final String interfaceRef = toModelName(_interface.getSimpleRef());
|
||||
final Model interfaceModel = allDefinitions.get(interfaceRef);
|
||||
if (interfaceModel instanceof ModelImpl) {
|
||||
final ModelImpl _interfaceModel = (ModelImpl) interfaceModel;
|
||||
if (_interfaceModel.getProperties() != null) {
|
||||
properties.putAll(_interfaceModel.getProperties());
|
||||
}
|
||||
if (_interfaceModel.getRequired() != null) {
|
||||
required.addAll(_interfaceModel.getRequired());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// child model (properties owned by the model itself)
|
||||
Model child = composed.getChild();
|
||||
if (child != null && child instanceof RefModel && allDefinitions != null) {
|
||||
final String childRef = ((RefModel) child).getSimpleRef();
|
||||
child = allDefinitions.get(childRef);
|
||||
}
|
||||
if (child != null && child instanceof ModelImpl) {
|
||||
final ModelImpl _child = (ModelImpl) child;
|
||||
if (_child.getProperties() != null) {
|
||||
properties.putAll(_child.getProperties());
|
||||
}
|
||||
if (_child.getRequired() != null) {
|
||||
required.addAll(_child.getRequired());
|
||||
}
|
||||
}
|
||||
addVars(m, properties, required);
|
||||
} else {
|
||||
ModelImpl impl = (ModelImpl) model;
|
||||
if (impl.getAdditionalProperties() != null) {
|
||||
@ -553,7 +606,7 @@ public class DefaultCodegen {
|
||||
|
||||
public CodegenProperty fromProperty(String name, Property p) {
|
||||
if (p == null) {
|
||||
LOGGER.error("unexpected missing property for name " + null);
|
||||
LOGGER.error("unexpected missing property for name " + name);
|
||||
return null;
|
||||
}
|
||||
CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY);
|
||||
@ -583,7 +636,9 @@ public class DefaultCodegen {
|
||||
if (np.getMaximum() != null) {
|
||||
allowableValues.put("max", np.getMaximum());
|
||||
}
|
||||
property.allowableValues = allowableValues;
|
||||
if(allowableValues.size() > 0) {
|
||||
property.allowableValues = allowableValues;
|
||||
}
|
||||
}
|
||||
|
||||
if (p instanceof StringProperty) {
|
||||
@ -850,6 +905,17 @@ public class DefaultCodegen {
|
||||
}
|
||||
op.bodyParam = bodyParam;
|
||||
op.httpMethod = httpMethod.toUpperCase();
|
||||
// move "required" parameters in front of "optional" parameters
|
||||
Collections.sort(allParams, new Comparator<CodegenParameter>() {
|
||||
@Override
|
||||
public int compare(CodegenParameter one, CodegenParameter another) {
|
||||
boolean oneRequired = one.required == null ? false : one.required;
|
||||
boolean anotherRequired = another.required == null ? false : another.required;
|
||||
if (oneRequired == anotherRequired) return 0;
|
||||
else if (oneRequired) return -1;
|
||||
else return 1;
|
||||
}
|
||||
});
|
||||
op.allParams = addHasMore(allParams);
|
||||
op.bodyParams = addHasMore(bodyParams);
|
||||
op.pathParams = addHasMore(pathParams);
|
||||
@ -964,7 +1030,9 @@ public class DefaultCodegen {
|
||||
p.baseType = pr.datatype;
|
||||
imports.add(pr.baseType);
|
||||
} else {
|
||||
property = PropertyBuilder.build(qp.getType(), qp.getFormat(), null);
|
||||
Map<PropertyId, Object> args = new HashMap<PropertyId, Object>();
|
||||
args.put(PropertyId.ENUM, qp.getEnum());
|
||||
property = PropertyBuilder.build(qp.getType(), qp.getFormat(), args);
|
||||
}
|
||||
if (property == null) {
|
||||
LOGGER.warn("warning! Property type \"" + qp.getType() + "\" not found for parameter \"" + param.getName() + "\", using String");
|
||||
@ -972,8 +1040,11 @@ public class DefaultCodegen {
|
||||
}
|
||||
property.setRequired(param.getRequired());
|
||||
CodegenProperty model = fromProperty(qp.getName(), property);
|
||||
p.collectionFormat = collectionFormat;
|
||||
p.dataType = model.datatype;
|
||||
p.isEnum = model.isEnum;
|
||||
p._enum = model._enum;
|
||||
p.allowableValues = model.allowableValues;
|
||||
p.collectionFormat = collectionFormat;
|
||||
p.paramName = toParamName(qp.getName());
|
||||
|
||||
if (model.complexType != null) {
|
||||
@ -1056,10 +1127,17 @@ public class DefaultCodegen {
|
||||
sec.keyParamName = apiKeyDefinition.getName();
|
||||
sec.isKeyInHeader = apiKeyDefinition.getIn() == In.HEADER;
|
||||
sec.isKeyInQuery = !sec.isKeyInHeader;
|
||||
} else if(schemeDefinition instanceof BasicAuthDefinition) {
|
||||
sec.isKeyInHeader = sec.isKeyInQuery = sec.isApiKey = sec.isOAuth = false;
|
||||
sec.isBasic = true;
|
||||
} else {
|
||||
sec.isKeyInHeader = sec.isKeyInQuery = sec.isApiKey = false;
|
||||
sec.isBasic = schemeDefinition instanceof BasicAuthDefinition;
|
||||
sec.isOAuth = !sec.isBasic;
|
||||
final OAuth2Definition oauth2Definition = (OAuth2Definition) schemeDefinition;
|
||||
sec.isKeyInHeader = sec.isKeyInQuery = sec.isApiKey = sec.isBasic = false;
|
||||
sec.isOAuth = true;
|
||||
sec.flow = oauth2Definition.getFlow();
|
||||
sec.authorizationUrl = oauth2Definition.getAuthorizationUrl();
|
||||
sec.tokenUrl = oauth2Definition.getTokenUrl();
|
||||
sec.scopes = oauth2Definition.getScopes().keySet();
|
||||
}
|
||||
|
||||
sec.hasMore = it.hasNext();
|
||||
@ -1146,7 +1224,9 @@ public class DefaultCodegen {
|
||||
if (mappedType != null) {
|
||||
addImport(m, mappedType);
|
||||
}
|
||||
} /**
|
||||
}
|
||||
|
||||
/**
|
||||
* Underscore the given word.
|
||||
*
|
||||
* @param word The word
|
||||
@ -1208,9 +1288,8 @@ public class DefaultCodegen {
|
||||
} else {
|
||||
m.emptyVars = true;
|
||||
}
|
||||
} public static String camelize(String word) {
|
||||
return camelize(word, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove characters not suitable for variable or method name from the input and camelize it
|
||||
@ -1231,7 +1310,13 @@ public class DefaultCodegen {
|
||||
name = name.substring(0, 1).toLowerCase() + name.substring(1);
|
||||
}
|
||||
return name;
|
||||
} public static String camelize(String word, boolean lowercaseFirstLetter) {
|
||||
}
|
||||
|
||||
public static String camelize(String word) {
|
||||
return camelize(word, false);
|
||||
}
|
||||
|
||||
public static String camelize(String word, boolean lowercaseFirstLetter) {
|
||||
// Replace all slashes with dots (package separator)
|
||||
Pattern p = Pattern.compile("\\/(.?)");
|
||||
Matcher m = p.matcher(word);
|
||||
@ -1294,6 +1379,14 @@ public class DefaultCodegen {
|
||||
}
|
||||
|
||||
public boolean shouldOverwrite(String filename) {
|
||||
return true;
|
||||
return !(skipOverwrite && new File(filename).exists());
|
||||
}
|
||||
|
||||
public boolean isSkipOverwrite() {
|
||||
return skipOverwrite;
|
||||
}
|
||||
|
||||
public void setSkipOverwrite(boolean skipOverwrite) {
|
||||
this.skipOverwrite = skipOverwrite;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package io.swagger.codegen;
|
||||
|
||||
import com.samskivert.mustache.Mustache;
|
||||
import com.samskivert.mustache.Template;
|
||||
|
||||
import io.swagger.models.ComposedModel;
|
||||
import io.swagger.models.Contact;
|
||||
import io.swagger.models.Info;
|
||||
import io.swagger.models.License;
|
||||
@ -9,9 +11,13 @@ import io.swagger.models.Model;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.auth.OAuth2Definition;
|
||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.util.Json;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -20,6 +26,8 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -56,6 +64,10 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
List<File> files = new ArrayList<File>();
|
||||
try {
|
||||
config.processOpts();
|
||||
|
||||
config.additionalProperties().put("generatedDate", DateTime.now().toString());
|
||||
config.additionalProperties().put("generatorClass", config.getClass().toString());
|
||||
|
||||
if (swagger.getInfo() != null) {
|
||||
Info info = swagger.getInfo();
|
||||
if (info.getTitle() != null) {
|
||||
@ -105,10 +117,8 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
if (swagger.getBasePath() != null) {
|
||||
hostBuilder.append(swagger.getBasePath());
|
||||
} else {
|
||||
hostBuilder.append("/");
|
||||
}
|
||||
String contextPath = swagger.getBasePath() == null ? "/" : swagger.getBasePath();
|
||||
String contextPath = swagger.getBasePath() == null ? "" : swagger.getBasePath();
|
||||
String basePath = hostBuilder.toString();
|
||||
|
||||
|
||||
@ -118,11 +128,13 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
// models
|
||||
Map<String, Model> definitions = swagger.getDefinitions();
|
||||
if (definitions != null) {
|
||||
for (String name : definitions.keySet()) {
|
||||
List<String> sortedModelKeys = sortModelsByInheritance(definitions);
|
||||
|
||||
for (String name : sortedModelKeys) {
|
||||
Model model = definitions.get(name);
|
||||
Map<String, Model> modelMap = new HashMap<String, Model>();
|
||||
modelMap.put(name, model);
|
||||
Map<String, Object> models = processModels(config, modelMap);
|
||||
Map<String, Object> models = processModels(config, modelMap, definitions);
|
||||
models.putAll(config.additionalProperties());
|
||||
|
||||
allModels.add(((List<Object>) models.get("models")).get(0));
|
||||
@ -130,6 +142,9 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
for (String templateName : config.modelTemplateFiles().keySet()) {
|
||||
String suffix = config.modelTemplateFiles().get(templateName);
|
||||
String filename = config.modelFileFolder() + File.separator + config.toModelFilename(name) + suffix;
|
||||
if (!config.shouldOverwrite(filename)) {
|
||||
continue;
|
||||
}
|
||||
String template = readTemplate(config.templateDir() + File.separator + templateName);
|
||||
Template tmpl = Mustache.compiler()
|
||||
.withLoader(new Mustache.TemplateLoader() {
|
||||
@ -178,7 +193,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
for (String templateName : config.apiTemplateFiles().keySet()) {
|
||||
|
||||
String filename = config.apiFilename(templateName, tag);
|
||||
if (new File(filename).exists() && !config.shouldOverwrite(filename)) {
|
||||
if (!config.shouldOverwrite(filename) && new File(filename).exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -218,7 +233,11 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
bundle.put("models", allModels);
|
||||
bundle.put("apiFolder", config.apiPackage().replace('.', File.separatorChar));
|
||||
bundle.put("modelPackage", config.modelPackage());
|
||||
bundle.put("authMethods", config.fromSecurity(swagger.getSecurityDefinitions()));
|
||||
List<CodegenSecurity> authMethods = config.fromSecurity(swagger.getSecurityDefinitions());
|
||||
if (authMethods != null && !authMethods.isEmpty()) {
|
||||
bundle.put("authMethods", authMethods);
|
||||
bundle.put("hasAuthMethods", true);
|
||||
}
|
||||
if (swagger.getExternalDocs() != null) {
|
||||
bundle.put("externalDocs", swagger.getExternalDocs());
|
||||
}
|
||||
@ -245,6 +264,9 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
of.mkdirs();
|
||||
}
|
||||
String outputFilename = outputFolder + File.separator + support.destinationFilename;
|
||||
if (!config.shouldOverwrite(outputFilename)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (support.templateFile.endsWith("mustache")) {
|
||||
String template = readTemplate(config.templateDir() + File.separator + support.templateFile);
|
||||
@ -316,17 +338,63 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> sortModelsByInheritance(final Map<String, Model> definitions) {
|
||||
List<String> sortedModelKeys = new ArrayList<String>(definitions.keySet());
|
||||
Comparator<String> cmp = new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
Model model1 = definitions.get(o1);
|
||||
Model model2 = definitions.get(o2);
|
||||
|
||||
int model1InheritanceDepth = getInheritanceDepth(model1);
|
||||
int model2InheritanceDepth = getInheritanceDepth(model2);
|
||||
|
||||
if (model1InheritanceDepth == model2InheritanceDepth) {
|
||||
return 0;
|
||||
} else if (model1InheritanceDepth > model2InheritanceDepth) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private int getInheritanceDepth(Model model) {
|
||||
int inheritanceDepth = 0;
|
||||
Model parent = getParent(model);
|
||||
|
||||
while (parent != null) {
|
||||
inheritanceDepth++;
|
||||
parent = getParent(parent);
|
||||
}
|
||||
|
||||
return inheritanceDepth;
|
||||
}
|
||||
|
||||
private Model getParent(Model model) {
|
||||
if (model instanceof ComposedModel) {
|
||||
return definitions.get(((ComposedModel) model).getParent().getReference());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
Collections.sort(sortedModelKeys, cmp);
|
||||
|
||||
return sortedModelKeys;
|
||||
}
|
||||
|
||||
public Map<String, List<CodegenOperation>> processPaths(Map<String, Path> paths) {
|
||||
Map<String, List<CodegenOperation>> ops = new HashMap<String, List<CodegenOperation>>();
|
||||
|
||||
for (String resourcePath : paths.keySet()) {
|
||||
Path path = paths.get(resourcePath);
|
||||
processOperation(resourcePath, "get", path.getGet(), ops);
|
||||
processOperation(resourcePath, "put", path.getPut(), ops);
|
||||
processOperation(resourcePath, "post", path.getPost(), ops);
|
||||
processOperation(resourcePath, "delete", path.getDelete(), ops);
|
||||
processOperation(resourcePath, "patch", path.getPatch(), ops);
|
||||
processOperation(resourcePath, "options", path.getOptions(), ops);
|
||||
processOperation(resourcePath, "get", path.getGet(), ops, path);
|
||||
processOperation(resourcePath, "put", path.getPut(), ops, path);
|
||||
processOperation(resourcePath, "post", path.getPost(), ops, path);
|
||||
processOperation(resourcePath, "delete", path.getDelete(), ops, path);
|
||||
processOperation(resourcePath, "patch", path.getPatch(), ops, path);
|
||||
processOperation(resourcePath, "options", path.getOptions(), ops, path);
|
||||
}
|
||||
return ops;
|
||||
}
|
||||
@ -339,14 +407,35 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
return map.get(name);
|
||||
}
|
||||
|
||||
|
||||
public void processOperation(String resourcePath, String httpMethod, Operation operation, Map<String, List<CodegenOperation>> operations) {
|
||||
public void processOperation(String resourcePath, String httpMethod, Operation operation, Map<String, List<CodegenOperation>> operations, Path path) {
|
||||
if (operation != null) {
|
||||
List<String> tags = operation.getTags();
|
||||
if (tags == null) {
|
||||
tags = new ArrayList<String>();
|
||||
tags.add("default");
|
||||
}
|
||||
|
||||
/*
|
||||
build up a set of parameter "ids" defined at the operation level
|
||||
per the swagger 2.0 spec "A unique parameter is defined by a combination of a name and location"
|
||||
i'm assuming "location" == "in"
|
||||
*/
|
||||
Set<String> operationParameters = new HashSet<String>();
|
||||
if (operation.getParameters() != null) {
|
||||
for (Parameter parameter : operation.getParameters()) {
|
||||
operationParameters.add(generateParameterId(parameter));
|
||||
}
|
||||
}
|
||||
|
||||
//need to propagate path level down to the operation
|
||||
if(path.getParameters() != null) {
|
||||
for (Parameter parameter : path.getParameters()) {
|
||||
//skip propagation if a parameter with the same name is already defined at the operation level
|
||||
if (!operationParameters.contains(generateParameterId(parameter))) {
|
||||
operation.addParameter(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String tag : tags) {
|
||||
CodegenOperation co = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions());
|
||||
@ -367,7 +456,22 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
String securityName = security.keySet().iterator().next();
|
||||
SecuritySchemeDefinition securityDefinition = fromSecurity(securityName);
|
||||
if (securityDefinition != null) {
|
||||
authMethods.put(securityName, securityDefinition);
|
||||
if(securityDefinition instanceof OAuth2Definition) {
|
||||
OAuth2Definition oauth2Definition = (OAuth2Definition) securityDefinition;
|
||||
OAuth2Definition oauth2Operation = new OAuth2Definition();
|
||||
oauth2Operation.setType(oauth2Definition.getType());
|
||||
oauth2Operation.setAuthorizationUrl(oauth2Definition.getAuthorizationUrl());
|
||||
oauth2Operation.setFlow(oauth2Definition.getFlow());
|
||||
oauth2Operation.setTokenUrl(oauth2Definition.getTokenUrl());
|
||||
for (String scope : security.values().iterator().next()) {
|
||||
if (oauth2Definition.getScopes().containsKey(scope)) {
|
||||
oauth2Operation.addScope(scope, oauth2Definition.getScopes().get(scope));
|
||||
}
|
||||
}
|
||||
authMethods.put(securityName, oauth2Operation);
|
||||
} else {
|
||||
authMethods.put(securityName, securityDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!authMethods.isEmpty()) {
|
||||
@ -377,6 +481,10 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
}
|
||||
|
||||
private String generateParameterId(Parameter parameter) {
|
||||
return parameter.getName() + ":" + parameter.getIn();
|
||||
}
|
||||
|
||||
protected String sanitizeTag(String tag) {
|
||||
// remove spaces and make strong case
|
||||
String[] parts = tag.split(" ");
|
||||
@ -393,6 +501,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
Map<String, Object> operations = new HashMap<String, Object>();
|
||||
Map<String, Object> objs = new HashMap<String, Object>();
|
||||
objs.put("classname", config.toApiName(tag));
|
||||
objs.put("pathPrefix", config.toApiVarName(tag));
|
||||
|
||||
// check for operationId uniqueness
|
||||
Set<String> opIds = new HashSet<String>();
|
||||
@ -430,6 +539,12 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
|
||||
operations.put("imports", imports);
|
||||
|
||||
// add a flag to indicate whether there's any {{import}}
|
||||
if (imports.size() > 0) {
|
||||
operations.put("hasImport", true);
|
||||
}
|
||||
|
||||
config.postProcessOperations(operations);
|
||||
if (objs.size() > 0) {
|
||||
List<CodegenOperation> os = (List<CodegenOperation>) objs.get("operation");
|
||||
@ -442,14 +557,14 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
return operations;
|
||||
}
|
||||
|
||||
public Map<String, Object> processModels(CodegenConfig config, Map<String, Model> definitions) {
|
||||
public Map<String, Object> processModels(CodegenConfig config, Map<String, Model> definitions, Map<String, Model> allDefinitions) {
|
||||
Map<String, Object> objs = new HashMap<String, Object>();
|
||||
objs.put("package", config.modelPackage());
|
||||
List<Object> models = new ArrayList<Object>();
|
||||
Set<String> allImports = new LinkedHashSet<String>();
|
||||
for (String key : definitions.keySet()) {
|
||||
Model mm = definitions.get(key);
|
||||
CodegenModel cm = config.fromModel(key, mm);
|
||||
CodegenModel cm = config.fromModel(key, mm, allDefinitions);
|
||||
Map<String, Object> mo = new HashMap<String, Object>();
|
||||
mo.put("model", cm);
|
||||
mo.put("importPath", config.toModelImport(key));
|
||||
|
@ -0,0 +1,144 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.properties.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public AbstractTypeScriptClientCodegen() {
|
||||
super();
|
||||
supportsInheritance = true;
|
||||
reservedWords = new HashSet<String>(Arrays.asList("abstract",
|
||||
"continue", "for", "new", "switch", "assert", "default", "if",
|
||||
"package", "synchronized", "do", "goto", "private",
|
||||
"this", "break", "double", "implements", "protected", "throw",
|
||||
"byte", "else", "import", "public", "throws", "case", "enum",
|
||||
"instanceof", "return", "transient", "catch", "extends", "int",
|
||||
"short", "try", "char", "final", "interface", "static", "void",
|
||||
"class", "finally", "const", "super", "while"));
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(Arrays.asList(
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float",
|
||||
"Object"));
|
||||
instantiationTypes.put("array", "Array");
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("Array", "Array");
|
||||
typeMapping.put("array", "Array");
|
||||
typeMapping.put("List", "Array");
|
||||
typeMapping.put("boolean", "boolean");
|
||||
typeMapping.put("string", "string");
|
||||
typeMapping.put("int", "number");
|
||||
typeMapping.put("float", "number");
|
||||
typeMapping.put("number", "number");
|
||||
typeMapping.put("long", "number");
|
||||
typeMapping.put("short", "number");
|
||||
typeMapping.put("char", "string");
|
||||
typeMapping.put("double", "number");
|
||||
typeMapping.put("object", "any");
|
||||
typeMapping.put("integer", "number");
|
||||
typeMapping.put("Map", "any");
|
||||
typeMapping.put("DateTime", "Date");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$"))
|
||||
return name;
|
||||
|
||||
// camelize the variable name
|
||||
// pet_id => PetId
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*"))
|
||||
name = escapeReservedWord(name);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name))
|
||||
throw new RuntimeException(name
|
||||
+ " (reserved word) cannot be used as a model name");
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// should be the same as the model name
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@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 "{ [key: string]: "+ getTypeDeclaration(inner) + "; }";
|
||||
} else if (p instanceof FileProperty) {
|
||||
return "any";
|
||||
}
|
||||
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 type;
|
||||
} else
|
||||
type = swaggerType;
|
||||
return type;
|
||||
}
|
||||
}
|
@ -251,6 +251,11 @@ public class AkkaScalaClientCodegen extends DefaultCodegen implements CodegenCon
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
return super.toOperationId(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, operationId));
|
||||
}
|
||||
|
||||
@ -396,4 +401,4 @@ public class AkkaScalaClientCodegen extends DefaultCodegen implements CodegenCon
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
protected String groupId = "io.swagger";
|
||||
@ -168,6 +170,11 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
@ -232,6 +239,8 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "JsonUtil.java"));
|
||||
supportingFiles.add(new SupportingFile("apiException.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ApiException.java"));
|
||||
supportingFiles.add(new SupportingFile("Pair.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "Pair.java"));
|
||||
}
|
||||
|
||||
public Boolean getUseAndroidMavenGradlePlugin() {
|
||||
|
@ -21,6 +21,8 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class AsyncScalaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
protected String groupId = "io.swagger";
|
||||
@ -204,4 +206,4 @@ public class AsyncScalaClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,22 +7,24 @@ import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.codegen.CliOption;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "IO.Swagger.Client";
|
||||
protected String groupId = "io.swagger";
|
||||
protected String artifactId = "swagger-csharp-client";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String sourceFolder = "src/main/csharp";
|
||||
protected String packageName = "IO.Swagger";
|
||||
protected String packageVersion = "1.0.0";
|
||||
protected String clientPackage = "IO.Swagger.Client";
|
||||
protected String sourceFolder = "src" + File.separator + "main" + File.separator + "csharp";
|
||||
|
||||
public CSharpClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/csharp";
|
||||
outputFolder = "generated-code" + File.separator + "csharp";
|
||||
modelTemplateFiles.put("model.mustache", ".cs");
|
||||
apiTemplateFiles.put("api.mustache", ".cs");
|
||||
templateDir = "csharp";
|
||||
@ -34,20 +36,10 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if", "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while")
|
||||
);
|
||||
|
||||
additionalProperties.put("invokerPackage", invokerPackage);
|
||||
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "Configuration.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ApiClient.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ApiException.cs"));
|
||||
supportingFiles.add(new SupportingFile("Newtonsoft.Json.dll", "bin", "Newtonsoft.Json.dll"));
|
||||
supportingFiles.add(new SupportingFile("RestSharp.dll", "bin", "RestSharp.dll"));
|
||||
supportingFiles.add(new SupportingFile("compile.mustache", "", "compile.bat"));
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"String",
|
||||
"string",
|
||||
"bool?",
|
||||
"double?",
|
||||
@ -64,6 +56,7 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float",
|
||||
"Stream", // not really a primitive, we include it to avoid model import
|
||||
"Object")
|
||||
);
|
||||
instantiationTypes.put("array", "List");
|
||||
@ -79,12 +72,50 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
typeMapping.put("number", "double?");
|
||||
typeMapping.put("datetime", "DateTime?");
|
||||
typeMapping.put("date", "DateTime?");
|
||||
typeMapping.put("file", "string"); // path to file
|
||||
typeMapping.put("file", "Stream");
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("list", "List");
|
||||
typeMapping.put("map", "Dictionary");
|
||||
typeMapping.put("object", "Object");
|
||||
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption("packageName", "C# package name (convention: Camel.Case), default: IO.Swagger"));
|
||||
cliOptions.add(new CliOption("packageVersion", "C# package version, default: 1.0.0"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey("packageVersion")) {
|
||||
packageVersion = (String) additionalProperties.get("packageVersion");
|
||||
} else {
|
||||
additionalProperties.put("packageVersion", packageVersion);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("packageName")) {
|
||||
packageName = (String) additionalProperties.get("packageName");
|
||||
apiPackage = packageName + ".Api";
|
||||
modelPackage = packageName + ".Model";
|
||||
clientPackage = packageName + ".Client";
|
||||
} else {
|
||||
additionalProperties.put("packageName", packageName);
|
||||
}
|
||||
|
||||
additionalProperties.put("clientPackage", clientPackage);
|
||||
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache",
|
||||
(sourceFolder + File.separator + clientPackage).replace(".", java.io.File.separator), "Configuration.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache",
|
||||
(sourceFolder + File.separator + clientPackage).replace(".", java.io.File.separator), "ApiClient.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache",
|
||||
(sourceFolder + File.separator + clientPackage).replace(".", java.io.File.separator), "ApiException.cs"));
|
||||
supportingFiles.add(new SupportingFile("Newtonsoft.Json.dll", "bin", "Newtonsoft.Json.dll"));
|
||||
supportingFiles.add(new SupportingFile("RestSharp.dll", "bin", "RestSharp.dll"));
|
||||
supportingFiles.add(new SupportingFile("compile.mustache", "", "compile.bat"));
|
||||
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
|
||||
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
@ -106,11 +137,11 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return (outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', '/')).replace('.', File.separatorChar);
|
||||
return (outputFolder + File.separator + sourceFolder + File.separator + apiPackage()).replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return (outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', '/')).replace('.', File.separatorChar);
|
||||
return (outputFolder + File.separator + sourceFolder + File.separator + modelPackage()).replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -137,8 +168,24 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
return name;
|
||||
}
|
||||
|
||||
// camelize(lower) the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -192,6 +239,11 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
|
@ -0,0 +1,255 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.codegen.CliOption;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String packageName = "IO.Swagger";
|
||||
protected String packageVersion = "1.0.0";
|
||||
protected String clientPackage = "IO.Swagger.Client";
|
||||
protected String sourceFolder = "src" + File.separator + "main" + File.separator + "CsharpDotNet2";
|
||||
|
||||
public CsharpDotNet2ClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code" + File.separator + "CsharpDotNet2";
|
||||
modelTemplateFiles.put("model.mustache", ".cs");
|
||||
apiTemplateFiles.put("api.mustache", ".cs");
|
||||
templateDir = "CsharpDotNet2";
|
||||
apiPackage = "IO.Swagger.Api";
|
||||
modelPackage = "IO.Swagger.Model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if", "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while")
|
||||
);
|
||||
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"String",
|
||||
"string",
|
||||
"bool?",
|
||||
"double?",
|
||||
"int?",
|
||||
"long?",
|
||||
"float?",
|
||||
"byte[]",
|
||||
"List",
|
||||
"Dictionary",
|
||||
"DateTime?",
|
||||
"String",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float",
|
||||
"Stream", // not really a primitive, we include it to avoid model import
|
||||
"Object")
|
||||
);
|
||||
instantiationTypes.put("array", "List");
|
||||
instantiationTypes.put("map", "Dictionary");
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("string", "string");
|
||||
typeMapping.put("boolean", "bool?");
|
||||
typeMapping.put("integer", "int?");
|
||||
typeMapping.put("float", "float?");
|
||||
typeMapping.put("long", "long?");
|
||||
typeMapping.put("double", "double?");
|
||||
typeMapping.put("number", "double?");
|
||||
typeMapping.put("datetime", "DateTime?");
|
||||
typeMapping.put("date", "DateTime?");
|
||||
typeMapping.put("file", "Stream");
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("list", "List");
|
||||
typeMapping.put("map", "Dictionary");
|
||||
typeMapping.put("object", "Object");
|
||||
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption("packageName", "C# package name (convention: Camel.Case), default: IO.Swagger"));
|
||||
cliOptions.add(new CliOption("packageVersion", "C# package version, default: 1.0.0"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey("packageVersion")) {
|
||||
packageVersion = (String) additionalProperties.get("packageVersion");
|
||||
} else {
|
||||
additionalProperties.put("packageVersion", packageVersion);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("packageName")) {
|
||||
packageName = (String) additionalProperties.get("packageName");
|
||||
apiPackage = packageName + ".Api";
|
||||
modelPackage = packageName + ".Model";
|
||||
clientPackage = packageName + ".Client";
|
||||
} else {
|
||||
additionalProperties.put("packageName", packageName);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("clientPackage")) {
|
||||
this.setClientPackage((String) additionalProperties.get("clientPackage"));
|
||||
} else {
|
||||
additionalProperties.put("clientPackage", clientPackage);
|
||||
}
|
||||
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache",
|
||||
(sourceFolder + File.separator + clientPackage).replace(".", java.io.File.separator), "Configuration.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache",
|
||||
(sourceFolder + File.separator + clientPackage).replace(".", java.io.File.separator), "ApiClient.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache",
|
||||
(sourceFolder + File.separator + clientPackage).replace(".", java.io.File.separator), "ApiException.cs"));
|
||||
supportingFiles.add(new SupportingFile("packages.config.mustache", "vendor", "packages.config"));
|
||||
supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "compile-mono.sh"));
|
||||
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
|
||||
|
||||
}
|
||||
|
||||
public void setClientPackage(String clientPackage) {
|
||||
this.clientPackage = clientPackage;
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "CsharpDotNet2";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a C# .Net 2.0 client library.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return (outputFolder + File.separator + sourceFolder + File.separator + apiPackage()).replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return (outputFolder + File.separator + sourceFolder + File.separator + modelPackage()).replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
return name;
|
||||
}
|
||||
|
||||
// camelize the variable name
|
||||
// pet_id => PetId
|
||||
name = camelize(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
return name;
|
||||
}
|
||||
|
||||
// camelize(lower) the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// should be the same as the model name
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
|
||||
@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.toLowerCase())) {
|
||||
type = typeMapping.get(swaggerType.toLowerCase());
|
||||
if (languageSpecificPrimitives.contains(type)) {
|
||||
return type;
|
||||
}
|
||||
} else {
|
||||
type = swaggerType;
|
||||
}
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
return camelize(operationId);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,367 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.AbstractNumericProperty;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.BooleanProperty;
|
||||
import io.swagger.models.properties.DateProperty;
|
||||
import io.swagger.models.properties.DateTimeProperty;
|
||||
import io.swagger.models.properties.DecimalProperty;
|
||||
import io.swagger.models.properties.DoubleProperty;
|
||||
import io.swagger.models.properties.FloatProperty;
|
||||
import io.swagger.models.properties.IntegerProperty;
|
||||
import io.swagger.models.properties.LongProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.PropertyBuilder;
|
||||
import io.swagger.models.properties.RefProperty;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String packageName = "io.swagger";
|
||||
protected String packageVersion = null;
|
||||
|
||||
protected String invokerPackage = "io.swagger";
|
||||
protected String sourceFolder = "src/main/flex";
|
||||
|
||||
public FlashClientCodegen() {
|
||||
super();
|
||||
|
||||
modelPackage = "io.swagger.client.model";
|
||||
apiPackage = "io.swagger.client.api";
|
||||
outputFolder = "generated-code" + File.separatorChar + "flash";
|
||||
modelTemplateFiles.put("model.mustache", ".as");
|
||||
modelTemplateFiles.put("modelList.mustache", "List.as");
|
||||
apiTemplateFiles.put("api.mustache", ".as");
|
||||
templateDir = "flash";
|
||||
|
||||
languageSpecificPrimitives.clear();
|
||||
languageSpecificPrimitives.add("Number");
|
||||
languageSpecificPrimitives.add("Boolean");
|
||||
languageSpecificPrimitives.add("String");
|
||||
languageSpecificPrimitives.add("Date");
|
||||
languageSpecificPrimitives.add("Array");
|
||||
languageSpecificPrimitives.add("Dictionary");
|
||||
|
||||
typeMapping.clear();
|
||||
typeMapping.put("integer", "Number");
|
||||
typeMapping.put("float", "Number");
|
||||
typeMapping.put("long", "Number");
|
||||
typeMapping.put("double", "Number");
|
||||
typeMapping.put("array", "Array");
|
||||
typeMapping.put("map", "Dictionary");
|
||||
typeMapping.put("boolean", "Boolean");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("date", "Date");
|
||||
typeMapping.put("DateTime", "Date");
|
||||
typeMapping.put("object", "Object");
|
||||
typeMapping.put("file", "File");
|
||||
|
||||
importMapping = new HashMap<String, String>();
|
||||
importMapping.put("File", "flash.filesystem.File");
|
||||
|
||||
// from
|
||||
reservedWords = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"add", "for", "lt", "tellTarget", "and", "function", "ne", "this", "break", "ge", "new", "typeof", "continue", "gt", "not", "var", "delete", "if", "on", "void", "do", "ifFrameLoaded", "onClipEvent", "while", "else", "in", "or", "with", "eq", "le", "return"));
|
||||
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption("packageName", "flash package name (convention: package.name), default: io.swagger"));
|
||||
cliOptions.add(new CliOption("packageVersion", "flash package version, default: 1.0.0"));
|
||||
cliOptions.add(new CliOption("invokerPackage", "root package for generated code"));
|
||||
cliOptions.add(new CliOption("sourceFolder", "source folder for generated code. e.g. src/main/flex"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey("invokerPackage")) {
|
||||
this.setInvokerPackage((String) additionalProperties.get("invokerPackage"));
|
||||
} else {
|
||||
//not set, use default to be passed to template
|
||||
additionalProperties.put("invokerPackage", invokerPackage);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("sourceFolder")) {
|
||||
this.setSourceFolder((String) additionalProperties.get("sourceFolder"));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("packageName")) {
|
||||
setPackageName((String) additionalProperties.get("packageName"));
|
||||
apiPackage = packageName + ".client.api";
|
||||
modelPackage = packageName + ".client.model";
|
||||
}
|
||||
else {
|
||||
setPackageName("io.swagger");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("packageVersion")) {
|
||||
setPackageVersion((String) additionalProperties.get("packageVersion"));
|
||||
}
|
||||
else {
|
||||
setPackageVersion("1.0.0");
|
||||
}
|
||||
|
||||
additionalProperties.put("packageName", packageName);
|
||||
additionalProperties.put("packageVersion", packageVersion);
|
||||
|
||||
//modelPackage = invokerPackage + File.separatorChar + "client" + File.separatorChar + "model";
|
||||
//apiPackage = invokerPackage + File.separatorChar + "client" + File.separatorChar + "api";
|
||||
|
||||
final String invokerFolder = (sourceFolder + File.separator + invokerPackage + File.separator + "swagger" + File.separator).replace(".", File.separator).replace('.', File.separatorChar);
|
||||
|
||||
supportingFiles.add(new SupportingFile("ApiInvoker.as", invokerFolder + "common", "ApiInvoker.as"));
|
||||
supportingFiles.add(new SupportingFile("ApiUrlHelper.as", invokerFolder + "common", "ApiUrlHelper.as"));
|
||||
supportingFiles.add(new SupportingFile("ApiUserCredentials.as", invokerFolder + "common", "ApiUserCredentials.as"));
|
||||
supportingFiles.add(new SupportingFile("ListWrapper.as", invokerFolder + "common", "ListWrapper.as"));
|
||||
supportingFiles.add(new SupportingFile("SwaggerApi.as", invokerFolder + "common", "SwaggerApi.as"));
|
||||
supportingFiles.add(new SupportingFile("XMLWriter.as", invokerFolder + "common", "XMLWriter.as"));
|
||||
supportingFiles.add(new SupportingFile("ApiError.as", invokerFolder + "exception", "ApiErrors.as"));
|
||||
supportingFiles.add(new SupportingFile("ApiErrorCodes.as", invokerFolder + "exception", "ApiErrorCodes.as"));
|
||||
supportingFiles.add(new SupportingFile("ApiClientEvent.as", invokerFolder + "event", "ApiClientEvent.as"));
|
||||
supportingFiles.add(new SupportingFile("Response.as", invokerFolder + "event", "Response.as"));
|
||||
supportingFiles.add(new SupportingFile("build.properties", sourceFolder, "build.properties"));
|
||||
supportingFiles.add(new SupportingFile("build.xml", sourceFolder, "build.xml"));
|
||||
supportingFiles.add(new SupportingFile("AirExecutorApp-app.xml", sourceFolder + File.separatorChar + "bin", "AirExecutorApp-app.xml"));
|
||||
supportingFiles.add(new SupportingFile("ASAXB-0.1.1.swc", sourceFolder + File.separatorChar + "lib", "ASAXB-0.1.1.swc"));
|
||||
supportingFiles.add(new SupportingFile("as3corelib.swc", sourceFolder + File.separatorChar + "lib", "as3corelib.swc"));
|
||||
supportingFiles.add(new SupportingFile("flexunit-4.1.0_RC2-28-flex_3.5.0.12683.swc", sourceFolder + File.separator + "lib" + File.separator + "ext", "flexunit-4.1.0_RC2-28-flex_3.5.0.12683.swc"));
|
||||
supportingFiles.add(new SupportingFile("flexunit-aircilistener-4.1.0_RC2-28-3.5.0.12683.swc", sourceFolder + File.separator + "lib" + File.separator + "ext", "flexunit-aircilistener-4.1.0_RC2-28-3.5.0.12683.swc"));
|
||||
supportingFiles.add(new SupportingFile("flexunit-cilistener-4.1.0_RC2-28-3.5.0.12683.swc", sourceFolder + File.separator + "lib" + File.separator + "ext", "flexunit-cilistener-4.1.0_RC2-28-3.5.0.12683.swc"));
|
||||
supportingFiles.add(new SupportingFile("flexunit-core-flex-4.0.0.2-sdk3.5.0.12683.swc", sourceFolder + File.separator + "lib" + File.separator + "ext", "flexunit-core-flex-4.0.0.2-sdk3.5.0.12683.swc"));
|
||||
}
|
||||
|
||||
private static String dropDots(String str) {
|
||||
return str.replaceAll("\\.", "_");
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "flash";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a Flash client library.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return name + "_";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return (outputFolder + File.separatorChar + sourceFolder + File.separatorChar + apiPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return (outputFolder + File.separatorChar + sourceFolder + File.separatorChar + modelPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
Property inner = ap.getItems();
|
||||
return getSwaggerType(p);
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
||||
return getSwaggerType(p);
|
||||
}
|
||||
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 type;
|
||||
}
|
||||
} else {
|
||||
type = toModelName(swaggerType);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof StringProperty) {
|
||||
return "null";
|
||||
} else if (p instanceof BooleanProperty) {
|
||||
return "false";
|
||||
} else if (p instanceof DateProperty) {
|
||||
return "null";
|
||||
} else if (p instanceof DateTimeProperty) {
|
||||
return "null";
|
||||
} else if (p instanceof DoubleProperty) {
|
||||
DoubleProperty dp = (DoubleProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
return "0.0";
|
||||
} else if (p instanceof FloatProperty) {
|
||||
FloatProperty dp = (FloatProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
return "0.0";
|
||||
} else if (p instanceof IntegerProperty) {
|
||||
IntegerProperty dp = (IntegerProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
return "0";
|
||||
} else if (p instanceof LongProperty) {
|
||||
LongProperty dp = (LongProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
return "0";
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return "new Dictionary()";
|
||||
} else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return "new Array()";
|
||||
} else {
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
|
||||
// underscore the variable name
|
||||
// petId => pet_id
|
||||
name = camelize(dropDots(name), true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
// underscore the model file name
|
||||
// PhoneNumber => phone_number
|
||||
return camelize(dropDots(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
// e.g. PhoneNumberApi.rb => phone_number_api.rb
|
||||
return camelize(name) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
// e.g. phone_number_api => PhoneNumberApi
|
||||
return camelize(name) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiVarName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
return camelize(name) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
return underscore(operationId);
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public void setPackageVersion(String packageVersion) {
|
||||
this.packageVersion = packageVersion;
|
||||
}
|
||||
|
||||
public void setInvokerPackage(String invokerPackage) {
|
||||
this.invokerPackage = invokerPackage;
|
||||
}
|
||||
|
||||
public void setSourceFolder(String sourceFolder) {
|
||||
this.sourceFolder = sourceFolder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,32 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.ComposedModel;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.ModelImpl;
|
||||
import io.swagger.models.RefModel;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
@ -19,7 +34,9 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String artifactId = "swagger-java-client";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String sourceFolder = "src/main/java";
|
||||
|
||||
protected String localVariablePrefix = "";
|
||||
protected Boolean serializableModel = false;
|
||||
|
||||
public JavaClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/java";
|
||||
@ -59,6 +76,8 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
cliOptions.add(new CliOption("artifactId", "artifactId in generated pom.xml"));
|
||||
cliOptions.add(new CliOption("artifactVersion", "artifact version in generated pom.xml"));
|
||||
cliOptions.add(new CliOption("sourceFolder", "source folder for generated code"));
|
||||
cliOptions.add(new CliOption("localVariablePrefix", "prefix for generated code members and local variables"));
|
||||
cliOptions.add(new CliOption("serializableModel", "boolean - toggle \"implements Serializable\" for generated models"));
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
@ -76,7 +95,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
|
||||
if (additionalProperties.containsKey("invokerPackage")) {
|
||||
this.setInvokerPackage((String) additionalProperties.get("invokerPackage"));
|
||||
} else {
|
||||
@ -109,6 +128,19 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
this.setSourceFolder((String) additionalProperties.get("sourceFolder"));
|
||||
}
|
||||
|
||||
|
||||
if (additionalProperties.containsKey("localVariablePrefix")) {
|
||||
this.setLocalVariablePrefix((String) additionalProperties.get("localVariablePrefix"));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("serializableModel")) {
|
||||
this.setSerializableModel(Boolean.valueOf((String)additionalProperties.get("serializableModel")));
|
||||
} else {
|
||||
additionalProperties.put("serializableModel", serializableModel);
|
||||
}
|
||||
|
||||
this.sanitizeConfig();
|
||||
|
||||
final String invokerFolder = (sourceFolder + File.separator + invokerPackage).replace(".", File.separator);
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", invokerFolder, "ApiClient.java"));
|
||||
@ -116,6 +148,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache", invokerFolder, "Configuration.java"));
|
||||
supportingFiles.add(new SupportingFile("JsonUtil.mustache", invokerFolder, "JsonUtil.java"));
|
||||
supportingFiles.add(new SupportingFile("StringUtil.mustache", invokerFolder, "StringUtil.java"));
|
||||
supportingFiles.add(new SupportingFile("Pair.mustache", invokerFolder, "Pair.java"));
|
||||
|
||||
final String authFolder = (sourceFolder + File.separator + invokerPackage + ".auth").replace(".", File.separator);
|
||||
supportingFiles.add(new SupportingFile("auth/Authentication.mustache", authFolder, "Authentication.java"));
|
||||
@ -124,7 +157,26 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
|
||||
}
|
||||
|
||||
|
||||
private void sanitizeConfig() {
|
||||
// Sanitize any config options here. We also have to update the additionalProperties because
|
||||
// the whole additionalProperties object is injected into the main object passed to the mustache layer
|
||||
|
||||
this.setApiPackage(sanitizePackageName(apiPackage));
|
||||
if (additionalProperties.containsKey("apiPackage")) {
|
||||
this.additionalProperties.put("apiPackage", apiPackage);
|
||||
}
|
||||
|
||||
this.setModelPackage(sanitizePackageName(modelPackage));
|
||||
if (additionalProperties.containsKey("modelPackage")) {
|
||||
this.additionalProperties.put("modelPackage", modelPackage);
|
||||
}
|
||||
|
||||
this.setInvokerPackage(sanitizePackageName(invokerPackage));
|
||||
if (additionalProperties.containsKey("invokerPackage")) {
|
||||
this.additionalProperties.put("invokerPackage", invokerPackage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
@ -204,6 +256,18 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
final ArrayProperty ap = (ArrayProperty) p;
|
||||
return String.format("new ArrayList<%s>()", getTypeDeclaration(ap.getItems()));
|
||||
} else if (p instanceof MapProperty) {
|
||||
final MapProperty ap = (MapProperty) p;
|
||||
return String.format("new HashMap<String, %s>()", getTypeDeclaration(ap.getAdditionalProperties()));
|
||||
}
|
||||
return super.toDefaultValue(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSwaggerType(Property p) {
|
||||
String swaggerType = super.getSwaggerType(p);
|
||||
@ -221,6 +285,11 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
@ -229,6 +298,57 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return camelize(operationId, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions) {
|
||||
CodegenModel codegenModel = super.fromModel(name, model, allDefinitions);
|
||||
|
||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null && codegenModel.hasEnums) {
|
||||
final Model parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
||||
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
|
||||
codegenModel = this.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
||||
}
|
||||
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
private CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {
|
||||
// This generator uses inline classes to define enums, which breaks when
|
||||
// dealing with models that have subTypes. To clean this up, we will analyze
|
||||
// the parent and child models, look for enums that match, and remove
|
||||
// them from the child models and leave them in the parent.
|
||||
// Because the child models extend the parents, the enums will be available via the parent.
|
||||
|
||||
// Only bother with reconciliation if the parent model has enums.
|
||||
if (parentCodegenModel.hasEnums) {
|
||||
|
||||
// Get the properties for the parent and child models
|
||||
final List<CodegenProperty> parentModelCodegenProperties = parentCodegenModel.vars;
|
||||
List<CodegenProperty> codegenProperties = codegenModel.vars;
|
||||
|
||||
// Iterate over all of the parent model properties
|
||||
for (CodegenProperty parentModelCodegenPropery : parentModelCodegenProperties) {
|
||||
// Look for enums
|
||||
if (parentModelCodegenPropery.isEnum) {
|
||||
// Now that we have found an enum in the parent class,
|
||||
// and search the child class for the same enum.
|
||||
Iterator<CodegenProperty> iterator = codegenProperties.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
CodegenProperty codegenProperty = iterator.next();
|
||||
if (codegenProperty.isEnum && codegenProperty.equals(parentModelCodegenPropery)) {
|
||||
// We found an enum in the child class that is
|
||||
// a duplicate of the one in the parent, so remove it.
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
codegenModel.vars = codegenProperties;
|
||||
}
|
||||
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
public void setInvokerPackage(String invokerPackage) {
|
||||
this.invokerPackage = invokerPackage;
|
||||
}
|
||||
@ -248,4 +368,26 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void setSourceFolder(String sourceFolder) {
|
||||
this.sourceFolder = sourceFolder;
|
||||
}
|
||||
|
||||
public void setLocalVariablePrefix(String localVariablePrefix) {
|
||||
this.localVariablePrefix = localVariablePrefix;
|
||||
}
|
||||
|
||||
public Boolean getSerializableModel() {
|
||||
return serializableModel;
|
||||
}
|
||||
|
||||
public void setSerializableModel(Boolean serializableModel) {
|
||||
this.serializableModel = serializableModel;
|
||||
}
|
||||
|
||||
private String sanitizePackageName(String packageName) {
|
||||
packageName = packageName.trim();
|
||||
packageName = packageName.replaceAll("[^a-zA-Z0-9_\\.]", "_");
|
||||
if(Strings.isNullOrEmpty(packageName)) {
|
||||
return "invalidPackageName";
|
||||
}
|
||||
return packageName;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,188 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.util.Json;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class JavaInflectorServerCodegen extends JavaClientCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "io.swagger.handler";
|
||||
protected String groupId = "io.swagger";
|
||||
protected String artifactId = "swagger-inflector-server";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String title = "Swagger Inflector";
|
||||
|
||||
public JavaInflectorServerCodegen() {
|
||||
super();
|
||||
|
||||
sourceFolder = "src/main/java";
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
templateDir = "JavaInflector";
|
||||
|
||||
apiPackage = System.getProperty("swagger.codegen.inflector.apipackage", "io.swagger.handler");
|
||||
modelPackage = System.getProperty("swagger.codegen.inflector.modelpackage", "io.swagger.model");
|
||||
|
||||
additionalProperties.put("invokerPackage", invokerPackage);
|
||||
additionalProperties.put("groupId", groupId);
|
||||
additionalProperties.put("artifactId", artifactId);
|
||||
additionalProperties.put("artifactVersion", artifactVersion);
|
||||
additionalProperties.put("title", title);
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float")
|
||||
);
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "inflector";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a Java Inflector Server application.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
supportingFiles.clear();
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("web.mustache", "src/main/webapp/WEB-INF", "web.xml"));
|
||||
supportingFiles.add(new SupportingFile("inflector.mustache", "", "inflector.yaml"));
|
||||
}
|
||||
|
||||
@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 getTypeDeclaration(inner);
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||
String basePath = resourcePath;
|
||||
if (basePath.startsWith("/")) {
|
||||
basePath = basePath.substring(1);
|
||||
}
|
||||
int pos = basePath.indexOf("/");
|
||||
if (pos > 0) {
|
||||
basePath = basePath.substring(0, pos);
|
||||
}
|
||||
|
||||
if (basePath == "") {
|
||||
basePath = "default";
|
||||
} else {
|
||||
if (co.path.startsWith("/" + basePath)) {
|
||||
co.path = co.path.substring(("/" + basePath).length());
|
||||
}
|
||||
co.subresourceOperation = !co.path.isEmpty();
|
||||
}
|
||||
List<CodegenOperation> opList = operations.get(basePath);
|
||||
if (opList == null) {
|
||||
opList = new ArrayList<CodegenOperation>();
|
||||
operations.put(basePath, opList);
|
||||
}
|
||||
opList.add(co);
|
||||
co.baseName = basePath;
|
||||
}
|
||||
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
if (operations != null) {
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
for (CodegenOperation operation : ops) {
|
||||
if (operation.returnType == null) {
|
||||
operation.returnType = "Void";
|
||||
} else if (operation.returnType.startsWith("List")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
operation.returnType = rt.substring("List<".length(), end);
|
||||
operation.returnContainer = "List";
|
||||
}
|
||||
} else if (operation.returnType.startsWith("Map")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
operation.returnType = rt.substring("Map<".length(), end);
|
||||
operation.returnContainer = "Map";
|
||||
}
|
||||
} else if (operation.returnType.startsWith("Set")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
operation.returnType = rt.substring("Set<".length(), end);
|
||||
operation.returnContainer = "Set";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processSwagger(Swagger swagger) {
|
||||
super.processSwagger(swagger);
|
||||
|
||||
try {
|
||||
File file = new File( outputFolder + "/src/main/swagger/swagger.json" );
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
FileWriter swaggerFile = new FileWriter(file);
|
||||
swaggerFile.write( Json.pretty( swagger ));
|
||||
swaggerFile.flush();
|
||||
swaggerFile.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultController";
|
||||
}
|
||||
name = name.replaceAll("[^a-zA-Z0-9]+", "_");
|
||||
return camelize(name)+ "Controller";
|
||||
}
|
||||
|
||||
public boolean shouldOverwrite(String filename) {
|
||||
return super.shouldOverwrite(filename);
|
||||
}
|
||||
}
|
@ -89,21 +89,6 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
|
||||
}
|
||||
|
||||
@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 getTypeDeclaration(inner);
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||
String basePath = resourcePath;
|
||||
@ -166,6 +151,15 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
name = name.replaceAll("[^a-zA-Z0-9]+", "_");
|
||||
return camelize(name) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
|
||||
@ -200,7 +194,6 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
}
|
||||
|
||||
public boolean shouldOverwrite(String filename) {
|
||||
|
||||
return !filename.endsWith("ServiceImpl.java") && !filename.endsWith("ServiceFactory.java");
|
||||
return super.shouldOverwrite(filename) && !filename.endsWith("ServiceImpl.java") && !filename.endsWith("ServiceFactory.java");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,11 +9,19 @@ import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String apiVersion = "1.0.0";
|
||||
@ -197,4 +205,50 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> getOperations(Map<String, Object> objs) {
|
||||
Map<String, Object> apiInfo = (Map<String, Object>) objs.get("apiInfo");
|
||||
List<Map<String, Object>> apis = (List<Map<String, Object>>) apiInfo.get("apis");
|
||||
Map<String, Object> api = apis.get(0);
|
||||
return (Map<String, Object>) api.get("operations");
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> sortOperationsByPath(List<CodegenOperation> ops) {
|
||||
Multimap<String, CodegenOperation> opsByPath = ArrayListMultimap.create();
|
||||
|
||||
for (CodegenOperation op : ops) {
|
||||
opsByPath.put(op.path, op);
|
||||
}
|
||||
|
||||
List<Map<String, Object>> opsByPathList = new ArrayList<Map<String, Object>>();
|
||||
for (Entry<String, Collection<CodegenOperation>> entry : opsByPath.asMap().entrySet()) {
|
||||
Map<String, Object> opsByPathEntry = new HashMap<String, Object>();
|
||||
opsByPathList.add(opsByPathEntry);
|
||||
opsByPathEntry.put("path", entry.getKey());
|
||||
opsByPathEntry.put("operation", entry.getValue());
|
||||
List<CodegenOperation> operationsForThisPath = Lists.newArrayList(entry.getValue());
|
||||
operationsForThisPath.get(operationsForThisPath.size() - 1).hasMore = null;
|
||||
if (opsByPathList.size() < opsByPath.asMap().size()) {
|
||||
opsByPathEntry.put("hasMore", "true");
|
||||
}
|
||||
}
|
||||
|
||||
return opsByPathList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
Map<String, Object> operations = getOperations(objs);
|
||||
|
||||
if (operations != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
|
||||
List<Map<String, Object>> opsByPathList = sortOperationsByPath(ops);
|
||||
operations.put("operationsByPath", opsByPathList);
|
||||
}
|
||||
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
}
|
||||
}
|
@ -16,45 +16,64 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected Set<String> foundationClasses = new HashSet<String>();
|
||||
protected String sourceFolder = "client";
|
||||
protected String podName = "SwaggerClient";
|
||||
protected String podVersion = "1.0.0";
|
||||
protected String classPrefix = "SWG";
|
||||
protected String projectName = "SwaggerClient";
|
||||
|
||||
public ObjcClientCodegen() {
|
||||
super();
|
||||
|
||||
outputFolder = "generated-code" + File.separator + "objc";
|
||||
modelTemplateFiles.put("model-header.mustache", ".h");
|
||||
modelTemplateFiles.put("model-body.mustache", ".m");
|
||||
apiTemplateFiles.put("api-header.mustache", ".h");
|
||||
apiTemplateFiles.put("api-body.mustache", ".m");
|
||||
templateDir = "objc";
|
||||
modelPackage = "";
|
||||
|
||||
defaultIncludes = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"bool",
|
||||
"BOOL",
|
||||
"int",
|
||||
"NSString",
|
||||
"NSObject",
|
||||
"NSArray",
|
||||
"NSNumber",
|
||||
"NSDate",
|
||||
"NSDictionary",
|
||||
"NSMutableArray",
|
||||
"NSMutableDictionary")
|
||||
);
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"NSNumber",
|
||||
"NSString",
|
||||
"NSObject",
|
||||
"NSDate",
|
||||
"bool",
|
||||
"BOOL")
|
||||
);
|
||||
defaultIncludes.clear();
|
||||
defaultIncludes.add("bool");
|
||||
defaultIncludes.add("BOOL");
|
||||
defaultIncludes.add("int");
|
||||
defaultIncludes.add("NSURL");
|
||||
defaultIncludes.add("NSString");
|
||||
defaultIncludes.add("NSObject");
|
||||
defaultIncludes.add("NSArray");
|
||||
defaultIncludes.add("NSNumber");
|
||||
defaultIncludes.add("NSDate");
|
||||
defaultIncludes.add("NSDictionary");
|
||||
defaultIncludes.add("NSMutableArray");
|
||||
defaultIncludes.add("NSMutableDictionary");
|
||||
|
||||
languageSpecificPrimitives.clear();
|
||||
languageSpecificPrimitives.add("NSNumber");
|
||||
languageSpecificPrimitives.add("NSString");
|
||||
languageSpecificPrimitives.add("NSObject");
|
||||
languageSpecificPrimitives.add("NSDate");
|
||||
languageSpecificPrimitives.add("NSURL");
|
||||
languageSpecificPrimitives.add("bool");
|
||||
languageSpecificPrimitives.add("BOOL");
|
||||
|
||||
typeMapping.clear();
|
||||
typeMapping.put("enum", "NSString");
|
||||
typeMapping.put("date", "NSDate");
|
||||
typeMapping.put("DateTime", "NSDate");
|
||||
typeMapping.put("boolean", "NSNumber");
|
||||
typeMapping.put("string", "NSString");
|
||||
typeMapping.put("integer", "NSNumber");
|
||||
typeMapping.put("int", "NSNumber");
|
||||
typeMapping.put("float", "NSNumber");
|
||||
typeMapping.put("long", "NSNumber");
|
||||
typeMapping.put("double", "NSNumber");
|
||||
typeMapping.put("array", "NSArray");
|
||||
typeMapping.put("map", "NSDictionary");
|
||||
typeMapping.put("number", "NSNumber");
|
||||
typeMapping.put("List", "NSArray");
|
||||
typeMapping.put("object", "NSObject");
|
||||
typeMapping.put("file", "NSURL");
|
||||
|
||||
// ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm
|
||||
reservedWords = new HashSet<String>(
|
||||
@ -70,26 +89,10 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
"double", "protocol", "interface", "implementation",
|
||||
"NSObject", "NSInteger", "NSNumber", "CGFloat",
|
||||
"property", "nonatomic", "retain", "strong",
|
||||
"weak", "unsafe_unretained", "readwrite", "readonly"
|
||||
"weak", "unsafe_unretained", "readwrite", "readonly",
|
||||
"description"
|
||||
));
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("enum", "NSString");
|
||||
typeMapping.put("Date", "NSDate");
|
||||
typeMapping.put("DateTime", "NSDate");
|
||||
typeMapping.put("boolean", "BOOL");
|
||||
typeMapping.put("string", "NSString");
|
||||
typeMapping.put("integer", "NSNumber");
|
||||
typeMapping.put("int", "NSNumber");
|
||||
typeMapping.put("float", "NSNumber");
|
||||
typeMapping.put("long", "NSNumber");
|
||||
typeMapping.put("double", "NSNumber");
|
||||
typeMapping.put("array", "NSArray");
|
||||
typeMapping.put("map", "NSDictionary");
|
||||
typeMapping.put("number", "NSNumber");
|
||||
typeMapping.put("List", "NSArray");
|
||||
typeMapping.put("object", "NSObject");
|
||||
|
||||
importMapping = new HashMap<String, String>();
|
||||
|
||||
foundationClasses = new HashSet<String>(
|
||||
@ -98,15 +101,17 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
"NSObject",
|
||||
"NSString",
|
||||
"NSDate",
|
||||
"NSURL",
|
||||
"NSDictionary")
|
||||
);
|
||||
|
||||
instantiationTypes.put("array", "NSMutableArray");
|
||||
instantiationTypes.put("map", "NSMutableDictionary");
|
||||
|
||||
cliOptions.add(new CliOption("classPrefix", "prefix for generated classes"));
|
||||
cliOptions.add(new CliOption("sourceFolder", "source folder for generated code"));
|
||||
cliOptions.add(new CliOption("projectName", "name of the Xcode project in generated Podfile"));
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption("classPrefix", "prefix for generated classes (convention: Abbreviation of pod name e.g. `HN` for `HackerNews`), default: `SWG`"));
|
||||
cliOptions.add(new CliOption("podName", "cocoapods package name (convention: CameCase), default: `SwaggerClient`"));
|
||||
cliOptions.add(new CliOption("podVersion", "cocoapods package version, default: `1.0.0`"));
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
@ -125,35 +130,43 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey("sourceFolder")) {
|
||||
this.setSourceFolder((String) additionalProperties.get("sourceFolder"));
|
||||
if (additionalProperties.containsKey("podName")) {
|
||||
setPodName((String) additionalProperties.get("podName"));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("podVersion")) {
|
||||
setPodVersion((String) additionalProperties.get("podVersion"));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("classPrefix")) {
|
||||
this.setClassPrefix((String) additionalProperties.get("classPrefix"));
|
||||
setClassPrefix((String) additionalProperties.get("classPrefix"));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("projectName")) {
|
||||
this.setProjectName((String) additionalProperties.get("projectName"));
|
||||
} else {
|
||||
additionalProperties.put("projectName", projectName);
|
||||
}
|
||||
additionalProperties.put("podName", podName);
|
||||
additionalProperties.put("podVersion", podVersion);
|
||||
additionalProperties.put("classPrefix", classPrefix);
|
||||
|
||||
supportingFiles.add(new SupportingFile("SWGObject.h", sourceFolder, "SWGObject.h"));
|
||||
supportingFiles.add(new SupportingFile("SWGObject.m", sourceFolder, "SWGObject.m"));
|
||||
supportingFiles.add(new SupportingFile("SWGQueryParamCollection.h", sourceFolder, "SWGQueryParamCollection.h"));
|
||||
supportingFiles.add(new SupportingFile("SWGQueryParamCollection.m", sourceFolder, "SWGQueryParamCollection.m"));
|
||||
supportingFiles.add(new SupportingFile("SWGApiClient-header.mustache", sourceFolder, "SWGApiClient.h"));
|
||||
supportingFiles.add(new SupportingFile("SWGApiClient-body.mustache", sourceFolder, "SWGApiClient.m"));
|
||||
supportingFiles.add(new SupportingFile("SWGJSONResponseSerializer-header.mustache", sourceFolder, "SWGJSONResponseSerializer.h"));
|
||||
supportingFiles.add(new SupportingFile("SWGJSONResponseSerializer-body.mustache", sourceFolder, "SWGJSONResponseSerializer.m"));
|
||||
supportingFiles.add(new SupportingFile("SWGFile.h", sourceFolder, "SWGFile.h"));
|
||||
supportingFiles.add(new SupportingFile("SWGFile.m", sourceFolder, "SWGFile.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.m", sourceFolder, "JSONValueTransformer+ISO8601.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.h", sourceFolder, "JSONValueTransformer+ISO8601.h"));
|
||||
supportingFiles.add(new SupportingFile("SWGConfiguration-body.mustache", sourceFolder, "SWGConfiguration.m"));
|
||||
supportingFiles.add(new SupportingFile("SWGConfiguration-header.mustache", sourceFolder, "SWGConfiguration.h"));
|
||||
supportingFiles.add(new SupportingFile("Podfile.mustache", "", "Podfile"));
|
||||
String swaggerFolder = podName;
|
||||
|
||||
modelPackage = swaggerFolder;
|
||||
apiPackage = swaggerFolder;
|
||||
|
||||
supportingFiles.add(new SupportingFile("Object-header.mustache", swaggerFolder, classPrefix + "Object.h"));
|
||||
supportingFiles.add(new SupportingFile("Object-body.mustache", swaggerFolder, classPrefix + "Object.m"));
|
||||
supportingFiles.add(new SupportingFile("QueryParamCollection-header.mustache", swaggerFolder, classPrefix + "QueryParamCollection.h"));
|
||||
supportingFiles.add(new SupportingFile("QueryParamCollection-body.mustache", swaggerFolder, classPrefix + "QueryParamCollection.m"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient-header.mustache", swaggerFolder, classPrefix + "ApiClient.h"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient-body.mustache", swaggerFolder, classPrefix + "ApiClient.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONResponseSerializer-header.mustache", swaggerFolder, classPrefix + "JSONResponseSerializer.h"));
|
||||
supportingFiles.add(new SupportingFile("JSONResponseSerializer-body.mustache", swaggerFolder, classPrefix + "JSONResponseSerializer.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONRequestSerializer-body.mustache", swaggerFolder, classPrefix + "JSONRequestSerializer.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONRequestSerializer-header.mustache", swaggerFolder, classPrefix + "JSONRequestSerializer.h"));
|
||||
supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.m", swaggerFolder, "JSONValueTransformer+ISO8601.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.h", swaggerFolder, "JSONValueTransformer+ISO8601.h"));
|
||||
supportingFiles.add(new SupportingFile("Configuration-body.mustache", swaggerFolder, classPrefix + "Configuration.m"));
|
||||
supportingFiles.add(new SupportingFile("Configuration-header.mustache", swaggerFolder, classPrefix + "Configuration.h"));
|
||||
supportingFiles.add(new SupportingFile("podspec.mustache", "", podName + ".podspec"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -202,21 +215,22 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
Property inner = ap.getItems();
|
||||
String innerType = getSwaggerType(inner);
|
||||
|
||||
// In this codition, type of property p is array of primitive,
|
||||
// return container type with pointer, e.g. `NSArray*'
|
||||
if (languageSpecificPrimitives.contains(innerType)) {
|
||||
return getSwaggerType(p) + "*";
|
||||
}
|
||||
|
||||
// In this codition, type of property p is array of model,
|
||||
// return container type combine inner type with pointer, e.g. `NSArray<SWGTag>*'
|
||||
String innerTypeDeclaration = getTypeDeclaration(inner);
|
||||
|
||||
if (innerTypeDeclaration.endsWith("*")) {
|
||||
innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1);
|
||||
}
|
||||
|
||||
return getSwaggerType(p) + "<" + innerTypeDeclaration + ">*";
|
||||
// In this codition, type of property p is array of primitive,
|
||||
// return container type with pointer, e.g. `NSArray* /* NSString */'
|
||||
if (languageSpecificPrimitives.contains(innerType)) {
|
||||
return getSwaggerType(p) + "*" + " /* " + innerTypeDeclaration + " */";
|
||||
}
|
||||
// In this codition, type of property p is array of model,
|
||||
// return container type combine inner type with pointer, e.g. `NSArray<SWGTag>*'
|
||||
else {
|
||||
return getSwaggerType(p) + "<" + innerTypeDeclaration + ">*";
|
||||
}
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
@ -285,11 +299,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
if ("".equals(modelPackage())) {
|
||||
return name;
|
||||
} else {
|
||||
return modelPackage() + "." + name;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -299,12 +309,12 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder;
|
||||
return outputFolder + File.separatorChar + apiPackage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder;
|
||||
return outputFolder + File.separatorChar + modelPackage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -351,6 +361,11 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
@ -359,15 +374,15 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return camelize(operationId, true);
|
||||
}
|
||||
|
||||
public void setSourceFolder(String sourceFolder) {
|
||||
this.sourceFolder = sourceFolder;
|
||||
}
|
||||
|
||||
public void setClassPrefix(String classPrefix) {
|
||||
this.classPrefix = classPrefix;
|
||||
}
|
||||
|
||||
public void setProjectName(String projectName) {
|
||||
this.projectName = projectName;
|
||||
public void setPodName(String podName) {
|
||||
this.podName = podName;
|
||||
}
|
||||
|
||||
public void setPodVersion(String podVersion) {
|
||||
this.podVersion = podVersion;
|
||||
}
|
||||
}
|
||||
|
@ -9,11 +9,12 @@ import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.codegen.CliOption;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String moduleName = "SwaggerClient";
|
||||
protected String moduleVersion = "1.0.0";
|
||||
@ -158,15 +159,17 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// return the name in underscore style
|
||||
// PhoneNumber => phone_number
|
||||
name = underscore(name);
|
||||
|
||||
// parameter name starting with number won't compile
|
||||
// need to escape it by appending _ at the beginning
|
||||
if (name.matches("^[0-9]")) {
|
||||
if (name.matches("^\\d.*")) {
|
||||
name = "_" + name;
|
||||
}
|
||||
|
||||
// return the name in underscore style
|
||||
// PhoneNumber => phone_number
|
||||
return underscore(name);
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -213,6 +216,11 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
@ -14,16 +15,20 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "Swagger\\Client";
|
||||
protected String groupId = "swagger";
|
||||
protected String artifactId = "swagger-client";
|
||||
protected String artifactVersion = null;
|
||||
protected String composerVendorName = "swagger";
|
||||
protected String composerProjectName = "swagger-client";
|
||||
protected String packagePath = "SwaggerClient-php";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String srcBasePath = "lib";
|
||||
|
||||
public PhpClientCodegen() {
|
||||
super();
|
||||
|
||||
outputFolder = "generated-code/php";
|
||||
outputFolder = "generated-code" + File.separator + "php";
|
||||
modelTemplateFiles.put("model.mustache", ".php");
|
||||
apiTemplateFiles.put("api.mustache", ".php");
|
||||
templateDir = "php";
|
||||
@ -35,14 +40,6 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
"__halt_compiler", "abstract", "and", "array", "as", "break", "callable", "case", "catch", "class", "clone", "const", "continue", "declare", "default", "die", "do", "echo", "else", "elseif", "empty", "enddeclare", "endfor", "endforeach", "endif", "endswitch", "endwhile", "eval", "exit", "extends", "final", "for", "foreach", "function", "global", "goto", "if", "implements", "include", "include_once", "instanceof", "insteadof", "interface", "isset", "list", "namespace", "new", "or", "print", "private", "protected", "public", "require", "require_once", "return", "static", "switch", "throw", "trait", "try", "unset", "use", "var", "while", "xor")
|
||||
);
|
||||
|
||||
additionalProperties.put("invokerPackage", invokerPackage);
|
||||
additionalProperties.put("modelPackage", modelPackage);
|
||||
additionalProperties.put("apiPackage", apiPackage);
|
||||
additionalProperties.put("escapedInvokerPackage", invokerPackage.replace("\\", "\\\\"));
|
||||
additionalProperties.put("groupId", groupId);
|
||||
additionalProperties.put("artifactId", artifactId);
|
||||
additionalProperties.put("artifactVersion", artifactVersion);
|
||||
|
||||
// ref: http://php.net/manual/en/language.types.intro.php
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
@ -75,22 +72,23 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("date", "\\DateTime");
|
||||
typeMapping.put("datetime", "\\DateTime");
|
||||
typeMapping.put("file", "string");
|
||||
typeMapping.put("file", "\\SplFileObject");
|
||||
typeMapping.put("map", "map");
|
||||
typeMapping.put("array", "array");
|
||||
typeMapping.put("list", "array");
|
||||
typeMapping.put("object", "object");
|
||||
typeMapping.put("DateTime", "\\DateTime");
|
||||
|
||||
supportingFiles.add(new SupportingFile("composer.mustache", getPackagePath(), "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", toPackagePath(invokerPackage, "lib"), "Configuration.php"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", toPackagePath(invokerPackage, "lib"), "ApiClient.php"));
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache", toPackagePath(invokerPackage, "lib"), "ApiException.php"));
|
||||
supportingFiles.add(new SupportingFile("autoload.mustache", getPackagePath(), "autoload.php"));
|
||||
|
||||
cliOptions.add(new CliOption("invokerPackage", "The main namespace to use for all classes. e.g. Yay\\Pets"));
|
||||
cliOptions.add(new CliOption("packagePath", "The main package name for classes. e.g. GeneratedPetstore"));
|
||||
cliOptions.add(new CliOption("srcBasePath", "The directory under packagePath to serve as source root."));
|
||||
cliOptions.add(new CliOption("composerVendorName", "The vendor name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name. e.g. yaypets"));
|
||||
cliOptions.add(new CliOption("composerProjectName", "The project name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name. e.g. petstore-client"));
|
||||
cliOptions.add(new CliOption("artifactVersion", "The version to use in the composer package version field. e.g. 1.2.3"));
|
||||
}
|
||||
|
||||
public String getPackagePath() {
|
||||
return "SwaggerClient-php";
|
||||
return packagePath;
|
||||
}
|
||||
|
||||
public String toPackagePath(String packageName, String basePath) {
|
||||
@ -99,13 +97,27 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separatorChar;
|
||||
}
|
||||
|
||||
String regFirstPathSeparator;
|
||||
if ("/".equals(File.separator)) { // for mac, linux
|
||||
regFirstPathSeparator = "^/";
|
||||
} else { // for windows
|
||||
regFirstPathSeparator = "^\\\\";
|
||||
}
|
||||
|
||||
String regLastPathSeparator;
|
||||
if ("/".equals(File.separator)) { // for mac, linux
|
||||
regLastPathSeparator = "/$";
|
||||
} else { // for windows
|
||||
regLastPathSeparator = "\\\\$";
|
||||
}
|
||||
|
||||
return (getPackagePath() + File.separatorChar + basePath
|
||||
// Replace period, backslash, forward slash with file separator in package name
|
||||
+ packageName.replaceAll("[\\.\\\\/]", File.separator)
|
||||
// Trim prefix file separators from package path
|
||||
.replaceAll("^" + File.separator, ""))
|
||||
// Trim trailing file separators from the overall path
|
||||
.replaceAll(File.separator + "$", "");
|
||||
.replaceAll(regFirstPathSeparator, ""))
|
||||
// Trim trailing file separators from the overall path
|
||||
.replaceAll(regLastPathSeparator+ "$", "");
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
@ -120,6 +132,68 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return "Generates a PHP client library.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey("packagePath")) {
|
||||
this.setPackagePath((String) additionalProperties.get("packagePath"));
|
||||
} else {
|
||||
additionalProperties.put("packagePath", packagePath);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("srcBasePath")) {
|
||||
this.setSrcBasePath((String) additionalProperties.get("srcBasePath"));
|
||||
} else {
|
||||
additionalProperties.put("srcBasePath", srcBasePath);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("invokerPackage")) {
|
||||
this.setInvokerPackage((String) additionalProperties.get("invokerPackage"));
|
||||
} else {
|
||||
additionalProperties.put("invokerPackage", invokerPackage);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("modelPackage")) {
|
||||
this.setModelPackage((String) additionalProperties.get("modelPackage"));
|
||||
} else {
|
||||
additionalProperties.put("modelPackage", modelPackage);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("apiPackage")) {
|
||||
this.setApiPackage((String) additionalProperties.get("apiPackage"));
|
||||
} else {
|
||||
additionalProperties.put("apiPackage", apiPackage);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("composerProjectName")) {
|
||||
this.setComposerProjectName((String) additionalProperties.get("composerProjectName"));
|
||||
} else {
|
||||
additionalProperties.put("composerProjectName", composerProjectName);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("composerVendorName")) {
|
||||
this.setComposerVendorName((String) additionalProperties.get("composerVendorName"));
|
||||
} else {
|
||||
additionalProperties.put("composerVendorName", composerVendorName);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("artifactVersion")) {
|
||||
this.setArtifactVersion((String) additionalProperties.get("artifactVersion"));
|
||||
} else {
|
||||
additionalProperties.put("artifactVersion", artifactVersion);
|
||||
}
|
||||
|
||||
additionalProperties.put("escapedInvokerPackage", invokerPackage.replace("\\", "\\\\"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", toPackagePath(invokerPackage, srcBasePath), "Configuration.php"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", toPackagePath(invokerPackage, srcBasePath), "ApiClient.php"));
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache", toPackagePath(invokerPackage, srcBasePath), "ApiException.php"));
|
||||
supportingFiles.add(new SupportingFile("ObjectSerializer.mustache", toPackagePath(invokerPackage, srcBasePath), "ObjectSerializer.php"));
|
||||
supportingFiles.add(new SupportingFile("composer.mustache", getPackagePath(), "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("autoload.mustache", getPackagePath(), "autoload.php"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
@ -127,11 +201,11 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return (outputFolder + "/" + toPackagePath(apiPackage(), "lib"));
|
||||
return (outputFolder + "/" + toPackagePath(apiPackage(), srcBasePath));
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return (outputFolder + "/" + toPackagePath(modelPackage(), "lib"));
|
||||
return (outputFolder + "/" + toPackagePath(modelPackage(), srcBasePath));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -184,18 +258,43 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return "null";
|
||||
}
|
||||
|
||||
public void setInvokerPackage(String invokerPackage) {
|
||||
this.invokerPackage = invokerPackage;
|
||||
}
|
||||
|
||||
public void setArtifactVersion(String artifactVersion) {
|
||||
this.artifactVersion = artifactVersion;
|
||||
}
|
||||
|
||||
public void setPackagePath(String packagePath) {
|
||||
this.packagePath = packagePath;
|
||||
}
|
||||
|
||||
public void setSrcBasePath(String srcBasePath) {
|
||||
this.srcBasePath = srcBasePath;
|
||||
}
|
||||
|
||||
private void setComposerVendorName(String composerVendorName) {
|
||||
this.composerVendorName = composerVendorName;
|
||||
}
|
||||
|
||||
public void setComposerProjectName(String composerProjectName) {
|
||||
this.composerProjectName = composerProjectName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// return the name in underscore style
|
||||
// PhoneNumber => phone_number
|
||||
name = underscore(name);
|
||||
|
||||
// parameter name starting with number won't compile
|
||||
// need to escape it by appending _ at the beginning
|
||||
if (name.matches("^[0-9]")) {
|
||||
if (name.matches("^\\d.*")) {
|
||||
name = "_" + name;
|
||||
}
|
||||
|
||||
// return the name in underscore style
|
||||
// PhoneNumber => phone_number
|
||||
return underscore(name);
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -221,5 +320,4 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
// should be the same as the model name
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class Python3ClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
String module = "client";
|
||||
|
||||
@ -33,6 +35,7 @@ public class Python3ClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
languageSpecificPrimitives.add("bool");
|
||||
languageSpecificPrimitives.add("str");
|
||||
languageSpecificPrimitives.add("datetime");
|
||||
languageSpecificPrimitives.add("date");
|
||||
|
||||
typeMapping.clear();
|
||||
typeMapping.put("integer", "int");
|
||||
@ -43,7 +46,8 @@ public class Python3ClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
typeMapping.put("map", "map");
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("string", "str");
|
||||
typeMapping.put("date", "datetime");
|
||||
typeMapping.put("date", "date");
|
||||
typeMapping.put("DateTime", "datetime");
|
||||
|
||||
// from https://docs.python.org/release/2.5.4/ref/keywords.html
|
||||
reservedWords = new HashSet<String>(
|
||||
@ -199,6 +203,11 @@ public class Python3ClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
@ -12,26 +13,22 @@ import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String module = "SwaggerPetstore";
|
||||
protected String invokerPackage;
|
||||
protected String eggPackage;
|
||||
protected String packageName = null;
|
||||
protected String packageVersion = null;
|
||||
|
||||
public PythonClientCodegen() {
|
||||
super();
|
||||
|
||||
eggPackage = module + "-python";
|
||||
|
||||
invokerPackage = eggPackage + File.separatorChar + module;
|
||||
|
||||
modelPackage = "models";
|
||||
apiPackage = "api";
|
||||
outputFolder = "generated-code" + File.separatorChar + "python";
|
||||
modelTemplateFiles.put("model.mustache", ".py");
|
||||
apiTemplateFiles.put("api.mustache", ".py");
|
||||
templateDir = "python";
|
||||
|
||||
apiPackage = invokerPackage + File.separatorChar + "apis";
|
||||
modelPackage = invokerPackage + File.separatorChar + "models";
|
||||
|
||||
languageSpecificPrimitives.clear();
|
||||
languageSpecificPrimitives.add("int");
|
||||
languageSpecificPrimitives.add("float");
|
||||
@ -39,6 +36,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
languageSpecificPrimitives.add("bool");
|
||||
languageSpecificPrimitives.add("str");
|
||||
languageSpecificPrimitives.add("datetime");
|
||||
languageSpecificPrimitives.add("date");
|
||||
|
||||
typeMapping.clear();
|
||||
typeMapping.put("integer", "int");
|
||||
@ -49,8 +47,10 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
typeMapping.put("map", "dict");
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("string", "str");
|
||||
typeMapping.put("date", "datetime");
|
||||
typeMapping.put("date", "date");
|
||||
typeMapping.put("DateTime", "datetime");
|
||||
typeMapping.put("object", "object");
|
||||
typeMapping.put("file", "file");
|
||||
|
||||
// from https://docs.python.org/release/2.5.4/ref/keywords.html
|
||||
reservedWords = new HashSet<String>(
|
||||
@ -60,14 +60,43 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"print", "class", "exec", "in", "raise", "continue", "finally", "is",
|
||||
"return", "def", "for", "lambda", "try"));
|
||||
|
||||
additionalProperties.put("module", module);
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption("packageName", "python package name (convension: under_score), default: swagger_client"));
|
||||
cliOptions.add(new CliOption("packageVersion", "python package version, default: 1.0.0"));
|
||||
}
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", eggPackage, "README.md"));
|
||||
supportingFiles.add(new SupportingFile("setup.mustache", eggPackage, "setup.py"));
|
||||
supportingFiles.add(new SupportingFile("api_client.mustache", invokerPackage, "api_client.py"));
|
||||
supportingFiles.add(new SupportingFile("rest.mustache", invokerPackage, "rest.py"));
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", invokerPackage, "configuration.py"));
|
||||
supportingFiles.add(new SupportingFile("__init__package.mustache", invokerPackage, "__init__.py"));
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey("packageName")) {
|
||||
setPackageName((String) additionalProperties.get("packageName"));
|
||||
}
|
||||
else {
|
||||
setPackageName("swagger_client");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("packageVersion")) {
|
||||
setPackageVersion((String) additionalProperties.get("packageVersion"));
|
||||
}
|
||||
else {
|
||||
setPackageVersion("1.0.0");
|
||||
}
|
||||
|
||||
additionalProperties.put("packageName", packageName);
|
||||
additionalProperties.put("packageVersion", packageVersion);
|
||||
|
||||
String swaggerFolder = packageName;
|
||||
|
||||
modelPackage = swaggerFolder + File.separatorChar + "models";
|
||||
apiPackage = swaggerFolder + File.separatorChar + "apis";
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("setup.mustache", "", "setup.py"));
|
||||
supportingFiles.add(new SupportingFile("api_client.mustache", swaggerFolder, "api_client.py"));
|
||||
supportingFiles.add(new SupportingFile("rest.mustache", swaggerFolder, "rest.py"));
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", swaggerFolder, "configuration.py"));
|
||||
supportingFiles.add(new SupportingFile("__init__package.mustache", swaggerFolder, "__init__.py"));
|
||||
supportingFiles.add(new SupportingFile("__init__model.mustache", modelPackage, "__init__.py"));
|
||||
supportingFiles.add(new SupportingFile("__init__api.mustache", apiPackage, "__init__.py"));
|
||||
}
|
||||
@ -133,8 +162,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
public String toDefaultValue(Property p) {
|
||||
// TODO: Support Python def value
|
||||
return "null";
|
||||
return "None";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -151,6 +179,9 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
// petId => pet_id
|
||||
name = underscore(dropDots(name));
|
||||
|
||||
// remove leading underscore
|
||||
name = name.replaceAll("^_*", "");
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
@ -217,6 +248,11 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
@ -225,4 +261,23 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return underscore(operationId);
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public void setPackageVersion(String packageVersion) {
|
||||
this.packageVersion = packageVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Python package name from String `packageName`
|
||||
*
|
||||
* (PEP 0008) Python packages should also have short, all-lowercase names,
|
||||
* although the use of underscores is discouraged.
|
||||
*/
|
||||
public String generatePackageName(String packageName) {
|
||||
return underscore(packageName.replaceAll("[^\\w]+", ""));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,6 +15,8 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class RetrofitClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
protected String groupId = "io.swagger";
|
||||
@ -171,6 +173,11 @@ public class RetrofitClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
|
@ -13,6 +13,8 @@ import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String gemName = null;
|
||||
protected String moduleName = null;
|
||||
@ -55,12 +57,14 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("float", "Float");
|
||||
typeMapping.put("double", "Float");
|
||||
typeMapping.put("number", "Float");
|
||||
typeMapping.put("date", "Date");
|
||||
typeMapping.put("DateTime", "DateTime");
|
||||
typeMapping.put("boolean", "BOOLEAN");
|
||||
typeMapping.put("array", "Array");
|
||||
typeMapping.put("List", "Array");
|
||||
typeMapping.put("map", "Hash");
|
||||
typeMapping.put("object", "Object");
|
||||
typeMapping.put("file", "File");
|
||||
|
||||
// remove modelPackage and apiPackage added by default
|
||||
cliOptions.clear();
|
||||
@ -106,7 +110,6 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("swagger_client.gemspec.mustache", "", gemName + ".gemspec"));
|
||||
supportingFiles.add(new SupportingFile("swagger_client.mustache", libFolder, gemName + ".rb"));
|
||||
String baseFolder = libFolder + File.separator + gemName;
|
||||
supportingFiles.add(new SupportingFile("monkey.mustache", baseFolder, "monkey.rb"));
|
||||
supportingFiles.add(new SupportingFile("swagger.mustache", baseFolder, "swagger.rb"));
|
||||
String swaggerFolder = baseFolder + File.separator + "swagger";
|
||||
supportingFiles.add(new SupportingFile("swagger" + File.separator + "request.mustache", swaggerFolder, "request.rb"));
|
||||
@ -266,6 +269,11 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
|
@ -20,6 +20,11 @@ import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
@ -206,6 +211,11 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
@ -214,4 +224,17 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return camelize(operationId, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
// remove model imports to avoid warnings for importing class in the same package in Scala
|
||||
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
|
||||
final String prefix = modelPackage() + ".";
|
||||
Iterator<Map<String, String>> iterator = imports.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String _import = iterator.next().get("import");
|
||||
if (_import.startsWith(prefix)) iterator.remove();
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -88,11 +88,11 @@ public class SilexServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "silex";
|
||||
return "silex-PHP";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
@ -154,15 +154,17 @@ public class SilexServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// return the name in underscore style
|
||||
// PhoneNumber => phone_number
|
||||
name = underscore(name);
|
||||
|
||||
// parameter name starting with number won't compile
|
||||
// need to escape it by appending _ at the beginning
|
||||
if (name.matches("^[0-9]")) {
|
||||
if (name.matches("^\\d.*")) {
|
||||
name = "_" + name;
|
||||
}
|
||||
|
||||
// return the name in underscore style
|
||||
// PhoneNumber => phone_number
|
||||
return underscore(name);
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,217 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String gemName = null;
|
||||
protected String moduleName = null;
|
||||
protected String gemVersion = "1.0.0";
|
||||
protected String libFolder = "lib";
|
||||
|
||||
public SinatraServerCodegen() {
|
||||
super();
|
||||
apiPackage = "lib";
|
||||
outputFolder = "generated-code" + File.separator + "sinatra";
|
||||
|
||||
// no model
|
||||
modelTemplateFiles.clear();
|
||||
apiTemplateFiles.put("api.mustache", ".rb");
|
||||
templateDir = "sinatra";
|
||||
|
||||
typeMapping.clear();
|
||||
languageSpecificPrimitives.clear();
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"__FILE__", "and", "def", "end", "in", "or", "self", "unless", "__LINE__",
|
||||
"begin", "defined?", "ensure", "module", "redo", "super", "until", "BEGIN",
|
||||
"break", "do", "false", "next", "rescue", "then", "when", "END", "case",
|
||||
"else", "for", "nil", "retry", "true", "while", "alias", "class", "elsif",
|
||||
"if", "not", "return", "undef", "yield")
|
||||
);
|
||||
|
||||
languageSpecificPrimitives.add("int");
|
||||
languageSpecificPrimitives.add("array");
|
||||
languageSpecificPrimitives.add("map");
|
||||
languageSpecificPrimitives.add("string");
|
||||
languageSpecificPrimitives.add("DateTime");
|
||||
|
||||
typeMapping.put("long", "int");
|
||||
typeMapping.put("integer", "int");
|
||||
typeMapping.put("Array", "array");
|
||||
typeMapping.put("String", "string");
|
||||
typeMapping.put("List", "array");
|
||||
typeMapping.put("map", "map");
|
||||
|
||||
// remove modelPackage and apiPackage added by default
|
||||
cliOptions.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
// use constant model/api package (folder path)
|
||||
//setModelPackage("models");
|
||||
setApiPackage("api");
|
||||
|
||||
supportingFiles.add(new SupportingFile("my_app.mustache", "", "my_app.rb"));
|
||||
supportingFiles.add(new SupportingFile("Swaggering.rb", libFolder, "swaggering.rb"));
|
||||
supportingFiles.add(new SupportingFile("config.ru", "", "config.ru"));
|
||||
supportingFiles.add(new SupportingFile("Gemfile", "", "Gemfile"));
|
||||
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "sinatra";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a Sinatra server library.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + apiPackage.replace("/", File.separator);
|
||||
}
|
||||
|
||||
@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 type;
|
||||
}
|
||||
} else {
|
||||
type = swaggerType;
|
||||
}
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public String toDefaultValue(Property p) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// petId => pet_id
|
||||
name = underscore(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
// underscore the model file name
|
||||
// PhoneNumber.rb => phone_number.rb
|
||||
return underscore(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
// e.g. PhoneNumberApi.rb => phone_number_api.rb
|
||||
return underscore(name) + "_api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
// e.g. phone_number_api => PhoneNumberApi
|
||||
return camelize(name) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
return underscore(operationId);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,9 +1,6 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
@ -27,7 +24,7 @@ public class SpringMVCServerCodegen extends JavaClientCodegen implements Codegen
|
||||
protected String configPackage = "";
|
||||
|
||||
public SpringMVCServerCodegen() {
|
||||
super.processOpts();
|
||||
super();
|
||||
outputFolder = "generated-code/javaSpringMVC";
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
@ -55,6 +52,9 @@ public class SpringMVCServerCodegen extends JavaClientCodegen implements Codegen
|
||||
"Long",
|
||||
"Float")
|
||||
);
|
||||
|
||||
cliOptions.add(new CliOption("configPackage", "configuration package for generated code"));
|
||||
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
@ -73,6 +73,10 @@ public class SpringMVCServerCodegen extends JavaClientCodegen implements Codegen
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey("configPackage")) {
|
||||
this.setConfigPackage((String) additionalProperties.get("configPackage"));
|
||||
}
|
||||
|
||||
supportingFiles.clear();
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
@ -146,6 +150,14 @@ public class SpringMVCServerCodegen extends JavaClientCodegen implements Codegen
|
||||
if (operations != null) {
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
for (CodegenOperation operation : ops) {
|
||||
List<CodegenResponse> responses = operation.responses;
|
||||
if (responses != null) {
|
||||
for (CodegenResponse resp : responses) {
|
||||
if ("0".equals(resp.code)) {
|
||||
resp.code = "200";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (operation.returnType == null) {
|
||||
operation.returnType = "Void";
|
||||
} else if (operation.returnType.startsWith("List")) {
|
||||
@ -174,5 +186,9 @@ public class SpringMVCServerCodegen extends JavaClientCodegen implements Codegen
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
public void setConfigPackage(String configPackage) {
|
||||
this.configPackage = configPackage;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,298 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.parameters.HeaderParameter;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Pattern PATH_PARAM_PATTERN = Pattern.compile("\\{[a-zA-Z_]+\\}");
|
||||
protected static final String LIBRARY_PROMISE_KIT = "PromiseKit";
|
||||
protected static final String[] RESPONSE_LIBRARIES = { LIBRARY_PROMISE_KIT };
|
||||
protected String projectName = "SwaggerClient";
|
||||
protected boolean unwrapRequired = false;
|
||||
protected String[] responseAs = new String[0];
|
||||
protected String sourceFolder = "Classes" + File.separator + "Swaggers";
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "swift";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a swift client library.";
|
||||
}
|
||||
|
||||
public SwiftCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code" + File.separator + "swift";
|
||||
modelTemplateFiles.put("model.mustache", ".swift");
|
||||
apiTemplateFiles.put("api.mustache", ".swift");
|
||||
templateDir = "swift";
|
||||
apiPackage = File.separator + "APIs";
|
||||
modelPackage = File.separator + "Models";
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"Int",
|
||||
"Float",
|
||||
"Double",
|
||||
"Bool",
|
||||
"Void",
|
||||
"String",
|
||||
"Character")
|
||||
);
|
||||
defaultIncludes = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"NSDate",
|
||||
"Array",
|
||||
"Dictionary",
|
||||
"Set",
|
||||
"Any",
|
||||
"Empty",
|
||||
"AnyObject")
|
||||
);
|
||||
reservedWords = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"class", "break", "as", "associativity", "deinit", "case", "dynamicType", "convenience", "enum", "continue",
|
||||
"false", "dynamic", "extension", "default", "is", "didSet", "func", "do", "nil", "final", "import", "else",
|
||||
"self", "get", "init", "fallthrough", "Self", "infix", "internal", "for", "super", "inout", "let", "if",
|
||||
"true", "lazy", "operator", "in", "COLUMN", "left", "private", "return", "FILE", "mutating", "protocol",
|
||||
"switch", "FUNCTION", "none", "public", "where", "LINE", "nonmutating", "static", "while", "optional",
|
||||
"struct", "override", "subscript", "postfix", "typealias", "precedence", "var", "prefix", "Protocol",
|
||||
"required", "right", "set", "Type", "unowned", "weak")
|
||||
);
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("array", "Array");
|
||||
typeMapping.put("List", "Array");
|
||||
typeMapping.put("map", "Dictionary");
|
||||
typeMapping.put("date", "NSDate");
|
||||
typeMapping.put("Date", "NSDate");
|
||||
typeMapping.put("DateTime", "NSDate");
|
||||
typeMapping.put("boolean", "Bool");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("char", "Character");
|
||||
typeMapping.put("short", "Int");
|
||||
typeMapping.put("int", "Int");
|
||||
typeMapping.put("long", "Int");
|
||||
typeMapping.put("integer", "Int");
|
||||
typeMapping.put("Integer", "Int");
|
||||
typeMapping.put("float", "Float");
|
||||
typeMapping.put("number", "Double");
|
||||
typeMapping.put("double", "Double");
|
||||
typeMapping.put("object", "String");
|
||||
typeMapping.put("file", "NSURL");
|
||||
|
||||
importMapping = new HashMap<String, String>();
|
||||
|
||||
cliOptions.add(new CliOption("projectName", "Project name in Xcode"));
|
||||
cliOptions.add(new CliOption("responseAs", "Optionally use libraries to manage response. Currently " +
|
||||
StringUtils.join(RESPONSE_LIBRARIES, ", ") + " are available."));
|
||||
cliOptions.add(new CliOption("unwrapRequired", "Treat 'required' properties in response as non-optional " +
|
||||
"(which would crash the app if api returns null as opposed to required option specified in json schema"));
|
||||
cliOptions.add(new CliOption("podSource", "Source information used for Podspec"));
|
||||
cliOptions.add(new CliOption("podVersion", "Version used for Podspec"));
|
||||
cliOptions.add(new CliOption("podAuthors", "Authors used for Podspec"));
|
||||
cliOptions.add(new CliOption("podSocialMediaURL", "Social Media URL used for Podspec"));
|
||||
cliOptions.add(new CliOption("podDocsetURL", "Docset URL used for Podspec"));
|
||||
cliOptions.add(new CliOption("podLicense", "License used for Podspec"));
|
||||
cliOptions.add(new CliOption("podHomepage", "Homepage used for Podspec"));
|
||||
cliOptions.add(new CliOption("podSummary", "Summary used for Podspec"));
|
||||
cliOptions.add(new CliOption("podDescription", "Description used for Podspec"));
|
||||
cliOptions.add(new CliOption("podScreenshots", "Screenshots used for Podspec"));
|
||||
cliOptions.add(new CliOption("podDocumentationURL", "Documentation URL used for Podspec"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
// Setup project name
|
||||
if (additionalProperties.containsKey("projectName")) {
|
||||
projectName = (String) additionalProperties.get("projectName");
|
||||
} else {
|
||||
additionalProperties.put("projectName", projectName);
|
||||
}
|
||||
sourceFolder = projectName + File.separator + sourceFolder;
|
||||
|
||||
// Setup unwrapRequired option, which makes all the properties with "required" non-optional
|
||||
if (additionalProperties.containsKey("unwrapRequired")) {
|
||||
unwrapRequired = Boolean.parseBoolean(String.valueOf(additionalProperties.get("unwrapRequired")));
|
||||
}
|
||||
additionalProperties.put("unwrapRequired", unwrapRequired);
|
||||
|
||||
// Setup unwrapRequired option, which makes all the properties with "required" non-optional
|
||||
if (additionalProperties.containsKey("responseAs")) {
|
||||
Object responseAsObject = additionalProperties.get("responseAs");
|
||||
if (responseAsObject instanceof String) {
|
||||
responseAs = ((String)responseAsObject).split(",");
|
||||
} else {
|
||||
responseAs = (String[]) responseAsObject;
|
||||
}
|
||||
}
|
||||
additionalProperties.put("responseAs", responseAs);
|
||||
if (ArrayUtils.contains(responseAs, LIBRARY_PROMISE_KIT)) {
|
||||
additionalProperties.put("usePromiseKit", true);
|
||||
}
|
||||
|
||||
supportingFiles.add(new SupportingFile("Podspec.mustache", "", projectName + ".podspec"));
|
||||
supportingFiles.add(new SupportingFile("Cartfile.mustache", "", "Cartfile"));
|
||||
supportingFiles.add(new SupportingFile("APIHelper.mustache", sourceFolder, "APIHelper.swift"));
|
||||
supportingFiles.add(new SupportingFile("AlamofireImplementations.mustache", sourceFolder,
|
||||
"AlamofireImplementations.swift"));
|
||||
supportingFiles.add(new SupportingFile("Extensions.mustache", sourceFolder, "Extensions.swift"));
|
||||
supportingFiles.add(new SupportingFile("Models.mustache", sourceFolder, "Models.swift"));
|
||||
supportingFiles.add(new SupportingFile("APIs.mustache", sourceFolder, "APIs.swift"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "Swagger" + name; // add an underscore to the name
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
Property inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
return "[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 toDefaultValue(Property p) {
|
||||
// nil
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toInstantiationType(Property p) {
|
||||
if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return "[String:" + inner + "]";
|
||||
} else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return "[" + inner + "]";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenProperty fromProperty(String name, Property p) {
|
||||
CodegenProperty codegenProperty = super.fromProperty(name, p);
|
||||
if (codegenProperty.isEnum) {
|
||||
List<Map<String, String>> swiftEnums = new ArrayList<Map<String, String>>();
|
||||
List<String> values = (List<String>) codegenProperty.allowableValues.get("values");
|
||||
for (String value : values) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("enum", StringUtils.capitalize(value));
|
||||
map.put("raw", value);
|
||||
swiftEnums.add(map);
|
||||
}
|
||||
codegenProperty.allowableValues.put("values", swiftEnums);
|
||||
codegenProperty.datatypeWithEnum =
|
||||
StringUtils.left(codegenProperty.datatypeWithEnum, codegenProperty.datatypeWithEnum.length() - "Enum".length());
|
||||
if (reservedWords.contains(codegenProperty.datatypeWithEnum)) {
|
||||
codegenProperty.datatypeWithEnum = escapeReservedWord(codegenProperty.datatypeWithEnum);
|
||||
}
|
||||
}
|
||||
return codegenProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if(name.length() == 0)
|
||||
return "DefaultAPI";
|
||||
return initialCaps(name) + "API";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions) {
|
||||
path = normalizePath(path);
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
parameters = Lists.newArrayList(Iterators.filter(parameters.iterator(), new Predicate<Parameter>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable Parameter parameter) {
|
||||
return !(parameter instanceof HeaderParameter);
|
||||
}
|
||||
}));
|
||||
operation.setParameters(parameters);
|
||||
return super.fromOperation(path, httpMethod, operation, definitions);
|
||||
}
|
||||
|
||||
private static String normalizePath(String path) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
int cursor = 0;
|
||||
Matcher matcher = PATH_PARAM_PATTERN.matcher(path);
|
||||
boolean found = matcher.find();
|
||||
while (found) {
|
||||
String stringBeforeMatch = path.substring(cursor, matcher.start());
|
||||
builder.append(stringBeforeMatch);
|
||||
|
||||
String group = matcher.group().substring(1, matcher.group().length() - 1);
|
||||
group = camelize(group, true);
|
||||
builder
|
||||
.append("{")
|
||||
.append(group)
|
||||
.append("}");
|
||||
|
||||
cursor = matcher.end();
|
||||
found = matcher.find();
|
||||
}
|
||||
|
||||
String stringAfterMatch = path.substring(cursor);
|
||||
builder.append(stringAfterMatch);
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
@ -1,265 +0,0 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.parameters.HeaderParameter;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class SwiftGenerator extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Pattern PATH_PARAM_PATTERN = Pattern.compile("\\{[a-zA-Z_]+\\}");
|
||||
protected String sourceFolder = "Classes/Swaggers";
|
||||
|
||||
public SwiftGenerator() {
|
||||
super();
|
||||
outputFolder = "generated-code/swift";
|
||||
modelTemplateFiles.put("model.mustache", ".swift");
|
||||
apiTemplateFiles.put("api.mustache", ".swift");
|
||||
templateDir = "swift";
|
||||
apiPackage = "/APIs";
|
||||
modelPackage = "/Models";
|
||||
|
||||
// Inject application name
|
||||
String appName = System.getProperty("appName");
|
||||
if (appName == null) {
|
||||
appName = "SwaggerClient";
|
||||
}
|
||||
additionalProperties.put("projectName", appName);
|
||||
|
||||
// Inject base url override
|
||||
String basePathOverride = System.getProperty("basePathOverride");
|
||||
if (basePathOverride != null) {
|
||||
additionalProperties.put("basePathOverride", basePathOverride);
|
||||
}
|
||||
|
||||
sourceFolder = appName + "/" + sourceFolder;
|
||||
|
||||
supportingFiles.add(new SupportingFile("Cartfile.mustache", "", "Cartfile"));
|
||||
supportingFiles.add(new SupportingFile("APIHelper.mustache", sourceFolder, "APIHelper.swift"));
|
||||
supportingFiles.add(new SupportingFile("AlamofireImplementations.mustache", sourceFolder, "AlamofireImplementations.swift"));
|
||||
supportingFiles.add(new SupportingFile("Extensions.mustache", sourceFolder, "Extensions.swift"));
|
||||
supportingFiles.add(new SupportingFile("Models.mustache", sourceFolder, "Models.swift"));
|
||||
supportingFiles.add(new SupportingFile("APIs.mustache", sourceFolder, "APIs.swift"));
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"Int",
|
||||
"Float",
|
||||
"Double",
|
||||
"Bool",
|
||||
"Void",
|
||||
"String",
|
||||
"Character")
|
||||
);
|
||||
defaultIncludes = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"NSDate",
|
||||
"Array",
|
||||
"Dictionary",
|
||||
"Set",
|
||||
"Any",
|
||||
"Empty",
|
||||
"AnyObject")
|
||||
);
|
||||
reservedWords = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"class", "break", "as", "associativity", "deinit", "case", "dynamicType", "convenience", "enum", "continue",
|
||||
"false", "dynamic", "extension", "default", "is", "didSet", "func", "do", "nil", "final", "import", "else",
|
||||
"self", "get", "init", "fallthrough", "Self", "infix", "internal", "for", "super", "inout", "let", "if",
|
||||
"true", "lazy", "operator", "in", "COLUMN", "left", "private", "return", "FILE", "mutating", "protocol",
|
||||
"switch", "FUNCTION", "none", "public", "where", "LINE", "nonmutating", "static", "while", "optional",
|
||||
"struct", "override", "subscript", "postfix", "typealias", "precedence", "var", "prefix", "Protocol",
|
||||
"required", "right", "set", "Type", "unowned", "weak")
|
||||
);
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("array", "Array");
|
||||
typeMapping.put("List", "Array");
|
||||
typeMapping.put("map", "Dictionary");
|
||||
typeMapping.put("date", "NSDate");
|
||||
typeMapping.put("Date", "NSDate");
|
||||
typeMapping.put("DateTime", "NSDate");
|
||||
typeMapping.put("boolean", "Bool");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("char", "Character");
|
||||
typeMapping.put("short", "Int");
|
||||
typeMapping.put("int", "Int");
|
||||
typeMapping.put("long", "Int");
|
||||
typeMapping.put("integer", "Int");
|
||||
typeMapping.put("Integer", "Int");
|
||||
typeMapping.put("float", "Float");
|
||||
typeMapping.put("number", "Double");
|
||||
typeMapping.put("double", "Double");
|
||||
typeMapping.put("object", "AnyObject");
|
||||
typeMapping.put("file", "NSData");
|
||||
|
||||
importMapping = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
private static String normalizePath(String path) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
int cursor = 0;
|
||||
Matcher matcher = PATH_PARAM_PATTERN.matcher(path);
|
||||
boolean found = matcher.find();
|
||||
while (found) {
|
||||
String stringBeforeMatch = path.substring(cursor, matcher.start());
|
||||
builder.append(stringBeforeMatch);
|
||||
|
||||
String group = matcher.group().substring(1, matcher.group().length() - 1);
|
||||
group = camelize(group, true);
|
||||
builder
|
||||
.append("{")
|
||||
.append(group)
|
||||
.append("}");
|
||||
|
||||
cursor = matcher.end();
|
||||
found = matcher.find();
|
||||
}
|
||||
|
||||
String stringAfterMatch = path.substring(cursor);
|
||||
builder.append(stringAfterMatch);
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "swift";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a swift client library.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name; // add an underscore to the name
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
Property inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
return "[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 toDefaultValue(Property p) {
|
||||
// nil
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toInstantiationType(Property p) {
|
||||
if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return "[String:" + inner + "]";
|
||||
} else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return "[" + inner + "]";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenProperty fromProperty(String name, Property p) {
|
||||
CodegenProperty codegenProperty = super.fromProperty(name, p);
|
||||
if (codegenProperty.isEnum) {
|
||||
List<Map<String, String>> swiftEnums = new ArrayList<Map<String, String>>();
|
||||
List<String> values = (List<String>) codegenProperty.allowableValues.get("values");
|
||||
for (String value : values) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("enum", StringUtils.capitalize(value));
|
||||
map.put("raw", value);
|
||||
swiftEnums.add(map);
|
||||
}
|
||||
codegenProperty.allowableValues.put("values", swiftEnums);
|
||||
codegenProperty.datatypeWithEnum =
|
||||
StringUtils.left(codegenProperty.datatypeWithEnum, codegenProperty.datatypeWithEnum.length() - "Enum".length());
|
||||
}
|
||||
return codegenProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultAPI";
|
||||
}
|
||||
return initialCaps(name) + "API";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions) {
|
||||
path = normalizePath(path);
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
parameters = Lists.newArrayList(Iterators.filter(parameters.iterator(), new Predicate<Parameter>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable Parameter parameter) {
|
||||
return !(parameter instanceof HeaderParameter);
|
||||
}
|
||||
}));
|
||||
operation.setParameters(parameters);
|
||||
return super.fromOperation(path, httpMethod, operation, definitions);
|
||||
}
|
||||
}
|
@ -25,6 +25,8 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class TizenClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected static String PREFIX = "Sami";
|
||||
protected Set<String> foundationClasses = new HashSet<String>();
|
||||
@ -265,6 +267,11 @@ public class TizenClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return$
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
|
@ -0,0 +1,28 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCodegen {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "typescript-angular";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a TypeScript AngurlarJS client library.";
|
||||
}
|
||||
|
||||
public TypeScriptAngularClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/typescript-angular";
|
||||
modelTemplateFiles.put("model.mustache", ".ts");
|
||||
apiTemplateFiles.put("api.mustache", ".ts");
|
||||
templateDir = "TypeScript-Angular";
|
||||
apiPackage = "API.Client";
|
||||
modelPackage = "API.Client";
|
||||
supportingFiles.add(new SupportingFile("api.d.mustache", apiPackage().replace('.', File.separatorChar), "api.d.ts"));
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
|
||||
public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "typescript-node";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a TypeScript nodejs client library.";
|
||||
}
|
||||
|
||||
public TypeScriptNodeClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/typescript-node";
|
||||
templateDir = "TypeScript-node";
|
||||
supportingFiles.add(new SupportingFile("api.mustache", null, "api.ts"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,291 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using RestSharp;
|
||||
using RestSharp.Extensions;
|
||||
|
||||
namespace {{packageName}}.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// API client is mainly responible for making the HTTP call to the API backend.
|
||||
/// </summary>
|
||||
public class ApiClient
|
||||
{
|
||||
private readonly Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiClient" /> class.
|
||||
/// </summary>
|
||||
/// <param name="basePath">The base path.</param>
|
||||
public ApiClient(String basePath="{{basePath}}")
|
||||
{
|
||||
BasePath = basePath;
|
||||
RestClient = new RestClient(BasePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the base path.
|
||||
/// </summary>
|
||||
/// <value>The base path</value>
|
||||
public string BasePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the RestClient.
|
||||
/// </summary>
|
||||
/// <value>An instance of the RestClient</value>
|
||||
public RestClient RestClient { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default header.
|
||||
/// </summary>
|
||||
public Dictionary<String, String> DefaultHeader
|
||||
{
|
||||
get { return _defaultHeaderMap; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes the HTTP request (Sync).
|
||||
/// </summary>
|
||||
/// <param name="path">URL path.</param>
|
||||
/// <param name="method">HTTP method.</param>
|
||||
/// <param name="queryParams">Query parameters.</param>
|
||||
/// <param name="postBody">HTTP body (POST request).</param>
|
||||
/// <param name="headerParams">Header parameters.</param>
|
||||
/// <param name="formParams">Form parameters.</param>
|
||||
/// <param name="fileParams">File parameters.</param>
|
||||
/// <param name="authSettings">Authentication settings.</param>
|
||||
/// <returns>Object</returns>
|
||||
public Object CallApi(String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
|
||||
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
|
||||
Dictionary<String, FileParameter> fileParams, String[] authSettings)
|
||||
{
|
||||
|
||||
var request = new RestRequest(path, method);
|
||||
|
||||
UpdateParamsForAuth(queryParams, headerParams, authSettings);
|
||||
|
||||
// add default header, if any
|
||||
foreach(var defaultHeader in _defaultHeaderMap)
|
||||
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
|
||||
// add header parameter, if any
|
||||
foreach(var param in headerParams)
|
||||
request.AddHeader(param.Key, param.Value);
|
||||
|
||||
// add query parameter, if any
|
||||
foreach(var param in queryParams)
|
||||
request.AddParameter(param.Key, param.Value, ParameterType.GetOrPost);
|
||||
|
||||
// add form parameter, if any
|
||||
foreach(var param in formParams)
|
||||
request.AddParameter(param.Key, param.Value, ParameterType.GetOrPost);
|
||||
|
||||
// add file parameter, if any
|
||||
foreach(var param in fileParams)
|
||||
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
|
||||
|
||||
if (postBody != null) // http body (model) parameter
|
||||
request.AddParameter("application/json", postBody, ParameterType.RequestBody);
|
||||
|
||||
return (Object)RestClient.Execute(request);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add default header.
|
||||
/// </summary>
|
||||
/// <param name="key">Header field name.</param>
|
||||
/// <param name="value">Header field value.</param>
|
||||
/// <returns></returns>
|
||||
public void AddDefaultHeader(string key, string value)
|
||||
{
|
||||
_defaultHeaderMap.Add(key, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Escape string (url-encoded).
|
||||
/// </summary>
|
||||
/// <param name="str">String to be escaped.</param>
|
||||
/// <returns>Escaped string.</returns>
|
||||
public string EscapeString(string str)
|
||||
{
|
||||
return RestSharp.Contrib.HttpUtility.UrlEncode(str);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create FileParameter based on Stream.
|
||||
/// </summary>
|
||||
/// <param name="name">Parameter name.</param>
|
||||
/// <param name="stream">Input stream.</param>
|
||||
/// <returns>FileParameter.</returns>
|
||||
public FileParameter ParameterToFile(string name, Stream stream)
|
||||
{
|
||||
if (stream is FileStream)
|
||||
return FileParameter.Create(name, stream.ReadAsBytes(), Path.GetFileName(((FileStream)stream).Name));
|
||||
else
|
||||
return FileParameter.Create(name, stream.ReadAsBytes(), "no_file_name_provided");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If parameter is DateTime, output in ISO8601 format.
|
||||
/// If parameter is a list of string, join the list with ",".
|
||||
/// Otherwise just return the string.
|
||||
/// </summary>
|
||||
/// <param name="obj">The parameter (header, path, query, form).</param>
|
||||
/// <returns>Formatted string.</returns>
|
||||
public string ParameterToString(object obj)
|
||||
{
|
||||
if (obj is DateTime)
|
||||
return ((DateTime)obj).ToString ("u");
|
||||
else if (obj is List<string>)
|
||||
return String.Join(",", (obj as List<string>).ToArray());
|
||||
else
|
||||
return Convert.ToString (obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserialize the JSON string into a proper object.
|
||||
/// </summary>
|
||||
/// <param name="content">HTTP body (e.g. string, JSON).</param>
|
||||
/// <param name="type">Object type.</param>
|
||||
/// <returns>Object representation of the JSON string.</returns>
|
||||
public object Deserialize(string content, Type type, IList<Parameter> headers=null)
|
||||
{
|
||||
if (type == typeof(Object)) // return an object
|
||||
{
|
||||
return content;
|
||||
}
|
||||
|
||||
if (type == typeof(Stream))
|
||||
{
|
||||
var filePath = String.IsNullOrEmpty(Configuration.TempFolderPath)
|
||||
? Path.GetTempPath()
|
||||
: Configuration.TempFolderPath;
|
||||
|
||||
var fileName = filePath + Guid.NewGuid();
|
||||
if (headers != null)
|
||||
{
|
||||
var regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$");
|
||||
var match = regex.Match(headers.ToString());
|
||||
if (match.Success)
|
||||
fileName = filePath + match.Value.Replace("\"", "").Replace("'", "");
|
||||
}
|
||||
File.WriteAllText(fileName, content);
|
||||
return new FileStream(fileName, FileMode.Open);
|
||||
|
||||
}
|
||||
|
||||
if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) // return a datetime object
|
||||
{
|
||||
return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
}
|
||||
|
||||
if (type == typeof(String) || type.Name.StartsWith("System.Nullable")) // return primitive type
|
||||
{
|
||||
return ConvertType(content, type);
|
||||
}
|
||||
|
||||
// at this point, it must be a model (json)
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject(content, type);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new ApiException(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialize an object into JSON string.
|
||||
/// </summary>
|
||||
/// <param name="obj">Object.</param>
|
||||
/// <returns>JSON string.</returns>
|
||||
public string Serialize(object obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
return obj != null ? JsonConvert.SerializeObject(obj) : null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ApiException(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the API key with prefix.
|
||||
/// </summary>
|
||||
/// <param name="apiKeyIdentifier">API key identifier (authentication scheme).</param>
|
||||
/// <returns>API key with prefix.</returns>
|
||||
public string GetApiKeyWithPrefix (string apiKeyIdentifier)
|
||||
{
|
||||
var apiKeyValue = "";
|
||||
Configuration.ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue);
|
||||
var apiKeyPrefix = "";
|
||||
if (Configuration.ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix))
|
||||
return apiKeyPrefix + " " + apiKeyValue;
|
||||
else
|
||||
return apiKeyValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update parameters based on authentication.
|
||||
/// </summary>
|
||||
/// <param name="queryParams">Query parameters.</param>
|
||||
/// <param name="headerParams">Header parameters.</param>
|
||||
/// <param name="authSettings">Authentication settings.</param>
|
||||
public void UpdateParamsForAuth(Dictionary<String, String> queryParams, Dictionary<String, String> headerParams, string[] authSettings)
|
||||
{
|
||||
if (authSettings == null || authSettings.Length == 0)
|
||||
return;
|
||||
|
||||
foreach (string auth in authSettings)
|
||||
{
|
||||
// determine which one to use
|
||||
switch(auth)
|
||||
{
|
||||
{{#authMethods}}
|
||||
case "{{name}}":
|
||||
{{#isApiKey}}{{#isKeyInHeader}}headerParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInHeader}}{{#isKeyInQuery}}queryParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}headerParams["Authorization"] = "Basic " + Base64Encode(Configuration.Username + ":" + Configuration.Password);{{/isBasic}}
|
||||
{{#isOAuth}}//TODO support oauth{{/isOAuth}}
|
||||
break;
|
||||
{{/authMethods}}
|
||||
default:
|
||||
//TODO show warning about security definition not found
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encode string in base64 format.
|
||||
/// </summary>
|
||||
/// <param name="text">String to be encoded.</param>
|
||||
/// <returns>Encoded string.</returns>
|
||||
public static string Base64Encode(string text)
|
||||
{
|
||||
var textByte = System.Text.Encoding.UTF8.GetBytes(text);
|
||||
return System.Convert.ToBase64String(textByte);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dynamically cast the object into target type.
|
||||
/// Ref: http://stackoverflow.com/questions/4925718/c-dynamic-runtime-cast
|
||||
/// </summary>
|
||||
/// <param name="source">Object to be casted</param>
|
||||
/// <param name="dest">Target type</param>
|
||||
/// <returns>Casted object</returns>
|
||||
public static Object ConvertType(Object source, Type dest) {
|
||||
return Convert.ChangeType(source, dest);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
|
||||
namespace {{packageName}}.Client {
|
||||
/// <summary>
|
||||
/// API Exception
|
||||
/// </summary>
|
||||
public class ApiException : Exception {
|
||||
/// <summary>
|
||||
/// Gets or sets the error code (HTTP status code)
|
||||
/// </summary>
|
||||
/// <value>The error code (HTTP status code).</value>
|
||||
public int ErrorCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the error content (body json object)
|
||||
/// </summary>
|
||||
/// <value>The error content (Http response body).</value>
|
||||
public Object ErrorContent { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="basePath">The base path.</param>
|
||||
public ApiException() {}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">HTTP status code.</param>
|
||||
/// <param name="message">Error message.</param>
|
||||
public ApiException(int errorCode, string message) : base(message) {
|
||||
this.ErrorCode = errorCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">HTTP status code.</param>
|
||||
/// <param name="message">Error message.</param>
|
||||
/// <param name="errorContent">Error content.</param>
|
||||
public ApiException(int errorCode, string message, Object errorContent = null) : base(message) {
|
||||
this.ErrorCode = errorCode;
|
||||
this.ErrorContent = errorContent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace {{packageName}}.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a set of configuration settings
|
||||
/// </summary>
|
||||
public class Configuration
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Version of the package.
|
||||
/// </summary>
|
||||
/// <value>Version of the package.</value>
|
||||
public const string Version = "{{packageVersion}}";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default API client for making HTTP calls.
|
||||
/// </summary>
|
||||
/// <value>The API client.</value>
|
||||
public static ApiClient DefaultApiClient = new ApiClient();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the username (HTTP basic authentication).
|
||||
/// </summary>
|
||||
/// <value>The username.</value>
|
||||
public static String Username { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the password (HTTP basic authentication).
|
||||
/// </summary>
|
||||
/// <value>The password.</value>
|
||||
public static String Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the API key based on the authentication name.
|
||||
/// </summary>
|
||||
/// <value>The API key.</value>
|
||||
public static Dictionary<String, String> ApiKey = new Dictionary<String, String>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
|
||||
/// </summary>
|
||||
/// <value>The prefix of the API key.</value>
|
||||
public static Dictionary<String, String> ApiKeyPrefix = new Dictionary<String, String>();
|
||||
|
||||
private static string _tempFolderPath = Path.GetTempPath();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the temporary folder path to store the files downloaded from the server.
|
||||
/// </summary>
|
||||
/// <value>Folder path.</value>
|
||||
public static String TempFolderPath
|
||||
{
|
||||
get { return _tempFolderPath; }
|
||||
|
||||
set
|
||||
{
|
||||
if (String.IsNullOrEmpty(value))
|
||||
{
|
||||
_tempFolderPath = value;
|
||||
return;
|
||||
}
|
||||
|
||||
// create the directory if it does not exist
|
||||
if (!Directory.Exists(value))
|
||||
Directory.CreateDirectory(value);
|
||||
|
||||
// check if the path contains directory separator at the end
|
||||
if (value[value.Length - 1] == Path.DirectorySeparatorChar)
|
||||
_tempFolderPath = value;
|
||||
else
|
||||
_tempFolderPath = value + Path.DirectorySeparatorChar;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string with essential information for debugging.
|
||||
/// </summary>
|
||||
public static String ToDebugReport()
|
||||
{
|
||||
String report = "C# SDK ({{packageName}}) Debug Report:\n";
|
||||
report += " OS: " + Environment.OSVersion + "\n";
|
||||
report += " .NET Framework Version: " + Assembly
|
||||
.GetExecutingAssembly()
|
||||
.GetReferencedAssemblies()
|
||||
.Where(x => x.Name == "System.Core").First().Version.ToString() + "\n";
|
||||
report += " Version of the API: {{version}}\n";
|
||||
report += " SDK Package Version: {{packageVersion}}\n";
|
||||
|
||||
return report;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
# Csharp-DotNet2
|
||||
|
||||
This generator creates C# code targeting the .Net 2.0 framework. The resulting DLLs can be used in places where .Net 2.0 is the maximum supported version, such as in the Unity3d.
|
||||
|
||||
## Dependencies
|
||||
- Mono compiler
|
||||
- Note: NuGet is downloaded by the mono compilation script and packages are installed with it. No dependency DLLs are bundled with this generator.
|
||||
|
||||
|
||||
|
@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using RestSharp;
|
||||
using {{packageName}}.Client;
|
||||
{{#hasImport}}using {{packageName}}.Model;
|
||||
{{/hasImport}}
|
||||
|
||||
namespace {{packageName}}.Api
|
||||
{
|
||||
{{#operations}}
|
||||
public interface I{{classname}}
|
||||
{
|
||||
{{#operation}}
|
||||
/// <summary>
|
||||
/// {{summary}} {{notes}}
|
||||
/// </summary>
|
||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
||||
{{/allParams}}/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
||||
{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
{{/operation}}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a collection of functions to interact with the API endpoints
|
||||
/// </summary>
|
||||
public class {{classname}} : I{{classname}}
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="{{classname}}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiClient"> an instance of ApiClient (optional)</param>
|
||||
/// <returns></returns>
|
||||
public {{classname}}(ApiClient apiClient = null)
|
||||
{
|
||||
if (apiClient == null) // use the default one in Configuration
|
||||
this.ApiClient = Configuration.DefaultApiClient;
|
||||
else
|
||||
this.ApiClient = apiClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="{{classname}}"/> class.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public {{classname}}(String basePath)
|
||||
{
|
||||
this.ApiClient = new ApiClient(basePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the base path of the API client.
|
||||
/// </summary>
|
||||
/// <param name="basePath">The base path</param>
|
||||
/// <value>The base path</value>
|
||||
public void SetBasePath(String basePath)
|
||||
{
|
||||
this.ApiClient.BasePath = basePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the base path of the API client.
|
||||
/// </summary>
|
||||
/// <param name="basePath">The base path</param>
|
||||
/// <value>The base path</value>
|
||||
public String GetBasePath(String basePath)
|
||||
{
|
||||
return this.ApiClient.BasePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the API client.
|
||||
/// </summary>
|
||||
/// <value>An instance of the ApiClient</param>
|
||||
public ApiClient ApiClient {get; set;}
|
||||
|
||||
{{#operation}}
|
||||
/// <summary>
|
||||
/// {{summary}} {{notes}}
|
||||
/// </summary>
|
||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
||||
{{/allParams}}/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
||||
public {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
|
||||
{
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}");
|
||||
{{/required}}{{/allParams}}
|
||||
|
||||
var path = "{{path}}";
|
||||
path = path.Replace("{format}", "json");
|
||||
{{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", ApiClient.ParameterToString({{{paramName}}}));
|
||||
{{/pathParams}}
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, FileParameter>();
|
||||
String postBody = null;
|
||||
|
||||
{{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // query parameter
|
||||
{{/queryParams}}
|
||||
{{#headerParams}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // header parameter
|
||||
{{/headerParams}}
|
||||
{{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", ApiClient.ParameterToFile("{{baseName}}", {{paramName}}));{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
|
||||
{{/formParams}}
|
||||
{{#bodyParam}}postBody = ApiClient.Serialize({{paramName}}); // http body (model) parameter
|
||||
{{/bodyParam}}
|
||||
|
||||
// authentication setting, if any
|
||||
String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||
|
||||
if (((int)response.StatusCode) >= 400)
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content);
|
||||
else if (((int)response.StatusCode) == 0)
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.ErrorMessage, response.ErrorMessage);
|
||||
|
||||
{{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response.Content, typeof({{{returnType}}}), response.Headers);{{/returnType}}{{^returnType}}return;{{/returnType}}
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
wget -nc https://nuget.org/nuget.exe;
|
||||
mozroots --import --sync
|
||||
mono nuget.exe install vendor/packages.config -o vendor;
|
||||
mkdir -p bin;
|
||||
mcs -sdk:2 -r:vendor/Newtonsoft.Json.7.0.1/lib/net20/Newtonsoft.Json.dll,\
|
||||
vendor/RestSharp.Net2.1.1.11/lib/net20/RestSharp.Net2.dll,\
|
||||
System.Runtime.Serialization.dll \
|
||||
-target:library \
|
||||
-out:bin/{{packageName}}.dll \
|
||||
-recurse:src/*.cs \
|
||||
-doc:bin/{{packageName}}.xml \
|
||||
-platform:anycpu
|
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
namespace {{packageName}}.Model {
|
||||
|
||||
/// <summary>
|
||||
/// {{description}}
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class {{classname}}{{#parent}} : {{{parent}}}{{/parent}} {
|
||||
{{#vars}}
|
||||
/// <summary>
|
||||
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
||||
/// </summary>{{#description}}
|
||||
/// <value>{{{description}}}</value>{{/description}}
|
||||
[DataMember(Name="{{baseName}}", EmitDefaultValue=false)]
|
||||
[JsonProperty(PropertyName = "{{baseName}}")]
|
||||
public {{{datatype}}} {{name}} { get; set; }
|
||||
|
||||
{{/vars}}
|
||||
|
||||
/// <summary>
|
||||
/// Get the string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString() {
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class {{classname}} {\n");
|
||||
{{#vars}}
|
||||
sb.Append(" {{name}}: ").Append({{name}}).Append("\n");
|
||||
{{/vars}}
|
||||
sb.Append("}\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the JSON string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>JSON string presentation of the object</returns>
|
||||
public {{#parent}} new {{/parent}}string ToJson() {
|
||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
}
|
||||
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="RestSharp.Net2" version="1.1.11" targetFramework="net20" developmentDependency="true" />
|
||||
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net20" developmentDependency="true" />
|
||||
</packages>
|
@ -22,6 +22,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@ -39,6 +40,7 @@ import {{invokerPackage}}.auth.HttpBasicAuth;
|
||||
import {{invokerPackage}}.auth.ApiKeyAuth;
|
||||
import {{invokerPackage}}.auth.OAuth;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class ApiClient {
|
||||
private Map<String, Client> hostMap = new HashMap<String, Client>();
|
||||
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
@ -238,6 +240,62 @@ public class ApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Format to {@code Pair} objects.
|
||||
*/
|
||||
public List<Pair> parameterToPairs(String collectionFormat, String name, Object value){
|
||||
List<Pair> params = new ArrayList<Pair>();
|
||||
|
||||
// preconditions
|
||||
if (name == null || name.isEmpty() || value == null) return params;
|
||||
|
||||
Collection valueCollection = null;
|
||||
if (value instanceof Collection) {
|
||||
valueCollection = (Collection) value;
|
||||
} else {
|
||||
params.add(new Pair(name, parameterToString(value)));
|
||||
return params;
|
||||
}
|
||||
|
||||
if (valueCollection.isEmpty()){
|
||||
return params;
|
||||
}
|
||||
|
||||
// get the collection format
|
||||
collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
||||
|
||||
// create the params based on the collection format
|
||||
if (collectionFormat.equals("multi")) {
|
||||
for (Object item : valueCollection) {
|
||||
params.add(new Pair(name, parameterToString(item)));
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
String delimiter = ",";
|
||||
|
||||
if (collectionFormat.equals("csv")) {
|
||||
delimiter = ",";
|
||||
} else if (collectionFormat.equals("ssv")) {
|
||||
delimiter = " ";
|
||||
} else if (collectionFormat.equals("tsv")) {
|
||||
delimiter = "\t";
|
||||
} else if (collectionFormat.equals("pipes")) {
|
||||
delimiter = "|";
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder() ;
|
||||
for (Object item : valueCollection) {
|
||||
sb.append(delimiter);
|
||||
sb.append(parameterToString(item));
|
||||
}
|
||||
|
||||
params.add(new Pair(name, sb.substring(1)));
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the Accept header's value from the given accepts array:
|
||||
* if JSON exists in the given array, use it;
|
||||
@ -299,7 +357,7 @@ public class ApiClient {
|
||||
}
|
||||
else if(String.class.equals(cls)) {
|
||||
if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1)
|
||||
return json.substring(1, json.length() - 2);
|
||||
return json.substring(1, json.length() - 1);
|
||||
else
|
||||
return json;
|
||||
}
|
||||
@ -341,23 +399,25 @@ public class ApiClient {
|
||||
* @param authNames The authentications to apply
|
||||
* @return The response body in type of string
|
||||
*/
|
||||
public String invokeAPI(String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String accept, String contentType, String[] authNames) throws ApiException {
|
||||
public String invokeAPI(String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String accept, String contentType, String[] authNames) throws ApiException {
|
||||
updateParamsForAuth(authNames, queryParams, headerParams);
|
||||
|
||||
Client client = getClient();
|
||||
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(String key : queryParams.keySet()) {
|
||||
String value = queryParams.get(key);
|
||||
if (value != null){
|
||||
if(b.toString().length() == 0)
|
||||
b.append("?");
|
||||
else
|
||||
b.append("?");
|
||||
if (queryParams != null){
|
||||
for (Pair queryParam : queryParams){
|
||||
if (!queryParam.getName().isEmpty()) {
|
||||
b.append(escapeString(queryParam.getName()));
|
||||
b.append("=");
|
||||
b.append(escapeString(queryParam.getValue()));
|
||||
b.append("&");
|
||||
b.append(escapeString(key)).append("=").append(escapeString(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
String querystring = b.toString();
|
||||
|
||||
String querystring = b.substring(0, b.length() - 1);
|
||||
|
||||
Builder builder;
|
||||
if (accept == null)
|
||||
@ -421,10 +481,10 @@ public class ApiClient {
|
||||
throw new ApiException(500, "unknown method type " + method);
|
||||
}
|
||||
|
||||
if(response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) {
|
||||
if(response.getStatusInfo() == ClientResponse.Status.NO_CONTENT) {
|
||||
return null;
|
||||
}
|
||||
else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
|
||||
else if(response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
|
||||
if(response.hasEntity()) {
|
||||
return (String) response.getEntity(String.class);
|
||||
}
|
||||
@ -445,7 +505,7 @@ public class ApiClient {
|
||||
}
|
||||
}
|
||||
throw new ApiException(
|
||||
response.getClientResponseStatus().getStatusCode(),
|
||||
response.getStatusInfo().getStatusCode(),
|
||||
message,
|
||||
response.getHeaders(),
|
||||
respBody);
|
||||
@ -457,7 +517,7 @@ public class ApiClient {
|
||||
*
|
||||
* @param authNames The authentications to apply
|
||||
*/
|
||||
private void updateParamsForAuth(String[] authNames, Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
private void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams) {
|
||||
for (String authName : authNames) {
|
||||
Authentication auth = authentications.get(authName);
|
||||
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package {{invokerPackage}};
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class Configuration {
|
||||
private static ApiClient defaultApiClient = new ApiClient();
|
||||
|
||||
|
@ -7,6 +7,7 @@ import com.fasterxml.jackson.core.JsonGenerator.Feature;
|
||||
|
||||
import com.fasterxml.jackson.datatype.joda.*;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class JsonUtil {
|
||||
public static ObjectMapper mapper;
|
||||
|
||||
|
@ -0,0 +1,39 @@
|
||||
package {{invokerPackage}};
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class Pair {
|
||||
private String name = "";
|
||||
private String value = "";
|
||||
|
||||
public Pair (String name, String value) {
|
||||
setName(name);
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
private void setName(String name) {
|
||||
if (!isValidString(name)) return;
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private void setValue(String value) {
|
||||
if (!isValidString(value)) return;
|
||||
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
private boolean isValidString(String arg) {
|
||||
if (arg == null) return false;
|
||||
if (arg.trim().isEmpty()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package {{invokerPackage}};
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class StringUtil {
|
||||
/**
|
||||
* Check if the given array contains the given value (with case-insensitive comparison).
|
||||
|
@ -3,6 +3,7 @@ package {{package}};
|
||||
import {{invokerPackage}}.ApiException;
|
||||
import {{invokerPackage}}.ApiClient;
|
||||
import {{invokerPackage}}.Configuration;
|
||||
import {{invokerPackage}}.Pair;
|
||||
|
||||
import {{modelPackage}}.*;
|
||||
|
||||
@ -20,24 +21,25 @@ import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
{{#operations}}
|
||||
public class {{classname}} {
|
||||
private ApiClient apiClient;
|
||||
private ApiClient {{localVariablePrefix}}apiClient;
|
||||
|
||||
public {{classname}}() {
|
||||
this(Configuration.getDefaultApiClient());
|
||||
}
|
||||
|
||||
public {{classname}}(ApiClient apiClient) {
|
||||
this.apiClient = apiClient;
|
||||
this.{{localVariablePrefix}}apiClient = apiClient;
|
||||
}
|
||||
|
||||
public ApiClient getApiClient() {
|
||||
return apiClient;
|
||||
return {{localVariablePrefix}}apiClient;
|
||||
}
|
||||
|
||||
public void setApiClient(ApiClient apiClient) {
|
||||
this.apiClient = apiClient;
|
||||
this.{{localVariablePrefix}}apiClient = apiClient;
|
||||
}
|
||||
|
||||
{{#operation}}
|
||||
@ -48,7 +50,7 @@ public class {{classname}} {
|
||||
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||
*/
|
||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
||||
Object {{localVariablePrefix}}postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
if ({{paramName}} == null) {
|
||||
@ -57,61 +59,61 @@ public class {{classname}} {
|
||||
{{/required}}{{/allParams}}
|
||||
|
||||
// create path and map variables
|
||||
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}
|
||||
.replaceAll("\\{" + "{{paramName}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||
String {{localVariablePrefix}}path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}
|
||||
.replaceAll("\\{" + "{{baseName}}" + "\\}", {{localVariablePrefix}}apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
List<Pair> {{localVariablePrefix}}queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> {{localVariablePrefix}}headerParams = new HashMap<String, String>();
|
||||
Map<String, String> {{localVariablePrefix}}formParams = new HashMap<String, String>();
|
||||
|
||||
{{#queryParams}}if ({{paramName}} != null)
|
||||
queryParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
||||
{{#queryParams}}
|
||||
{{localVariablePrefix}}queryParams.addAll({{localVariablePrefix}}apiClient.parameterToPairs("{{#collectionFormat}}{{{collectionFormat}}}{{/collectionFormat}}", "{{baseName}}", {{paramName}}));
|
||||
{{/queryParams}}
|
||||
|
||||
{{#headerParams}}if ({{paramName}} != null)
|
||||
headerParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
||||
{{localVariablePrefix}}headerParams.put("{{baseName}}", {{localVariablePrefix}}apiClient.parameterToString({{paramName}}));
|
||||
{{/headerParams}}
|
||||
|
||||
final String[] accepts = {
|
||||
final String[] {{localVariablePrefix}}accepts = {
|
||||
{{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}
|
||||
};
|
||||
final String accept = apiClient.selectHeaderAccept(accepts);
|
||||
final String {{localVariablePrefix}}accept = {{localVariablePrefix}}apiClient.selectHeaderAccept({{localVariablePrefix}}accepts);
|
||||
|
||||
final String[] contentTypes = {
|
||||
final String[] {{localVariablePrefix}}contentTypes = {
|
||||
{{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}
|
||||
};
|
||||
final String contentType = apiClient.selectHeaderContentType(contentTypes);
|
||||
final String {{localVariablePrefix}}contentType = {{localVariablePrefix}}apiClient.selectHeaderContentType({{localVariablePrefix}}contentTypes);
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
boolean hasFields = false;
|
||||
FormDataMultiPart mp = new FormDataMultiPart();
|
||||
if({{localVariablePrefix}}contentType.startsWith("multipart/form-data")) {
|
||||
boolean {{localVariablePrefix}}hasFields = false;
|
||||
FormDataMultiPart {{localVariablePrefix}}mp = new FormDataMultiPart();
|
||||
{{#formParams}}{{#notFile}}
|
||||
if ({{paramName}} != null) {
|
||||
hasFields = true;
|
||||
mp.field("{{baseName}}", apiClient.parameterToString({{paramName}}), MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
{{localVariablePrefix}}hasFields = true;
|
||||
{{localVariablePrefix}}mp.field("{{baseName}}", {{localVariablePrefix}}apiClient.parameterToString({{paramName}}), MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
}
|
||||
{{/notFile}}{{#isFile}}
|
||||
if ({{paramName}} != null) {
|
||||
hasFields = true;
|
||||
mp.field("{{baseName}}", {{paramName}}.getName());
|
||||
mp.bodyPart(new FileDataBodyPart("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE));
|
||||
{{localVariablePrefix}}hasFields = true;
|
||||
{{localVariablePrefix}}mp.field("{{baseName}}", {{paramName}}.getName());
|
||||
{{localVariablePrefix}}mp.bodyPart(new FileDataBodyPart("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE));
|
||||
}
|
||||
{{/isFile}}{{/formParams}}
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
if({{localVariablePrefix}}hasFields)
|
||||
{{localVariablePrefix}}postBody = {{localVariablePrefix}}mp;
|
||||
}
|
||||
else {
|
||||
{{#formParams}}{{#notFile}}if ({{paramName}} != null)
|
||||
formParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));{{/notFile}}
|
||||
{{localVariablePrefix}}formParams.put("{{baseName}}", {{localVariablePrefix}}apiClient.parameterToString({{paramName}}));{{/notFile}}
|
||||
{{/formParams}}
|
||||
}
|
||||
|
||||
try {
|
||||
String[] authNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
||||
String response = apiClient.invokeAPI(path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
|
||||
if(response != null){
|
||||
return {{#returnType}}({{{returnType}}}) apiClient.deserialize(response, "{{returnContainer}}", {{returnBaseType}}.class){{/returnType}};
|
||||
String[] {{localVariablePrefix}}authNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
||||
String {{localVariablePrefix}}response = {{localVariablePrefix}}apiClient.invokeAPI({{localVariablePrefix}}path, "{{httpMethod}}", {{localVariablePrefix}}queryParams, {{localVariablePrefix}}postBody, {{localVariablePrefix}}headerParams, {{localVariablePrefix}}formParams, {{localVariablePrefix}}accept, {{localVariablePrefix}}contentType, {{localVariablePrefix}}authNames);
|
||||
if({{localVariablePrefix}}response != null){
|
||||
return {{#returnType}}({{{returnType}}}) {{localVariablePrefix}}apiClient.deserialize({{localVariablePrefix}}response, "{{returnContainer}}", {{returnBaseType}}.class){{/returnType}};
|
||||
}
|
||||
else {
|
||||
return {{#returnType}}null{{/returnType}};
|
||||
|
@ -3,6 +3,7 @@ package {{invokerPackage}};
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class ApiException extends Exception {
|
||||
private int code = 0;
|
||||
private String message = null;
|
||||
|
@ -1,7 +1,11 @@
|
||||
package {{invokerPackage}}.auth;
|
||||
|
||||
import java.util.Map;
|
||||
import {{invokerPackage}}.Pair;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class ApiKeyAuth implements Authentication {
|
||||
private final String location;
|
||||
private final String paramName;
|
||||
@ -39,7 +43,7 @@ public class ApiKeyAuth implements Authentication {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
|
||||
String value;
|
||||
if (apiKeyPrefix != null) {
|
||||
value = apiKeyPrefix + " " + apiKey;
|
||||
@ -47,7 +51,7 @@ public class ApiKeyAuth implements Authentication {
|
||||
value = apiKey;
|
||||
}
|
||||
if (location == "query") {
|
||||
queryParams.put(paramName, value);
|
||||
queryParams.add(new Pair(paramName, value));
|
||||
} else if (location == "header") {
|
||||
headerParams.put(paramName, value);
|
||||
}
|
||||
|
@ -1,8 +1,12 @@
|
||||
package {{invokerPackage}}.auth;
|
||||
|
||||
import java.util.Map;
|
||||
import {{invokerPackage}}.Pair;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public interface Authentication {
|
||||
/** Apply authentication settings to header and query params. */
|
||||
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams);
|
||||
void applyToParams(List<Pair> queryParams, Map<String, String> headerParams);
|
||||
}
|
||||
|
@ -1,10 +1,14 @@
|
||||
package {{invokerPackage}}.auth;
|
||||
|
||||
import {{invokerPackage}}.Pair;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class HttpBasicAuth implements Authentication {
|
||||
private String username;
|
||||
private String password;
|
||||
@ -26,7 +30,7 @@ public class HttpBasicAuth implements Authentication {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
try {
|
||||
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
|
||||
|
@ -1,10 +1,14 @@
|
||||
package {{invokerPackage}}.auth;
|
||||
|
||||
import java.util.Map;
|
||||
import {{invokerPackage}}.Pair;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class OAuth implements Authentication {
|
||||
@Override
|
||||
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
|
||||
// TODO: support oauth
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}")
|
@ -3,6 +3,9 @@ package {{package}};
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
{{#serializableModel}}
|
||||
import java.io.Serializable;{{/serializableModel}}
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
{{#models}}
|
||||
@ -12,7 +15,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
@ApiModel(description = "{{{description}}}")
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{>generatedAnnotation}}
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
public enum {{datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
||||
|
@ -0,0 +1,8 @@
|
||||
# Swagger Inflector
|
||||
|
||||
Run with
|
||||
|
||||
```
|
||||
mvn package jetty:run
|
||||
``
|
||||
|
@ -0,0 +1,28 @@
|
||||
package {{invokerPackage}};
|
||||
|
||||
import io.swagger.inflector.models.RequestContext;
|
||||
import io.swagger.inflector.models.ResponseContext;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import {{modelPackage}}.*;
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
{{#operations}}
|
||||
public class {{classname}} {
|
||||
|
||||
{{#operation}}
|
||||
public ResponseContext {{nickname}}(RequestContext request {{#allParams}},{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{/allParams}})
|
||||
{
|
||||
return new ResponseContext().status(Status.INTERNAL_SERVER_ERROR).entity( "Not implemented" );
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
|
@ -0,0 +1 @@
|
||||
{{#isBodyParam}}{{{dataType}}} {{paramName}}{{/isBodyParam}}
|
@ -0,0 +1 @@
|
||||
{{#isFormParam}}{{#notFile}}{{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}FormDataContentDisposition fileDetail{{/isFile}}{{/isFormParam}}
|
@ -0,0 +1 @@
|
||||
@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}")
|
@ -0,0 +1 @@
|
||||
{{#isHeaderParam}}{{{dataType}}} {{paramName}}{{/isHeaderParam}}
|
@ -0,0 +1,6 @@
|
||||
controllerPackage: {{invokerPackage}}
|
||||
modelPackage: {{modelPackage}}
|
||||
swaggerUrl: ./src/main/swagger/swagger.json
|
||||
modelMappings:
|
||||
{{#models}}{{#model}}{{classname}} : {{modelPackage}}.{{classname}}{{/model}}
|
||||
{{/models}}
|
@ -0,0 +1,52 @@
|
||||
package {{package}};
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
{{#models}}
|
||||
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
@ApiModel(description = "{{{description}}}")
|
||||
{{>generatedAnnotation}}
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
public enum {{datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
||||
};
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}}
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
@JsonProperty("{{name}}")
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
|
||||
{{/vars}}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#parent}}sb.append(" " + super.toString()).append("\n");{{/parent}}
|
||||
{{#vars}}sb.append(" {{name}}: ").append({{name}}).append("\n");
|
||||
{{/vars}}sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
@ -0,0 +1 @@
|
||||
{{#isPathParam}}{{{dataType}}} {{paramName}}{{/isPathParam}}
|
@ -0,0 +1,174 @@
|
||||
<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">
|
||||
<parent>
|
||||
<groupId>org.sonatype.oss</groupId>
|
||||
<artifactId>oss-parent</artifactId>
|
||||
<version>5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<prerequisites>
|
||||
<maven>2.2.0</maven>
|
||||
</prerequisites>
|
||||
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<directory>target</directory>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/logback.xml</exclude>
|
||||
</excludes>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<mode>development</mode>
|
||||
<url>${project.url}</url>
|
||||
<implementation-version>${project.version}</implementation-version>
|
||||
<package>io.swagger</package>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
<configuration>
|
||||
<monitoredDirName>.</monitoredDirName>
|
||||
<scanTargets>
|
||||
<scanTarget>inflector.yaml</scanTarget>
|
||||
<scanTarget>src/main/swagger/swagger.yaml</scanTarget>
|
||||
</scanTargets>
|
||||
<scanIntervalSeconds>1</scanIntervalSeconds>
|
||||
<webApp>
|
||||
<contextPath>/</contextPath>
|
||||
</webApp>
|
||||
<httpConnector>
|
||||
<port>8080</port>
|
||||
<idleTimeout>60000</idleTimeout>
|
||||
</httpConnector>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<!-- JSON -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>2.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-joda</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<!-- Jersey -->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.containers</groupId>
|
||||
<artifactId>jersey-container-servlet-core</artifactId>
|
||||
<version>${jersey2-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-multipart</artifactId>
|
||||
<version>${jersey2-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.core</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<version>${jersey2-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>${servlet-api-version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Logging -->
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
<version>${logback-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-ext</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Utils -->
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>${commons-lang-version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- http client -->
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-inflector</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<swagger-core-version>1.5.0</swagger-core-version>
|
||||
<swagger-parser-version>1.0.8</swagger-parser-version>
|
||||
<jackson-version>2.4.2</jackson-version>
|
||||
<joda-time-version>2.2</joda-time-version>
|
||||
<joda-version>1.2</joda-version>
|
||||
<jetty-version>9.2.9.v20150224</jetty-version>
|
||||
<jersey2-version>2.6</jersey2-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
<commons-io-version>2.4</commons-io-version>
|
||||
<commons-lang-version>2.4</commons-lang-version>
|
||||
<commons-csv-version>1.1</commons-csv-version>
|
||||
<logback-version>1.0.1</logback-version>
|
||||
<junit-version>4.8.2</junit-version>
|
||||
<slf4j-version>1.6.3</slf4j-version>
|
||||
</properties>
|
||||
</project>
|
@ -0,0 +1 @@
|
||||
{{#isQueryParam}}{{{dataType}}} {{paramName}}{{/isQueryParam}}
|
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
|
||||
<servlet>
|
||||
<servlet-name>swagger-inflector</servlet-name>
|
||||
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
|
||||
<init-param>
|
||||
<param-name>javax.ws.rs.Application</param-name>
|
||||
<param-value>io.swagger.inflector.SwaggerInflector</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>swagger-inflector</servlet-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
<filter>
|
||||
<filter-name>CORSFilter</filter-name>
|
||||
<filter-class>io.swagger.inflector.utils.CORSFilter</filter-class>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>CORSFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
</web-app>
|
@ -1,5 +1,6 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class ApiException extends Exception{
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
|
@ -3,6 +3,7 @@ package {{apiPackage}};
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
{{>generatedAnnotation}}
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class NotFoundException extends ApiException {
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
|
@ -26,6 +26,7 @@ import javax.ws.rs.*;
|
||||
{{#hasConsumes}}@Consumes({ {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}}
|
||||
{{#hasProduces}}@Produces({ {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}}
|
||||
@io.swagger.annotations.Api(value = "/{{baseName}}", description = "the {{baseName}} API")
|
||||
{{>generatedAnnotation}}
|
||||
{{#operations}}
|
||||
public class {{classname}} {
|
||||
|
||||
|
@ -18,6 +18,7 @@ import com.sun.jersey.multipart.FormDataParam;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
{{#operations}}
|
||||
public abstract class {{classname}}Service {
|
||||
{{#operation}}
|
||||
|
@ -3,6 +3,7 @@ package {{package}}.factories;
|
||||
import {{package}}.{{classname}}Service;
|
||||
import {{package}}.impl.{{classname}}ServiceImpl;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class {{classname}}ServiceFactory {
|
||||
|
||||
private final static {{classname}}Service service = new {{classname}}ServiceImpl();
|
||||
|
@ -18,6 +18,7 @@ import com.sun.jersey.multipart.FormDataParam;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
{{#operations}}
|
||||
public class {{classname}}ServiceImpl extends {{classname}}Service {
|
||||
{{#operation}}
|
||||
|
@ -0,0 +1 @@
|
||||
@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}")
|
@ -12,6 +12,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
@ApiModel(description = "{{{description}}}")
|
||||
{{>generatedAnnotation}}
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
public enum {{datatypeWithEnum}} {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user