Merge branch 'master' into java-global-security

This commit is contained in:
xhh
2015-10-15 17:57:27 +08:00
44 changed files with 1056 additions and 289 deletions

View File

@@ -1044,7 +1044,7 @@ public class DefaultCodegen {
}
}
for (String i : imports) {
if (!defaultIncludes.contains(i) && !languageSpecificPrimitives.contains(i)) {
if (needToImport(i)) {
op.imports.add(i);
}
}
@@ -1317,6 +1317,12 @@ public class DefaultCodegen {
return secs;
}
protected boolean needToImport(String type) {
return !defaultIncludes.contains(type)
&& !languageSpecificPrimitives.contains(type)
&& type.indexOf(".") < 0;
}
protected List<Map<String, Object>> toExamples(Map<String, Object> examples) {
if (examples == null) {
return null;
@@ -1420,7 +1426,7 @@ public class DefaultCodegen {
}
private void addImport(CodegenModel m, String type) {
if (type != null && !languageSpecificPrimitives.contains(type) && !defaultIncludes.contains(type)) {
if (type != null && needToImport(type)) {
m.imports.add(type);
}
}
@@ -1599,8 +1605,8 @@ public class DefaultCodegen {
* @return sanitized string
*/
public String sanitizeName(String name) {
// NOTE: performance wise, we should have written with 2 replaceAll to replace desired
// character with _ or empty character. Below aims to spell out different cases we've
// NOTE: performance wise, we should have written with 2 replaceAll to replace desired
// character with _ or empty character. Below aims to spell out different cases we've
// encountered so far and hopefully make it easier for others to add more special
// cases in the future.
@@ -1623,7 +1629,7 @@ public class DefaultCodegen {
// input name and age => input_name_and_age
name = name.replaceAll(" ", "_");
// remove everything else other than word, number and _
// $php_variable => php_variable
return name.replaceAll("[^a-zA-Z0-9_]", "");

View File

@@ -37,6 +37,8 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
protected String artifactVersion = "1.0.0";
protected String sourceFolder = "src/main/java";
protected String localVariablePrefix = "";
protected boolean fullJavaUtil = false;
protected String javaUtilPrefix = "";
protected Boolean serializableModel = false;
public JavaClientCodegen() {
@@ -81,6 +83,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC));
cliOptions.add(new CliOption(CodegenConstants.LOCAL_VARIABLE_PREFIX, CodegenConstants.LOCAL_VARIABLE_PREFIX_DESC));
cliOptions.add(new CliOption(CodegenConstants.SERIALIZABLE_MODEL, CodegenConstants.SERIALIZABLE_MODEL_DESC));
cliOptions.add(new CliOption("fullJavaUtil", "whether to use fully qualified name for classes under java.util (default to false)"));
supportedLibraries.put("<default>", "HTTP client: Jersey client 1.18. JSON processing: Jackson 2.4.2");
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.6");
@@ -107,7 +110,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override
public void processOpts() {
super.processOpts();
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
} else {
@@ -152,13 +155,42 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
// need to put back serializableModel (boolean) into additionalProperties as value in additionalProperties is string
additionalProperties.put(CodegenConstants.SERIALIZABLE_MODEL, serializableModel);
if (additionalProperties.containsKey("fullJavaUtil")) {
fullJavaUtil = Boolean.valueOf(additionalProperties.get("fullJavaUtil").toString());
}
if (fullJavaUtil) {
javaUtilPrefix = "java.util.";
}
additionalProperties.put("fullJavaUtil", fullJavaUtil);
additionalProperties.put("javaUtilPrefix", javaUtilPrefix);
if (fullJavaUtil) {
typeMapping.put("array", "java.util.List");
typeMapping.put("map", "java.util.Map");
typeMapping.put("DateTime", "java.util.Date");
typeMapping.remove("List");
importMapping.remove("Date");
importMapping.remove("Map");
importMapping.remove("HashMap");
importMapping.remove("Array");
importMapping.remove("ArrayList");
importMapping.remove("List");
importMapping.remove("Set");
importMapping.remove("DateTime");
instantiationTypes.put("array", "java.util.ArrayList");
instantiationTypes.put("map", "java.util.HashMap");
}
this.sanitizeConfig();
final String invokerFolder = (sourceFolder + File.separator + invokerPackage).replace(".", File.separator);
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
supportingFiles.add(new SupportingFile("build.gradle.mustache", "", "build.gradle"));
supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
supportingFiles.add(new SupportingFile("gradle.properties.mustache", "", "gradle.properties"));
supportingFiles.add(new SupportingFile("ApiClient.mustache", invokerFolder, "ApiClient.java"));
supportingFiles.add(new SupportingFile("StringUtil.mustache", invokerFolder, "StringUtil.java"));
final String authFolder = (sourceFolder + File.separator + invokerPackage + ".auth").replace(".", File.separator);
supportingFiles.add(new SupportingFile("auth/HttpBasicAuth.mustache", authFolder, "HttpBasicAuth.java"));
supportingFiles.add(new SupportingFile("auth/ApiKeyAuth.mustache", authFolder, "ApiKeyAuth.java"));
@@ -172,13 +204,11 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
supportingFiles.add(new SupportingFile("Pair.mustache", invokerFolder, "Pair.java"));
supportingFiles.add(new SupportingFile("auth/Authentication.mustache", authFolder, "Authentication.java"));
}
// library-specific files
if ("okhttp-gson".equals(getLibrary())) {
// the "okhttp-gson" library template requires "ApiCallback.mustache" for async call
supportingFiles.add(new SupportingFile("ApiCallback.mustache", invokerFolder, "ApiCallback.java"));
// "build.gradle" is for development with Gradle
supportingFiles.add(new SupportingFile("build.gradle.mustache", "", "build.gradle"));
// "build.sbt" is for development with SBT
supportingFiles.add(new SupportingFile("build.sbt.mustache", "", "build.sbt"));
} else if ("retrofit".equals(getLibrary())) {
@@ -189,25 +219,25 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
}
private void sanitizeConfig() {
// Sanitize any config options here. We also have to update the additionalProperties because
// 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(CodegenConstants.API_PACKAGE)) {
this.additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
}
this.setModelPackage(sanitizePackageName(modelPackage));
if (additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) {
this.additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);
}
this.setInvokerPackage(sanitizePackageName(invokerPackage));
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
this.additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
}
}
@Override
public String escapeReservedWord(String name) {
return "_" + name;
@@ -294,10 +324,22 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
public String toDefaultValue(Property p) {
if (p instanceof ArrayProperty) {
final ArrayProperty ap = (ArrayProperty) p;
return String.format("new ArrayList<%s>()", getTypeDeclaration(ap.getItems()));
final String pattern;
if (fullJavaUtil) {
pattern = "new java.util.ArrayList<%s>()";
} else {
pattern = "new ArrayList<%s>()";
}
return String.format(pattern, getTypeDeclaration(ap.getItems()));
} else if (p instanceof MapProperty) {
final MapProperty ap = (MapProperty) p;
return String.format("new HashMap<String, %s>()", getTypeDeclaration(ap.getAdditionalProperties()));
final String pattern;
if (fullJavaUtil) {
pattern = "new java.util.HashMap<String, %s>()";
} else {
pattern = "new HashMap<String, %s>()";
}
return String.format(pattern, getTypeDeclaration(ap.getAdditionalProperties()));
}
return super.toDefaultValue(p);
}
@@ -308,7 +350,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
String type = null;
if (typeMapping.containsKey(swaggerType)) {
type = typeMapping.get(swaggerType);
if (languageSpecificPrimitives.contains(type)) {
if (languageSpecificPrimitives.contains(type) || type.indexOf(".") >= 0) {
return type;
}
} else {
@@ -394,7 +436,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
}
return objs;
}
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
if("retrofit".equals(getLibrary())) {
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
@@ -418,6 +460,10 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
return objs;
}
protected boolean needToImport(String type) {
return super.needToImport(type) && type.indexOf(".") < 0;
}
private String findCommonPrefixOfVars(List<String> vars) {
String prefix = StringUtils.getCommonPrefix(vars.toArray(new String[vars.size()]));
// exclude trailing characters that should be part of a valid variable
@@ -426,7 +472,12 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
}
private String toEnumVarName(String value) {
return value.replaceAll("\\W+", "_").toUpperCase();
String var = value.replaceAll("\\W+", "_").toUpperCase();
if (var.matches("\\d.*")) {
return "_" + var;
} else {
return var;
}
}
private CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {

View File

@@ -6,16 +6,12 @@ import {{invokerPackage}}.Configuration;
import {{invokerPackage}}.Pair;
import {{invokerPackage}}.TypeRef;
import {{modelPackage}}.*;
import java.util.*;
{{#imports}}import {{import}};
{{/imports}}
import java.io.File;
import java.util.Map;
import java.util.HashMap;
{{^fullJavaUtil}}
import java.util.*;
{{/fullJavaUtil}}
{{>generatedAnnotation}}
{{#operations}}
@@ -59,9 +55,9 @@ public class {{classname}} {
.replaceAll("\\{" + "{{baseName}}" + "\\}", {{localVariablePrefix}}apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
// query params
List<Pair> {{localVariablePrefix}}queryParams = new ArrayList<Pair>();
Map<String, String> {{localVariablePrefix}}headerParams = new HashMap<String, String>();
Map<String, Object> {{localVariablePrefix}}formParams = new HashMap<String, Object>();
{{javaUtilPrefix}}List<Pair> {{localVariablePrefix}}queryParams = new {{javaUtilPrefix}}ArrayList<Pair>();
{{javaUtilPrefix}}Map<String, String> {{localVariablePrefix}}headerParams = new {{javaUtilPrefix}}HashMap<String, String>();
{{javaUtilPrefix}}Map<String, Object> {{localVariablePrefix}}formParams = new {{javaUtilPrefix}}HashMap<String, Object>();
{{#queryParams}}
{{localVariablePrefix}}queryParams.addAll({{localVariablePrefix}}apiClient.parameterToPairs("{{#collectionFormat}}{{{collectionFormat}}}{{/collectionFormat}}", "{{baseName}}", {{paramName}}));

View File

@@ -0,0 +1,107 @@
group = '{{groupId}}'
version = '{{artifactVersion}}'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
}
}
repositories {
jcenter()
}
if(hasProperty('target') && target == 'android') {
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 22
buildToolsVersion '22.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
// Rename the aar correctly
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
afterEvaluate {
android.libraryVariants.all { variant ->
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
task.description = "Create jar artifact for ${variant.name}"
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
artifacts.add('archives', task);
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
} else {
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
install {
repositories.mavenInstaller {
pom.artifactId = '{{artifactId}}'
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}
}
ext {
swagger_annotations_version = "1.5.0"
jackson_version = "2.4.2"
jersey_version = "1.18"
jodatime_version = "2.3"
junit_version = "4.8.1"
}
dependencies {
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
compile "com.sun.jersey:jersey-client:$jersey_version"
compile "com.sun.jersey.contribs:jersey-multipart:$jersey_version"
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
compile "joda-time:joda-time:$jodatime_version"
testCompile "junit:junit:$junit_version"
}

View File

@@ -0,0 +1,2 @@
# Uncomment to build for Android
#target = android

View File

@@ -6,16 +6,12 @@ import {{invokerPackage}}.Configuration;
import {{invokerPackage}}.Pair;
import {{invokerPackage}}.TypeRef;
import {{modelPackage}}.*;
import java.util.*;
{{#imports}}import {{import}};
{{/imports}}
import java.io.File;
import java.util.Map;
import java.util.HashMap;
{{^fullJavaUtil}}
import java.util.*;
{{/fullJavaUtil}}
{{>generatedAnnotation}}
{{#operations}}
@@ -58,9 +54,9 @@ public class {{classname}} {
.replaceAll("\\{" + "{{baseName}}" + "\\}", {{localVariablePrefix}}apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
// query params
List<Pair> {{localVariablePrefix}}queryParams = new ArrayList<Pair>();
Map<String, String> {{localVariablePrefix}}headerParams = new HashMap<String, String>();
Map<String, Object> {{localVariablePrefix}}formParams = new HashMap<String, Object>();
{{javaUtilPrefix}}List<Pair> {{localVariablePrefix}}queryParams = new {{javaUtilPrefix}}ArrayList<Pair>();
{{javaUtilPrefix}}Map<String, String> {{localVariablePrefix}}headerParams = new {{javaUtilPrefix}}HashMap<String, String>();
{{javaUtilPrefix}}Map<String, Object> {{localVariablePrefix}}formParams = new {{javaUtilPrefix}}HashMap<String, Object>();
{{#queryParams}}
{{localVariablePrefix}}queryParams.addAll({{localVariablePrefix}}apiClient.parameterToPairs("{{#collectionFormat}}{{{collectionFormat}}}{{/collectionFormat}}", "{{baseName}}", {{paramName}}));

View File

@@ -0,0 +1,107 @@
group = '{{groupId}}'
version = '{{artifactVersion}}'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
}
}
repositories {
jcenter()
}
if(hasProperty('target') && target == 'android') {
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 22
buildToolsVersion '22.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
// Rename the aar correctly
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
afterEvaluate {
android.libraryVariants.all { variant ->
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
task.description = "Create jar artifact for ${variant.name}"
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
artifacts.add('archives', task);
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
} else {
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
install {
repositories.mavenInstaller {
pom.artifactId = '{{artifactId}}'
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}
}
ext {
swagger_annotations_version = "1.5.0"
jackson_version = "2.4.2"
jersey_version = "2.6"
jodatime_version = "2.3"
junit_version = "4.8.1"
}
dependencies {
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
compile "org.glassfish.jersey.core:jersey-client:$jersey_version"
compile "org.glassfish.jersey.media:jersey-media-multipart:$jersey_version"
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
compile "joda-time:joda-time:$jodatime_version"
testCompile "junit:junit:$junit_version"
}

View File

@@ -6,22 +6,17 @@ import {{invokerPackage}}.ApiException;
import {{invokerPackage}}.Configuration;
import {{invokerPackage}}.Pair;
import {{modelPackage}}.*;
import com.google.gson.reflect.TypeToken;
import com.squareup.okhttp.Call;
import java.lang.reflect.Type;
import java.util.*;
{{#imports}}import {{import}};
{{/imports}}
import java.io.File;
import java.util.Map;
import java.util.HashMap;
import java.lang.reflect.Type;
{{^fullJavaUtil}}
import java.util.*;
{{/fullJavaUtil}}
{{#operations}}
public class {{classname}} {
@@ -58,15 +53,15 @@ public class {{classname}} {
String {{localVariablePrefix}}path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}
.replaceAll("\\{" + "{{baseName}}" + "\\}", {{localVariablePrefix}}apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
List<Pair> {{localVariablePrefix}}queryParams = new ArrayList<Pair>();{{#queryParams}}
{{javaUtilPrefix}}List<Pair> {{localVariablePrefix}}queryParams = new {{javaUtilPrefix}}ArrayList<Pair>();{{#queryParams}}
if ({{paramName}} != null)
{{localVariablePrefix}}queryParams.addAll({{localVariablePrefix}}apiClient.parameterToPairs("{{#collectionFormat}}{{{collectionFormat}}}{{/collectionFormat}}", "{{baseName}}", {{paramName}}));{{/queryParams}}
Map<String, String> {{localVariablePrefix}}headerParams = new HashMap<String, String>();{{#headerParams}}
{{javaUtilPrefix}}Map<String, String> {{localVariablePrefix}}headerParams = new {{javaUtilPrefix}}HashMap<String, String>();{{#headerParams}}
if ({{paramName}} != null)
{{localVariablePrefix}}headerParams.put("{{baseName}}", {{localVariablePrefix}}apiClient.parameterToString({{paramName}}));{{/headerParams}}
Map<String, Object> {{localVariablePrefix}}formParams = new HashMap<String, Object>();{{#formParams}}
{{javaUtilPrefix}}Map<String, Object> {{localVariablePrefix}}formParams = new {{javaUtilPrefix}}HashMap<String, Object>();{{#formParams}}
if ({{paramName}} != null)
{{localVariablePrefix}}formParams.put("{{baseName}}", {{paramName}});{{/formParams}}

View File

@@ -1,11 +1,89 @@
apply plugin: 'java'
apply plugin: 'maven'
group = '{{groupId}}'
version = '{{artifactVersion}}'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
}
}
repositories {
mavenCentral()
jcenter()
}
if(hasProperty('target') && target == 'android') {
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 22
buildToolsVersion '22.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
// Rename the aar correctly
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
afterEvaluate {
android.libraryVariants.all { variant ->
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
task.description = "Create jar artifact for ${variant.name}"
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
artifacts.add('archives', task);
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
} else {
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
install {
repositories.mavenInstaller {
pom.artifactId = '{{artifactId}}'
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}
}
dependencies {
@@ -15,17 +93,3 @@ dependencies {
compile 'com.brsanthu:migbase64:2.2'
testCompile 'junit:junit:4.8.1'
}
group = '{{groupId}}'
version = '{{artifactVersion}}'
install {
repositories.mavenInstaller {
pom.artifactId = '{{artifactId}}'
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}

View File

@@ -1,15 +1,16 @@
package {{package}};
import {{modelPackage}}.*;
import retrofit.Callback;
import retrofit.http.*;
import retrofit.mime.*;
import java.util.*;
{{#imports}}import {{import}};
{{/imports}}
{{^fullJavaUtil}}
import java.util.*;
{{/fullJavaUtil}}
{{#operations}}
public interface {{classname}} {
{{#operation}}
@@ -22,7 +23,7 @@ public interface {{classname}} {
*/
{{#formParams}}{{#-first}}
{{#isMultipart}}@Multipart{{/isMultipart}}{{^isMultipart}}@FormUrlEncoded{{/isMultipart}}{{/-first}}{{/formParams}}
@{{httpMethod}}("{{path}}")
@{{httpMethod}}("{{path}}")
{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}} {{nickname}}({{^allParams}});{{/allParams}}
{{#allParams}}{{>libraries/retrofit/queryParams}}{{>libraries/retrofit/pathParams}}{{>libraries/retrofit/headerParams}}{{>libraries/retrofit/bodyParams}}{{>libraries/retrofit/formParams}}{{#hasMore}}, {{/hasMore}}{{^hasMore}}
);{{/hasMore}}{{/allParams}}
@@ -31,15 +32,15 @@ public interface {{classname}} {
* {{summary}}
* Async method
{{#allParams}} * @param {{paramName}} {{description}}
{{/allParams}} * @param cb callback method
{{/allParams}} * @param cb callback method
* @return void
*/
{{#formParams}}{{#-first}}
{{#isMultipart}}@Multipart{{/isMultipart}}{{^isMultipart}}@FormUrlEncoded{{/isMultipart}}{{/-first}}{{/formParams}}
@{{httpMethod}}("{{path}}")
@{{httpMethod}}("{{path}}")
void {{nickname}}(
{{#allParams}}{{>libraries/retrofit/queryParams}}{{>libraries/retrofit/pathParams}}{{>libraries/retrofit/headerParams}}{{>libraries/retrofit/bodyParams}}{{>libraries/retrofit/formParams}}, {{/allParams}}Callback<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}> cb
);
);
{{/operation}}
}
{{/operations}}
{{/operations}}

View File

@@ -0,0 +1,103 @@
group = '{{groupId}}'
version = '{{artifactVersion}}'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
}
}
repositories {
jcenter()
}
if(hasProperty('target') && target == 'android') {
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 22
buildToolsVersion '22.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
// Rename the aar correctly
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
afterEvaluate {
android.libraryVariants.all { variant ->
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
task.description = "Create jar artifact for ${variant.name}"
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
artifacts.add('archives', task);
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
} else {
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
install {
repositories.mavenInstaller {
pom.artifactId = '{{artifactId}}'
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}
}
ext {
okhttp_version = "2.3.0"
oltu_version = "1.0.0"
retrofit_version = "1.9.0"
swagger_annotations_version = "1.5.0"
junit_version = "4.12"
}
dependencies {
compile "com.squareup.okhttp:okhttp:$okhttp_version"
compile "com.squareup.retrofit:retrofit:$retrofit_version"
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version"
testCompile "junit:junit:$junit_version"
}

View File

@@ -0,0 +1 @@
rootProject.name = "{{artifactId}}"

View File

@@ -3,7 +3,7 @@
/* tslint:disable:no-unused-variable member-ordering */
{{#operations}}
module {{package}} {
namespace {{package}} {
'use strict';
{{#description}}
@@ -16,7 +16,7 @@ module {{package}} {
static $inject: string[] = ['$http', '$httpParamSerializer'];
constructor(private $http: ng.IHttpService, basePath?: string, private $httpParamSerializer?: (any) => any) {
constructor(private $http: ng.IHttpService, basePath?: string, private $httpParamSerializer?: (d: any) => any) {
if (basePath) {
this.basePath = basePath;
}
@@ -24,16 +24,16 @@ module {{package}} {
{{#operation}}
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any ) : ng.IHttpPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> {
var path = this.basePath + '{{path}}';
let path = this.basePath + '{{path}}';
{{#pathParams}}
path = path.replace('{' + '{{baseName}}' + '}', String({{paramName}}));
{{/pathParams}}
var queryParameters: any = {};
var headerParams: any = {};
let queryParameters: any = {};
let headerParams: any = {};
{{#hasFormParams}}
var formParams: any = {};
let formParams: any = {};
{{/hasFormParams}}
{{#allParams}}
@@ -63,7 +63,7 @@ module {{package}} {
formParams['{{baseName}}'] = {{paramName}};
{{/formParams}}
var httpRequestParams: any = {
let httpRequestParams: any = {
method: '{{httpMethod}}',
url: path,
json: {{#hasFormParams}}false{{/hasFormParams}}{{^hasFormParams}}true{{/hasFormParams}},
@@ -76,7 +76,7 @@ module {{package}} {
};
if (extraHttpRequestParams) {
for (var k in extraHttpRequestParams) {
for (let k in extraHttpRequestParams) {
if (extraHttpRequestParams.hasOwnProperty(k)) {
httpRequestParams[k] = extraHttpRequestParams[k];
}

View File

@@ -1,6 +1,6 @@
/// <reference path="api.d.ts" />
module {{package}} {
namespace {{package}} {
'use strict';
{{#models}}
@@ -10,7 +10,7 @@ module {{package}} {
* {{{description}}}
*/
{{/description}}
export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
{{#vars}}
{{#description}}
@@ -23,7 +23,7 @@ module {{package}} {
}
{{#hasEnums}}
export module {{classname}} {
export namespace {{classname}} {
{{#vars}}
{{#isEnum}}

View File

@@ -27,7 +27,7 @@ export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
}
{{#hasEnums}}
export module {{classname}} {
export namespace {{classname}} {
{{#vars}}
{{#isEnum}}
export enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}}
@@ -157,15 +157,15 @@ export class {{classname}} {
{{#operation}}
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }> {
var path = this.url + this.basePath + '{{path}}';
let path = this.url + this.basePath + '{{path}}';
{{#pathParams}}
path = path.replace('{' + '{{baseName}}' + '}', String({{paramName}}));
{{/pathParams}}
var queryParameters: any = {};
var headerParams: any = {};
var formParams: any = {};
let queryParameters: any = {};
let headerParams: any = {};
let formParams: any = {};
{{#allParams}}{{#required}}
// verify required parameter '{{paramName}}' is set
@@ -183,7 +183,7 @@ export class {{classname}} {
headerParams['{{baseName}}'] = {{paramName}};
{{/headerParams}}
var useFormData = false;
let useFormData = false;
{{#formParams}}
if ({{paramName}} !== undefined) {
@@ -194,9 +194,9 @@ export class {{classname}} {
{{/isFile}}
{{/formParams}}
var deferred = promise.defer<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }>();
let deferred = promise.defer<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }>();
var requestOptions: request.Options = {
let requestOptions: request.Options = {
method: '{{httpMethod}}',
qs: queryParameters,
headers: headerParams,

View File

@@ -426,6 +426,7 @@
<module>samples/client/petstore/java/default</module>
<module>samples/client/petstore/java/jersey2</module>
<module>samples/client/petstore/java/okhttp-gson</module>
<module>samples/client/petstore/java/retrofit</module>
<module>samples/client/petstore/scala</module>
<module>samples/server/petstore/spring-mvc</module>
<!--module>samples/client/petstore/objc</module-->

View File

@@ -0,0 +1,107 @@
group = 'io.swagger'
version = '1.0.0'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
}
}
repositories {
jcenter()
}
if(hasProperty('target') && target == 'android') {
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 22
buildToolsVersion '22.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
// Rename the aar correctly
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
afterEvaluate {
android.libraryVariants.all { variant ->
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
task.description = "Create jar artifact for ${variant.name}"
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
artifacts.add('archives', task);
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
} else {
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
install {
repositories.mavenInstaller {
pom.artifactId = 'swagger-java-client'
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}
}
ext {
swagger_annotations_version = "1.5.0"
jackson_version = "2.4.2"
jersey_version = "1.18"
jodatime_version = "2.3"
junit_version = "4.8.1"
}
dependencies {
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
compile "com.sun.jersey:jersey-client:$jersey_version"
compile "com.sun.jersey.contribs:jersey-multipart:$jersey_version"
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
compile "joda-time:joda-time:$jodatime_version"
testCompile "junit:junit:$junit_version"
}

View File

@@ -0,0 +1,2 @@
# Uncomment to build for Android
#target = android

View File

@@ -0,0 +1 @@
rootProject.name = "swagger-java-client"

View File

@@ -6,18 +6,12 @@ import io.swagger.client.Configuration;
import io.swagger.client.Pair;
import io.swagger.client.TypeRef;
import io.swagger.client.model.*;
import java.util.*;
import io.swagger.client.model.Pet;
import java.io.File;
import java.io.File;
import java.util.Map;
import java.util.HashMap;
import java.util.*;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-01T23:05:28.119+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-09T21:30:27.235+08:00")
public class PetApi {
private ApiClient apiClient;
@@ -272,7 +266,7 @@ public class PetApi {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
String[] authNames = new String[] { "api_key", "petstore_auth" };
String[] authNames = new String[] { "petstore_auth", "api_key" };

View File

@@ -6,18 +6,12 @@ import io.swagger.client.Configuration;
import io.swagger.client.Pair;
import io.swagger.client.TypeRef;
import io.swagger.client.model.*;
import java.util.*;
import java.util.Map;
import io.swagger.client.model.Order;
import java.io.File;
import java.util.Map;
import java.util.HashMap;
import java.util.*;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-01T23:05:28.119+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-09T21:30:27.235+08:00")
public class StoreApi {
private ApiClient apiClient;

View File

@@ -6,18 +6,12 @@ import io.swagger.client.Configuration;
import io.swagger.client.Pair;
import io.swagger.client.TypeRef;
import io.swagger.client.model.*;
import java.util.*;
import io.swagger.client.model.User;
import java.util.*;
import java.io.File;
import java.util.Map;
import java.util.HashMap;
import java.util.*;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-01T23:05:28.119+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-09T21:30:27.235+08:00")
public class UserApi {
private ApiClient apiClient;

View File

@@ -10,7 +10,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@ApiModel(description = "")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-01T23:05:28.119+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-09T21:30:27.235+08:00")
public class Order {
private Long id = null;

View File

@@ -2,8 +2,8 @@ package io.swagger.client.model;
import io.swagger.client.StringUtil;
import io.swagger.client.model.Category;
import io.swagger.client.model.Tag;
import java.util.*;
import io.swagger.client.model.Tag;
@@ -12,7 +12,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@ApiModel(description = "")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-01T23:05:28.119+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-09T21:30:27.235+08:00")
public class Pet {
private Long id = null;

View File

@@ -0,0 +1,107 @@
group = 'io.swagger'
version = '1.0.0'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
}
}
repositories {
jcenter()
}
if(hasProperty('target') && target == 'android') {
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 22
buildToolsVersion '22.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
// Rename the aar correctly
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
afterEvaluate {
android.libraryVariants.all { variant ->
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
task.description = "Create jar artifact for ${variant.name}"
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
artifacts.add('archives', task);
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
} else {
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
install {
repositories.mavenInstaller {
pom.artifactId = 'swagger-petstore-jersey2'
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}
}
ext {
swagger_annotations_version = "1.5.0"
jackson_version = "2.4.2"
jersey_version = "2.6"
jodatime_version = "2.3"
junit_version = "4.8.1"
}
dependencies {
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
compile "org.glassfish.jersey.core:jersey-client:$jersey_version"
compile "org.glassfish.jersey.media:jersey-media-multipart:$jersey_version"
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
compile "joda-time:joda-time:$jodatime_version"
testCompile "junit:junit:$junit_version"
}

View File

@@ -0,0 +1,2 @@
# Uncomment to build for Android
#target = android

View File

@@ -0,0 +1 @@
rootProject.name = "swagger-petstore-jersey2"

View File

@@ -6,18 +6,12 @@ import io.swagger.client.Configuration;
import io.swagger.client.Pair;
import io.swagger.client.TypeRef;
import io.swagger.client.model.*;
import java.util.*;
import io.swagger.client.model.Pet;
import java.io.File;
import java.io.File;
import java.util.Map;
import java.util.HashMap;
import java.util.*;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-09T21:30:19.416+08:00")
public class PetApi {
private ApiClient apiClient;

View File

@@ -6,18 +6,12 @@ import io.swagger.client.Configuration;
import io.swagger.client.Pair;
import io.swagger.client.TypeRef;
import io.swagger.client.model.*;
import java.util.*;
import java.util.Map;
import io.swagger.client.model.Order;
import java.io.File;
import java.util.Map;
import java.util.HashMap;
import java.util.*;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-09T21:30:19.416+08:00")
public class StoreApi {
private ApiClient apiClient;

View File

@@ -6,18 +6,12 @@ import io.swagger.client.Configuration;
import io.swagger.client.Pair;
import io.swagger.client.TypeRef;
import io.swagger.client.model.*;
import java.util.*;
import io.swagger.client.model.User;
import java.util.*;
import java.io.File;
import java.util.Map;
import java.util.HashMap;
import java.util.*;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-09T21:30:19.416+08:00")
public class UserApi {
private ApiClient apiClient;

View File

@@ -10,7 +10,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@ApiModel(description = "")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-09T21:30:19.416+08:00")
public class Order {
private Long id = null;
@@ -19,7 +19,9 @@ public class Order {
private Date shipDate = null;
public enum StatusEnum {
PLACED("placed"), APPROVED("approved"), DELIVERED("delivered");
PLACED("placed"),
APPROVED("approved"),
DELIVERED("delivered");
private String value;

View File

@@ -12,7 +12,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@ApiModel(description = "")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-09T21:30:19.416+08:00")
public class Pet {
private Long id = null;
@@ -22,7 +22,9 @@ public class Pet {
private List<Tag> tags = new ArrayList<Tag>();
public enum StatusEnum {
AVAILABLE("available"), PENDING("pending"), SOLD("sold");
AVAILABLE("available"),
PENDING("pending"),
SOLD("sold");
private String value;

View File

@@ -1,11 +1,89 @@
apply plugin: 'java'
apply plugin: 'maven'
group = 'io.swagger'
version = '1.0.0'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
}
}
repositories {
mavenCentral()
jcenter()
}
if(hasProperty('target') && target == 'android') {
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 22
buildToolsVersion '22.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
// Rename the aar correctly
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
afterEvaluate {
android.libraryVariants.all { variant ->
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
task.description = "Create jar artifact for ${variant.name}"
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
artifacts.add('archives', task);
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
} else {
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
install {
repositories.mavenInstaller {
pom.artifactId = 'swagger-petstore-okhttp-gson'
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}
}
dependencies {
@@ -15,17 +93,3 @@ dependencies {
compile 'com.brsanthu:migbase64:2.2'
testCompile 'junit:junit:4.8.1'
}
group = 'io.swagger'
version = '1.0.0'
install {
repositories.mavenInstaller {
pom.artifactId = 'swagger-petstore-okhttp-gson'
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}

View File

@@ -0,0 +1,2 @@
# Uncomment to build for Android
#target = android

View File

@@ -0,0 +1 @@
rootProject.name = "swagger-petstore-okhttp-gson"

View File

@@ -6,22 +6,15 @@ import io.swagger.client.ApiException;
import io.swagger.client.Configuration;
import io.swagger.client.Pair;
import io.swagger.client.model.*;
import com.google.gson.reflect.TypeToken;
import com.squareup.okhttp.Call;
import java.lang.reflect.Type;
import java.util.*;
import io.swagger.client.model.Pet;
import java.io.File;
import java.io.File;
import java.util.Map;
import java.util.HashMap;
import java.lang.reflect.Type;
import java.util.*;
public class PetApi {
private ApiClient apiClient;

View File

@@ -6,22 +6,15 @@ import io.swagger.client.ApiException;
import io.swagger.client.Configuration;
import io.swagger.client.Pair;
import io.swagger.client.model.*;
import com.google.gson.reflect.TypeToken;
import com.squareup.okhttp.Call;
import java.lang.reflect.Type;
import java.util.*;
import java.util.Map;
import io.swagger.client.model.Order;
import java.io.File;
import java.util.Map;
import java.util.HashMap;
import java.lang.reflect.Type;
import java.util.*;
public class StoreApi {
private ApiClient apiClient;

View File

@@ -6,22 +6,15 @@ import io.swagger.client.ApiException;
import io.swagger.client.Configuration;
import io.swagger.client.Pair;
import io.swagger.client.model.*;
import com.google.gson.reflect.TypeToken;
import com.squareup.okhttp.Call;
import java.lang.reflect.Type;
import java.util.*;
import io.swagger.client.model.User;
import java.util.*;
import java.io.File;
import java.util.Map;
import java.util.HashMap;
import java.lang.reflect.Type;
import java.util.*;
public class UserApi {
private ApiClient apiClient;

View File

@@ -0,0 +1,103 @@
group = 'io.swagger'
version = '1.0.0'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
}
}
repositories {
jcenter()
}
if(hasProperty('target') && target == 'android') {
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 22
buildToolsVersion '22.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
// Rename the aar correctly
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
afterEvaluate {
android.libraryVariants.all { variant ->
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
task.description = "Create jar artifact for ${variant.name}"
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
artifacts.add('archives', task);
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
} else {
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
install {
repositories.mavenInstaller {
pom.artifactId = 'swagger-petstore-retrofit'
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}
}
ext {
okhttp_version = "2.3.0"
oltu_version = "1.0.0"
retrofit_version = "1.9.0"
swagger_annotations_version = "1.5.0"
junit_version = "4.12"
}
dependencies {
compile "com.squareup.okhttp:okhttp:$okhttp_version"
compile "com.squareup.retrofit:retrofit:$retrofit_version"
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version"
testCompile "junit:junit:$junit_version"
}

View File

@@ -0,0 +1,2 @@
# Uncomment to build for Android
#target = android

View File

@@ -0,0 +1 @@
rootProject.name = "swagger-petstore-retrofit"

View File

@@ -1,15 +1,14 @@
package io.swagger.client.api;
import io.swagger.client.model.*;
import retrofit.Callback;
import retrofit.http.*;
import retrofit.mime.*;
import java.util.*;
import io.swagger.client.model.Pet;
import java.io.File;
import java.util.*;
public interface PetApi {
/**
@@ -20,7 +19,7 @@ public interface PetApi {
* @return Void
*/
@PUT("/pet")
@PUT("/pet")
Void updatePet(
@Body Pet body
);
@@ -29,14 +28,14 @@ public interface PetApi {
* Update an existing pet
* Async method
* @param body Pet object that needs to be added to the store
* @param cb callback method
* @param cb callback method
* @return void
*/
@PUT("/pet")
@PUT("/pet")
void updatePet(
@Body Pet body, Callback<Void> cb
);
);
/**
* Add a new pet to the store
@@ -46,7 +45,7 @@ public interface PetApi {
* @return Void
*/
@POST("/pet")
@POST("/pet")
Void addPet(
@Body Pet body
);
@@ -55,14 +54,14 @@ public interface PetApi {
* Add a new pet to the store
* Async method
* @param body Pet object that needs to be added to the store
* @param cb callback method
* @param cb callback method
* @return void
*/
@POST("/pet")
@POST("/pet")
void addPet(
@Body Pet body, Callback<Void> cb
);
);
/**
* Finds Pets by status
@@ -72,7 +71,7 @@ public interface PetApi {
* @return List<Pet>
*/
@GET("/pet/findByStatus")
@GET("/pet/findByStatus")
List<Pet> findPetsByStatus(
@Query("status") List<String> status
);
@@ -81,14 +80,14 @@ public interface PetApi {
* Finds Pets by status
* Async method
* @param status Status values that need to be considered for filter
* @param cb callback method
* @param cb callback method
* @return void
*/
@GET("/pet/findByStatus")
@GET("/pet/findByStatus")
void findPetsByStatus(
@Query("status") List<String> status, Callback<List<Pet>> cb
);
);
/**
* Finds Pets by tags
@@ -98,7 +97,7 @@ public interface PetApi {
* @return List<Pet>
*/
@GET("/pet/findByTags")
@GET("/pet/findByTags")
List<Pet> findPetsByTags(
@Query("tags") List<String> tags
);
@@ -107,14 +106,14 @@ public interface PetApi {
* Finds Pets by tags
* Async method
* @param tags Tags to filter by
* @param cb callback method
* @param cb callback method
* @return void
*/
@GET("/pet/findByTags")
@GET("/pet/findByTags")
void findPetsByTags(
@Query("tags") List<String> tags, Callback<List<Pet>> cb
);
);
/**
* Find pet by ID
@@ -124,7 +123,7 @@ public interface PetApi {
* @return Pet
*/
@GET("/pet/{petId}")
@GET("/pet/{petId}")
Pet getPetById(
@Path("petId") Long petId
);
@@ -133,14 +132,14 @@ public interface PetApi {
* Find pet by ID
* Async method
* @param petId ID of pet that needs to be fetched
* @param cb callback method
* @param cb callback method
* @return void
*/
@GET("/pet/{petId}")
@GET("/pet/{petId}")
void getPetById(
@Path("petId") Long petId, Callback<Pet> cb
);
);
/**
* Updates a pet in the store with form data
@@ -153,7 +152,7 @@ public interface PetApi {
*/
@FormUrlEncoded
@POST("/pet/{petId}")
@POST("/pet/{petId}")
Void updatePetWithForm(
@Path("petId") String petId, @Field("name") String name, @Field("status") String status
);
@@ -164,15 +163,15 @@ public interface PetApi {
* @param petId ID of pet that needs to be updated
* @param name Updated name of the pet
* @param status Updated status of the pet
* @param cb callback method
* @param cb callback method
* @return void
*/
@FormUrlEncoded
@POST("/pet/{petId}")
@POST("/pet/{petId}")
void updatePetWithForm(
@Path("petId") String petId, @Field("name") String name, @Field("status") String status, Callback<Void> cb
);
);
/**
* Deletes a pet
@@ -183,7 +182,7 @@ public interface PetApi {
* @return Void
*/
@DELETE("/pet/{petId}")
@DELETE("/pet/{petId}")
Void deletePet(
@Path("petId") Long petId, @Header("api_key") String apiKey
);
@@ -193,14 +192,14 @@ public interface PetApi {
* Async method
* @param petId Pet id to delete
* @param apiKey
* @param cb callback method
* @param cb callback method
* @return void
*/
@DELETE("/pet/{petId}")
@DELETE("/pet/{petId}")
void deletePet(
@Path("petId") Long petId, @Header("api_key") String apiKey, Callback<Void> cb
);
);
/**
* uploads an image
@@ -213,7 +212,7 @@ public interface PetApi {
*/
@Multipart
@POST("/pet/{petId}/uploadImage")
@POST("/pet/{petId}/uploadImage")
Void uploadFile(
@Path("petId") Long petId, @Part("additionalMetadata") String additionalMetadata, @Part("file") TypedFile file
);
@@ -224,14 +223,14 @@ public interface PetApi {
* @param petId ID of pet to update
* @param additionalMetadata Additional data to pass to server
* @param file file to upload
* @param cb callback method
* @param cb callback method
* @return void
*/
@Multipart
@POST("/pet/{petId}/uploadImage")
@POST("/pet/{petId}/uploadImage")
void uploadFile(
@Path("petId") Long petId, @Part("additionalMetadata") String additionalMetadata, @Part("file") TypedFile file, Callback<Void> cb
);
);
}

View File

@@ -1,15 +1,14 @@
package io.swagger.client.api;
import io.swagger.client.model.*;
import retrofit.Callback;
import retrofit.http.*;
import retrofit.mime.*;
import java.util.*;
import java.util.Map;
import io.swagger.client.model.Order;
import java.util.*;
public interface StoreApi {
/**
@@ -19,21 +18,21 @@ public interface StoreApi {
* @return Map<String, Integer>
*/
@GET("/store/inventory")
@GET("/store/inventory")
Map<String, Integer> getInventory();
/**
* Returns pet inventories by status
* Async method
* @param cb callback method
* @param cb callback method
* @return void
*/
@GET("/store/inventory")
@GET("/store/inventory")
void getInventory(
Callback<Map<String, Integer>> cb
);
);
/**
* Place an order for a pet
@@ -43,7 +42,7 @@ public interface StoreApi {
* @return Order
*/
@POST("/store/order")
@POST("/store/order")
Order placeOrder(
@Body Order body
);
@@ -52,14 +51,14 @@ public interface StoreApi {
* Place an order for a pet
* Async method
* @param body order placed for purchasing the pet
* @param cb callback method
* @param cb callback method
* @return void
*/
@POST("/store/order")
@POST("/store/order")
void placeOrder(
@Body Order body, Callback<Order> cb
);
);
/**
* Find purchase order by ID
@@ -69,7 +68,7 @@ public interface StoreApi {
* @return Order
*/
@GET("/store/order/{orderId}")
@GET("/store/order/{orderId}")
Order getOrderById(
@Path("orderId") String orderId
);
@@ -78,14 +77,14 @@ public interface StoreApi {
* Find purchase order by ID
* Async method
* @param orderId ID of pet that needs to be fetched
* @param cb callback method
* @param cb callback method
* @return void
*/
@GET("/store/order/{orderId}")
@GET("/store/order/{orderId}")
void getOrderById(
@Path("orderId") String orderId, Callback<Order> cb
);
);
/**
* Delete purchase order by ID
@@ -95,7 +94,7 @@ public interface StoreApi {
* @return Void
*/
@DELETE("/store/order/{orderId}")
@DELETE("/store/order/{orderId}")
Void deleteOrder(
@Path("orderId") String orderId
);
@@ -104,13 +103,13 @@ public interface StoreApi {
* Delete purchase order by ID
* Async method
* @param orderId ID of the order that needs to be deleted
* @param cb callback method
* @param cb callback method
* @return void
*/
@DELETE("/store/order/{orderId}")
@DELETE("/store/order/{orderId}")
void deleteOrder(
@Path("orderId") String orderId, Callback<Void> cb
);
);
}

View File

@@ -1,15 +1,14 @@
package io.swagger.client.api;
import io.swagger.client.model.*;
import retrofit.Callback;
import retrofit.http.*;
import retrofit.mime.*;
import java.util.*;
import io.swagger.client.model.User;
import java.util.*;
import java.util.*;
public interface UserApi {
/**
@@ -20,7 +19,7 @@ public interface UserApi {
* @return Void
*/
@POST("/user")
@POST("/user")
Void createUser(
@Body User body
);
@@ -29,14 +28,14 @@ public interface UserApi {
* Create user
* Async method
* @param body Created user object
* @param cb callback method
* @param cb callback method
* @return void
*/
@POST("/user")
@POST("/user")
void createUser(
@Body User body, Callback<Void> cb
);
);
/**
* Creates list of users with given input array
@@ -46,7 +45,7 @@ public interface UserApi {
* @return Void
*/
@POST("/user/createWithArray")
@POST("/user/createWithArray")
Void createUsersWithArrayInput(
@Body List<User> body
);
@@ -55,14 +54,14 @@ public interface UserApi {
* Creates list of users with given input array
* Async method
* @param body List of user object
* @param cb callback method
* @param cb callback method
* @return void
*/
@POST("/user/createWithArray")
@POST("/user/createWithArray")
void createUsersWithArrayInput(
@Body List<User> body, Callback<Void> cb
);
);
/**
* Creates list of users with given input array
@@ -72,7 +71,7 @@ public interface UserApi {
* @return Void
*/
@POST("/user/createWithList")
@POST("/user/createWithList")
Void createUsersWithListInput(
@Body List<User> body
);
@@ -81,14 +80,14 @@ public interface UserApi {
* Creates list of users with given input array
* Async method
* @param body List of user object
* @param cb callback method
* @param cb callback method
* @return void
*/
@POST("/user/createWithList")
@POST("/user/createWithList")
void createUsersWithListInput(
@Body List<User> body, Callback<Void> cb
);
);
/**
* Logs user into the system
@@ -99,7 +98,7 @@ public interface UserApi {
* @return String
*/
@GET("/user/login")
@GET("/user/login")
String loginUser(
@Query("username") String username, @Query("password") String password
);
@@ -109,14 +108,14 @@ public interface UserApi {
* Async method
* @param username The user name for login
* @param password The password for login in clear text
* @param cb callback method
* @param cb callback method
* @return void
*/
@GET("/user/login")
@GET("/user/login")
void loginUser(
@Query("username") String username, @Query("password") String password, Callback<String> cb
);
);
/**
* Logs out current logged in user session
@@ -125,21 +124,21 @@ public interface UserApi {
* @return Void
*/
@GET("/user/logout")
@GET("/user/logout")
Void logoutUser();
/**
* Logs out current logged in user session
* Async method
* @param cb callback method
* @param cb callback method
* @return void
*/
@GET("/user/logout")
@GET("/user/logout")
void logoutUser(
Callback<Void> cb
);
);
/**
* Get user by user name
@@ -149,7 +148,7 @@ public interface UserApi {
* @return User
*/
@GET("/user/{username}")
@GET("/user/{username}")
User getUserByName(
@Path("username") String username
);
@@ -158,14 +157,14 @@ public interface UserApi {
* Get user by user name
* Async method
* @param username The name that needs to be fetched. Use user1 for testing.
* @param cb callback method
* @param cb callback method
* @return void
*/
@GET("/user/{username}")
@GET("/user/{username}")
void getUserByName(
@Path("username") String username, Callback<User> cb
);
);
/**
* Updated user
@@ -176,7 +175,7 @@ public interface UserApi {
* @return Void
*/
@PUT("/user/{username}")
@PUT("/user/{username}")
Void updateUser(
@Path("username") String username, @Body User body
);
@@ -186,14 +185,14 @@ public interface UserApi {
* Async method
* @param username name that need to be deleted
* @param body Updated user object
* @param cb callback method
* @param cb callback method
* @return void
*/
@PUT("/user/{username}")
@PUT("/user/{username}")
void updateUser(
@Path("username") String username, @Body User body, Callback<Void> cb
);
);
/**
* Delete user
@@ -203,7 +202,7 @@ public interface UserApi {
* @return Void
*/
@DELETE("/user/{username}")
@DELETE("/user/{username}")
Void deleteUser(
@Path("username") String username
);
@@ -212,13 +211,13 @@ public interface UserApi {
* Delete user
* Async method
* @param username The name that needs to be deleted
* @param cb callback method
* @param cb callback method
* @return void
*/
@DELETE("/user/{username}")
@DELETE("/user/{username}")
void deleteUser(
@Path("username") String username, Callback<Void> cb
);
);
}