diff --git a/README.md b/README.md index 0577dceb8e..7b130b4b8a 100644 --- a/README.md +++ b/README.md @@ -276,6 +276,9 @@ CONFIG OPTIONS apiPackage package for generated api classes + sortParamsByRequiredFlag + Sort method arguments to place required parameters before optional parameters. Default: true + invokerPackage root package for generated code @@ -291,6 +294,12 @@ CONFIG OPTIONS sourceFolder source folder for generated code + localVariablePrefix + prefix for generated code members and local variables + + serializableModel + boolean - toggle "implements Serializable" for generated models + library library template (sub-template) to use: - HTTP client: Jersey client 1.18. JSON processing: Jackson 2.4.2 diff --git a/bin/all-petstore.sh b/bin/all-petstore.sh index 180e95590b..2f9d4c0c0f 100755 --- a/bin/all-petstore.sh +++ b/bin/all-petstore.sh @@ -33,7 +33,6 @@ cd $APP_DIR ./bin/perl-petstore.sh ./bin/php-petstore.sh ./bin/python-petstore.sh -./bin/python3-petstore.sh ./bin/qt5-petstore.sh ./bin/ruby-petstore.sh ./bin/scala-async-petstore.sh diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java index 6dd85d10c2..38c70fcc82 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java @@ -7,7 +7,8 @@ import java.util.List; public class CodegenParameter { public Boolean isFormParam, isQueryParam, isPathParam, isHeaderParam, - isCookieParam, isBodyParam, isFile, notFile, hasMore, isContainer, secondaryParam, isBinary; + isCookieParam, isBodyParam, isFile, notFile, hasMore, isContainer, + secondaryParam, isBinary, isCollectionFormatMulti; public String baseName, paramName, dataType, collectionFormat, description, baseType, defaultValue; public String jsonSchema; public boolean isEnum; @@ -33,6 +34,7 @@ public class CodegenParameter { output.paramName = this.paramName; output.dataType = this.dataType; output.collectionFormat = this.collectionFormat; + output.isCollectionFormatMulti = this.isCollectionFormatMulti; output.description = this.description; output.baseType = this.baseType; output.isFormParam = this.isFormParam; diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index efc0aa31db..575f9742f5 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -492,10 +492,16 @@ public class DefaultCodegen { } else if (p instanceof DecimalProperty) { datatype = "number"; } else if (p instanceof RefProperty) { - RefProperty r = (RefProperty) p; - datatype = r.get$ref(); - if (datatype.indexOf("#/definitions/") == 0) { - datatype = datatype.substring("#/definitions/".length()); + try { + RefProperty r = (RefProperty) p; + datatype = r.get$ref(); + if (datatype.indexOf("#/definitions/") == 0) { + datatype = datatype.substring("#/definitions/".length()); + } + } catch (Exception e) { + LOGGER.warn("Error obtaining the datatype from RefProperty:" + p + ". Datatype default to Object"); + datatype = "Object"; + e.printStackTrace(); } } else { if (p != null) { @@ -584,7 +590,7 @@ public class DefaultCodegen { } } // interfaces (intermediate models) - if (allDefinitions != null) { + if (allDefinitions != null && composed.getInterfaces() != null) { for (RefModel _interface : composed.getInterfaces()) { final String interfaceRef = toModelName(_interface.getSimpleRef()); final Model interfaceModel = allDefinitions.get(interfaceRef); @@ -1038,7 +1044,7 @@ public class DefaultCodegen { } } for (String i : imports) { - if (!defaultIncludes.contains(i) && !languageSpecificPrimitives.contains(i)) { + if (needToImport(i)) { op.imports.add(i); } } @@ -1199,6 +1205,9 @@ public class DefaultCodegen { p._enum = model._enum; p.allowableValues = model.allowableValues; p.collectionFormat = collectionFormat; + if(collectionFormat != null && collectionFormat.equals("multi")) { + p.isCollectionFormatMulti = true; + } p.paramName = toParamName(qp.getName()); if (model.complexType != null) { @@ -1311,6 +1320,12 @@ public class DefaultCodegen { return secs; } + protected boolean needToImport(String type) { + return !defaultIncludes.contains(type) + && !languageSpecificPrimitives.contains(type) + && type.indexOf(".") < 0; + } + protected List> toExamples(Map examples) { if (examples == null) { return null; @@ -1414,7 +1429,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); } } @@ -1593,8 +1608,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. @@ -1617,7 +1632,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_]", ""); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java index bc8a60afbd..ac4a36a37e 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java @@ -12,6 +12,7 @@ import io.swagger.models.License; import io.swagger.models.Model; import io.swagger.models.Operation; import io.swagger.models.Path; +import io.swagger.models.SecurityRequirement; import io.swagger.models.Swagger; import io.swagger.models.auth.OAuth2Definition; import io.swagger.models.auth.SecuritySchemeDefinition; @@ -480,16 +481,25 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { config.addOperationToGroup(sanitizeTag(tag), resourcePath, operation, co, operations); List>> securities = operation.getSecurity(); - if (securities == null) { + if (securities == null && swagger.getSecurity() != null) { + securities = new ArrayList>>(); + for (SecurityRequirement sr : swagger.getSecurity()) { + securities.add(sr.getRequirements()); + } + } + if (securities == null || securities.isEmpty()) { continue; } Map authMethods = new HashMap(); - for (Map> security : securities) { - if (security.size() != 1) { - //Not sure what to do - continue; - } - String securityName = security.keySet().iterator().next(); + // NOTE: Use only the first security requirement for now. + // See the "security" field of "Swagger Object": + // https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#swagger-object + // "there is a logical OR between the security requirements" + if (securities.size() > 1) { + LOGGER.warn("More than 1 security requirements are found, using only the first one"); + } + Map> security = securities.get(0); + for (String securityName : security.keySet()) { SecuritySchemeDefinition securityDefinition = fromSecurity(securityName); if (securityDefinition != null) { if(securityDefinition instanceof OAuth2Definition) { @@ -500,7 +510,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { oauth2Operation.setFlow(oauth2Definition.getFlow()); oauth2Operation.setTokenUrl(oauth2Definition.getTokenUrl()); oauth2Operation.setScopes(new HashMap()); - for (String scope : security.values().iterator().next()) { + for (String scope : security.get(securityName)) { if (oauth2Definition.getScopes().containsKey(scope)) { oauth2Operation.addScope(scope, oauth2Definition.getScopes().get(scope)); } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java index 4b17715e66..bd3487d06d 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java @@ -104,13 +104,13 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig } additionalProperties.put("clientPackage", clientPackage); - + supportingFiles.add(new SupportingFile("Configuration.mustache", - (sourceFolder + File.separator + clientPackage).replace(".", java.io.File.separator), "Configuration.cs")); + 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")); + 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")); + 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")); @@ -137,12 +137,11 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig @Override public String apiFileFolder() { - - return outputFolder + File.separator + (sourceFolder + File.separator + apiPackage()).replace('.', File.separatorChar); + 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); + return outputFolder + File.separator + sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar); } @Override diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CsharpDotNet2ClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CsharpDotNet2ClientCodegen.java index 432e7ae3fa..9d9757a913 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CsharpDotNet2ClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CsharpDotNet2ClientCodegen.java @@ -108,11 +108,11 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege } supportingFiles.add(new SupportingFile("Configuration.mustache", - (sourceFolder + File.separator + clientPackage).replace(".", java.io.File.separator), "Configuration.cs")); + 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")); + 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")); + 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")); @@ -142,11 +142,11 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege @Override public String apiFileFolder() { - return (outputFolder + File.separator + sourceFolder + File.separator + apiPackage()).replace('.', File.separatorChar); + 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); + return outputFolder + File.separator + sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar); } @Override diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java index 360dc9c0f2..d265e5a723 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java @@ -12,6 +12,7 @@ import io.swagger.codegen.DefaultCodegen; import io.swagger.codegen.SupportingFile; import io.swagger.models.Model; import io.swagger.models.properties.ArrayProperty; +import io.swagger.models.properties.LongProperty; import io.swagger.models.properties.MapProperty; import io.swagger.models.properties.Property; @@ -37,6 +38,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 +84,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("", "HTTP client: Jersey client 1.18. JSON processing: Jackson 2.4.2"); supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.6"); @@ -107,7 +111,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 { @@ -149,16 +153,49 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig { this.setSerializableModel(Boolean.valueOf((String)additionalProperties.get(CodegenConstants.SERIALIZABLE_MODEL).toString())); } + if (additionalProperties.containsKey(CodegenConstants.LIBRARY)) { + this.setLibrary((String) additionalProperties.get(CodegenConstants.LIBRARY)); + } + // 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,42 +209,41 @@ 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())) { supportingFiles.add(new SupportingFile("auth/OAuthOkHttpClient.mustache", authFolder, "OAuthOkHttpClient.java")); + supportingFiles.add(new SupportingFile("CollectionFormats.mustache", invokerFolder, "CollectionFormats.java")); } else { supportingFiles.add(new SupportingFile("TypeRef.mustache", invokerFolder, "TypeRef.java")); } } 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 +330,28 @@ 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()", getTypeDeclaration(ap.getAdditionalProperties())); + final String pattern; + if (fullJavaUtil) { + pattern = "new java.util.HashMap()"; + } else { + pattern = "new HashMap()"; + } + return String.format(pattern, getTypeDeclaration(ap.getAdditionalProperties())); + } else if (p instanceof LongProperty) { + LongProperty dp = (LongProperty) p; + if (dp.getDefault() != null) { + return dp.getDefault().toString()+"l"; + } + return "null"; } return super.toDefaultValue(p); } @@ -308,7 +362,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 +448,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig { } return objs; } - + public Map postProcessOperations(Map objs) { if("retrofit".equals(getLibrary())) { Map operations = (Map) objs.get("operations"); @@ -418,6 +472,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 vars) { String prefix = StringUtils.getCommonPrefix(vars.toArray(new String[vars.size()])); // exclude trailing characters that should be part of a valid variable @@ -426,7 +484,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) { diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaInflectorServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaInflectorServerCodegen.java index 56dbdd0e48..d678515f4c 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaInflectorServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaInflectorServerCodegen.java @@ -22,10 +22,6 @@ 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() { @@ -35,6 +31,8 @@ public class JavaInflectorServerCodegen extends JavaClientCodegen implements Cod modelTemplateFiles.put("model.mustache", ".java"); apiTemplateFiles.put("api.mustache", ".java"); templateDir = "JavaInflector"; + invokerPackage = "io.swagger.handler"; + artifactId = "swagger-inflector-server"; apiPackage = System.getProperty("swagger.codegen.inflector.apipackage", "io.swagger.handler"); modelPackage = System.getProperty("swagger.codegen.inflector.modelpackage", "io.swagger.model"); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java index eb0f6be03e..883b08d8df 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java @@ -16,16 +16,14 @@ import java.util.List; import java.util.Map; public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConfig { - protected String invokerPackage = "io.swagger.api"; - protected String groupId = "io.swagger"; - protected String artifactId = "swagger-jaxrs-server"; - protected String artifactVersion = "1.0.0"; protected String title = "Swagger Server"; public JaxRSServerCodegen() { super.processOpts(); sourceFolder = "src/gen/java"; + invokerPackage = "io.swagger.api"; + artifactId = "swagger-jaxrs-server"; outputFolder = System.getProperty("swagger.codegen.jaxrs.genfolder", "generated-code/javaJaxRS"); modelTemplateFiles.put("model.mustache", ".java"); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SpringMVCServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SpringMVCServerCodegen.java index 6bd64b0e4f..30d1007326 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SpringMVCServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SpringMVCServerCodegen.java @@ -15,13 +15,7 @@ import java.util.Map; import java.util.Iterator; public class SpringMVCServerCodegen extends JavaClientCodegen implements CodegenConfig { - protected String invokerPackage = "io.swagger.api"; - protected String groupId = "io.swagger"; - protected String artifactId = "swagger-spring-mvc-server"; - protected String artifactVersion = "1.0.0"; - protected String sourceFolder = "src/main/java"; protected String title = "Petstore Server"; - protected String configPackage = ""; public SpringMVCServerCodegen() { @@ -33,7 +27,8 @@ public class SpringMVCServerCodegen extends JavaClientCodegen implements Codegen apiPackage = "io.swagger.api"; modelPackage = "io.swagger.model"; configPackage = "io.swagger.configuration"; - + invokerPackage = "io.swagger.api"; + artifactId = "swagger-spring-mvc-server"; additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage); additionalProperties.put(CodegenConstants.GROUP_ID, groupId); @@ -201,4 +196,3 @@ public class SpringMVCServerCodegen extends JavaClientCodegen implements Codegen return objs; } } - diff --git a/modules/swagger-codegen/src/main/resources/Java/api.mustache b/modules/swagger-codegen/src/main/resources/Java/api.mustache index ad957261f2..08d28ebd51 100644 --- a/modules/swagger-codegen/src/main/resources/Java/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/api.mustache @@ -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 {{localVariablePrefix}}queryParams = new ArrayList(); - Map {{localVariablePrefix}}headerParams = new HashMap(); - Map {{localVariablePrefix}}formParams = new HashMap(); + {{javaUtilPrefix}}List {{localVariablePrefix}}queryParams = new {{javaUtilPrefix}}ArrayList(); + {{javaUtilPrefix}}Map {{localVariablePrefix}}headerParams = new {{javaUtilPrefix}}HashMap(); + {{javaUtilPrefix}}Map {{localVariablePrefix}}formParams = new {{javaUtilPrefix}}HashMap(); {{#queryParams}} {{localVariablePrefix}}queryParams.addAll({{localVariablePrefix}}apiClient.parameterToPairs("{{#collectionFormat}}{{{collectionFormat}}}{{/collectionFormat}}", "{{baseName}}", {{paramName}})); diff --git a/modules/swagger-codegen/src/main/resources/Java/build.gradle.mustache b/modules/swagger-codegen/src/main/resources/Java/build.gradle.mustache new file mode 100644 index 0000000000..971dcd816a --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Java/build.gradle.mustache @@ -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" +} diff --git a/modules/swagger-codegen/src/main/resources/Java/gradle.properties.mustache b/modules/swagger-codegen/src/main/resources/Java/gradle.properties.mustache new file mode 100644 index 0000000000..05644f0754 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Java/gradle.properties.mustache @@ -0,0 +1,2 @@ +# Uncomment to build for Android +#target = android \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache index d525db8a28..10f2fa2f74 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache @@ -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 {{localVariablePrefix}}queryParams = new ArrayList(); - Map {{localVariablePrefix}}headerParams = new HashMap(); - Map {{localVariablePrefix}}formParams = new HashMap(); + {{javaUtilPrefix}}List {{localVariablePrefix}}queryParams = new {{javaUtilPrefix}}ArrayList(); + {{javaUtilPrefix}}Map {{localVariablePrefix}}headerParams = new {{javaUtilPrefix}}HashMap(); + {{javaUtilPrefix}}Map {{localVariablePrefix}}formParams = new {{javaUtilPrefix}}HashMap(); {{#queryParams}} {{localVariablePrefix}}queryParams.addAll({{localVariablePrefix}}apiClient.parameterToPairs("{{#collectionFormat}}{{{collectionFormat}}}{{/collectionFormat}}", "{{baseName}}", {{paramName}})); diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.gradle.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.gradle.mustache new file mode 100644 index 0000000000..548c1854e5 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.gradle.mustache @@ -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" +} diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache index b272687c7f..efb1a14f27 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache @@ -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 {{localVariablePrefix}}queryParams = new ArrayList();{{#queryParams}} + {{javaUtilPrefix}}List {{localVariablePrefix}}queryParams = new {{javaUtilPrefix}}ArrayList();{{#queryParams}} if ({{paramName}} != null) {{localVariablePrefix}}queryParams.addAll({{localVariablePrefix}}apiClient.parameterToPairs("{{#collectionFormat}}{{{collectionFormat}}}{{/collectionFormat}}", "{{baseName}}", {{paramName}}));{{/queryParams}} - Map {{localVariablePrefix}}headerParams = new HashMap();{{#headerParams}} + {{javaUtilPrefix}}Map {{localVariablePrefix}}headerParams = new {{javaUtilPrefix}}HashMap();{{#headerParams}} if ({{paramName}} != null) {{localVariablePrefix}}headerParams.put("{{baseName}}", {{localVariablePrefix}}apiClient.parameterToString({{paramName}}));{{/headerParams}} - Map {{localVariablePrefix}}formParams = new HashMap();{{#formParams}} + {{javaUtilPrefix}}Map {{localVariablePrefix}}formParams = new {{javaUtilPrefix}}HashMap();{{#formParams}} if ({{paramName}} != null) {{localVariablePrefix}}formParams.put("{{baseName}}", {{paramName}});{{/formParams}} diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/build.gradle.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/build.gradle.mustache index 02e1caa673..289f9a6df7 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/build.gradle.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/build.gradle.mustache @@ -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 -} diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/CollectionFormats.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/CollectionFormats.mustache new file mode 100644 index 0000000000..a549ea59d1 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/CollectionFormats.mustache @@ -0,0 +1,95 @@ +package {{invokerPackage}}; + +import java.util.Arrays; +import java.util.List; + +public class CollectionFormats { + + public static class CSVParams { + + protected List params; + + public CSVParams() { + } + + public CSVParams(List params) { + this.params = params; + } + + public CSVParams(String... params) { + this.params = Arrays.asList(params); + } + + public List getParams() { + return params; + } + + public void setParams(List params) { + this.params = params; + } + + @Override + public String toString() { + return StringUtil.join(params.toArray(new String[0]), ","); + } + + } + + public static class SSVParams extends CSVParams { + + public SSVParams() { + } + + public SSVParams(List params) { + super(params); + } + + public SSVParams(String... params) { + super(params); + } + + @Override + public String toString() { + return StringUtil.join(params.toArray(new String[0]), " "); + } + } + + public static class TSVParams extends CSVParams { + + public TSVParams() { + } + + public TSVParams(List params) { + super(params); + } + + public TSVParams(String... params) { + super(params); + } + + @Override + public String toString() { + return StringUtil.join( params.toArray(new String[0]), "\t"); + } + } + + public static class PIPESParams extends CSVParams { + + public PIPESParams() { + } + + public PIPESParams(List params) { + super(params); + } + + public PIPESParams(String... params) { + super(params); + } + + @Override + public String toString() { + return StringUtil.join(params.toArray(new String[0]), "|"); + } + } + +} diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/api.mustache index 89850d92bd..84c799d625 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/api.mustache @@ -1,15 +1,18 @@ package {{package}}; -import {{modelPackage}}.*; +import {{invokerPackage}}.CollectionFormats.*; 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 +25,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 +34,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}} \ No newline at end of file +{{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/build.gradle.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/build.gradle.mustache new file mode 100644 index 0000000000..a285745505 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/build.gradle.mustache @@ -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" +} diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/queryParams.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/queryParams.mustache index e0a58533e5..3c5b1bb7e6 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/queryParams.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/queryParams.mustache @@ -1 +1 @@ -{{#isQueryParam}}@Query("{{baseName}}") {{{dataType}}} {{paramName}}{{/isQueryParam}} \ No newline at end of file +{{#isQueryParam}}@Query("{{baseName}}") {{#collectionFormat}}{{#isCollectionFormatMulti}}{{{dataType}}}{{/isCollectionFormatMulti}}{{^isCollectionFormatMulti}}{{{collectionFormat.toUpperCase}}}Params{{/isCollectionFormatMulti}}{{/collectionFormat}}{{^collectionFormat}}{{{dataType}}}{{/collectionFormat}} {{paramName}}{{/isQueryParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/Java/settings.gradle.mustache b/modules/swagger-codegen/src/main/resources/Java/settings.gradle.mustache new file mode 100644 index 0000000000..b8fd6c4c41 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Java/settings.gradle.mustache @@ -0,0 +1 @@ +rootProject.name = "{{artifactId}}" \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache index 233ead8bee..9681634a76 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache @@ -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]; } diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/model.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/model.mustache index b425d14d5e..5b57ed4dc9 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/model.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/model.mustache @@ -1,6 +1,6 @@ /// -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}} diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache index 6528a5d3a2..4d03ae0f42 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache @@ -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, diff --git a/modules/swagger-codegen/src/main/resources/android-java/apiInvoker.mustache b/modules/swagger-codegen/src/main/resources/android-java/apiInvoker.mustache index ac24335df1..1f6d77a071 100644 --- a/modules/swagger-codegen/src/main/resources/android-java/apiInvoker.mustache +++ b/modules/swagger-codegen/src/main/resources/android-java/apiInvoker.mustache @@ -365,8 +365,10 @@ public class ApiInvoker { int code = response.getStatusLine().getStatusCode(); String responseString = null; - if(code == 204) + if(code == 204) { responseString = ""; + return responseString; + } else if(code >= 200 && code < 300) { if(response.getEntity() != null) { HttpEntity resEntity = response.getEntity(); diff --git a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache index 8927cbbecb..9db41df2ae 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache @@ -1,11 +1,11 @@ config = $config; $this->serializer = new ObjectSerializer(); } - + /** * Get the config * @return Configuration @@ -87,7 +87,7 @@ class ApiClient { return $this->config; } - + /** * Get the serializer * @return ObjectSerializer @@ -96,7 +96,7 @@ class ApiClient { return $this->serializer; } - + /** * Get API key (with prefix if set) * @param string $apiKeyIdentifier name of apikey @@ -106,20 +106,20 @@ class ApiClient { $prefix = $this->config->getApiKeyPrefix($apiKeyIdentifier); $apiKey = $this->config->getApiKey($apiKeyIdentifier); - + if (!isset($apiKey)) { return null; } - + if (isset($prefix)) { $keyWithPrefix = $prefix." ".$apiKey; } else { $keyWithPrefix = $apiKey; } - + return $keyWithPrefix; } - + /** * Make the HTTP call (Sync) * @param string $resourcePath path to method endpoint @@ -133,28 +133,28 @@ class ApiClient */ public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) { - + $headers = array(); - + // construct the http header $headerParams = array_merge( - (array)$this->config->getDefaultHeaders(), + (array)$this->config->getDefaultHeaders(), (array)$headerParams ); - + foreach ($headerParams as $key => $val) { $headers[] = "$key: $val"; } - + // form data if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) { $postData = http_build_query($postData); } else if ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model $postData = json_encode($this->serializer->sanitizeForSerialization($postData)); } - + $url = $this->config->getHost() . $resourcePath; - + $curl = curl_init(); // set timeout, if needed if ($this->config->getCurlTimeout() != 0) { @@ -162,13 +162,19 @@ class ApiClient } // return the result on success, rather than just TRUE curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - + + // disable SSL verification, if needed + if ($this->config->getSSLVerification() == false) { + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); + } + if (! empty($queryParams)) { $url = ($url . '?' . http_build_query($queryParams)); } - + if ($method == self::$POST) { curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); @@ -190,44 +196,44 @@ class ApiClient throw new ApiException('Method ' . $method . ' is not recognized.'); } curl_setopt($curl, CURLOPT_URL, $url); - + // Set user agent curl_setopt($curl, CURLOPT_USERAGENT, $this->config->getUserAgent()); - + // debugging for curl if ($this->config->getDebug()) { error_log("[DEBUG] HTTP Request body ~BEGIN~\n".print_r($postData, true)."\n~END~\n", 3, $this->config->getDebugFile()); - + curl_setopt($curl, CURLOPT_VERBOSE, 1); curl_setopt($curl, CURLOPT_STDERR, fopen($this->config->getDebugFile(), 'a')); } else { curl_setopt($curl, CURLOPT_VERBOSE, 0); } - + // obtain the HTTP response headers curl_setopt($curl, CURLOPT_HEADER, 1); - + // Make the request $response = curl_exec($curl); $http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $http_header = substr($response, 0, $http_header_size); $http_body = substr($response, $http_header_size); $response_info = curl_getinfo($curl); - + // debug HTTP response body if ($this->config->getDebug()) { error_log("[DEBUG] HTTP Response body ~BEGIN~\n".print_r($http_body, true)."\n~END~\n", 3, $this->config->getDebugFile()); } - + // Handle the response if ($response_info['http_code'] == 0) { throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null); } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { - // return raw body if response is a file + // return raw body if response is a file if ($responseType == '\SplFileObject') { return array($http_body, $http_header); } - + $data = json_decode($http_body); if (json_last_error() > 0) { // if response is a string $data = $http_body; @@ -240,7 +246,7 @@ class ApiClient } return array($data, $http_header); } - + /** * Return the header 'Accept' based on an array of Accept provided * @@ -258,7 +264,7 @@ class ApiClient return implode(',', $accept); } } - + /** * Return the content type based on an array of content-type provided * diff --git a/modules/swagger-codegen/src/main/resources/php/configuration.mustache b/modules/swagger-codegen/src/main/resources/php/configuration.mustache index 981085c637..96bc8a1b66 100644 --- a/modules/swagger-codegen/src/main/resources/php/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/php/configuration.mustache @@ -27,8 +27,8 @@ */ /** - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen * Do not edit the class manually. */ @@ -48,70 +48,70 @@ class Configuration { private static $_defaultConfiguration = null; - - /** + + /** * Associate array to store API key(s) * * @var string[] */ protected $apiKeys = array(); - + /** * Associate array to store API prefix (e.g. Bearer) * * @var string[] */ protected $apiKeyPrefixes = array(); - - /** + + /** * Username for HTTP basic authentication * * @var string */ protected $username = ''; - + /** * Password for HTTP basic authentication * * @var string */ protected $password = ''; - + /** * The default instance of ApiClient * * @var \{{invokerPackage}}\ApiClient */ protected $defaultHeaders = array(); - + /** * The host * * @var string */ protected $host = '{{basePath}}'; - + /** * Timeout (second) of the HTTP request, by default set to 0, no timeout * - * @var string + * @var string */ protected $curlTimeout = 0; - + /** * User agent of the HTTP request, set to "PHP-Swagger" by default * * @var string */ protected $userAgent = "PHP-Swagger/{{artifactVersion}}"; - + /** * Debug switch (default set to false) * * @var bool */ protected $debug = false; - + /** * Debug file location (log to STDOUT by default) * @@ -126,6 +126,15 @@ class Configuration */ protected $tempFolderPath; + /** + * Indicates if SSL verification should be enabled or disabled. + * + * This is useful if the host uses a self-signed SSL certificate. + * + * @var boolean True if the certificate should be validated, false otherwise. + */ + protected $sslVerification = true; + /** * Constructor */ @@ -133,7 +142,7 @@ class Configuration { $this->tempFolderPath = sys_get_temp_dir(); } - + /** * Sets API key * @@ -147,7 +156,7 @@ class Configuration $this->apiKeys[$apiKeyIdentifier] = $key; return $this; } - + /** * Gets API key * @@ -159,7 +168,7 @@ class Configuration { return isset($this->apiKeys[$apiKeyIdentifier]) ? $this->apiKeys[$apiKeyIdentifier] : null; } - + /** * Sets the prefix for API key (e.g. Bearer) * @@ -173,7 +182,7 @@ class Configuration $this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix; return $this; } - + /** * Gets API key prefix * @@ -185,7 +194,7 @@ class Configuration { return isset($this->apiKeyPrefixes[$apiKeyIdentifier]) ? $this->apiKeyPrefixes[$apiKeyIdentifier] : null; } - + /** * Sets the username for HTTP basic authentication * @@ -198,7 +207,7 @@ class Configuration $this->username = $username; return $this; } - + /** * Gets the username for HTTP basic authentication * @@ -208,7 +217,7 @@ class Configuration { return $this->username; } - + /** * Sets the password for HTTP basic authentication * @@ -221,7 +230,7 @@ class Configuration $this->password = $password; return $this; } - + /** * Gets the password for HTTP basic authentication * @@ -231,7 +240,7 @@ class Configuration { return $this->password; } - + /** * Adds a default header * @@ -245,11 +254,11 @@ class Configuration if (!is_string($headerName)) { throw new \InvalidArgumentException('Header name must be a string.'); } - + $this->defaultHeaders[$headerName] = $headerValue; return $this; } - + /** * Gets the default header * @@ -259,7 +268,7 @@ class Configuration { return $this->defaultHeaders; } - + /** * Deletes a default header * @@ -271,7 +280,7 @@ class Configuration { unset($this->defaultHeaders[$headerName]); } - + /** * Sets the host * @@ -284,7 +293,7 @@ class Configuration $this->host = $host; return $this; } - + /** * Gets the host * @@ -294,7 +303,7 @@ class Configuration { return $this->host; } - + /** * Sets the user agent of the api client * @@ -307,11 +316,11 @@ class Configuration if (!is_string($userAgent)) { throw new \InvalidArgumentException('User-agent must be a string.'); } - + $this->userAgent = $userAgent; return $this; } - + /** * Gets the user agent of the api client * @@ -321,7 +330,7 @@ class Configuration { return $this->userAgent; } - + /** * Sets the HTTP timeout value * @@ -334,11 +343,11 @@ class Configuration if (!is_numeric($seconds) || $seconds < 0) { throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.'); } - + $this->curlTimeout = $seconds; return $this; } - + /** * Gets the HTTP timeout value * @@ -348,10 +357,10 @@ class Configuration { return $this->curlTimeout; } - + /** * Sets debug flag - * + * * @param bool $debug Debug flag * * @return Configuration @@ -361,7 +370,7 @@ class Configuration $this->debug = $debug; return $this; } - + /** * Gets the debug flag * @@ -371,7 +380,7 @@ class Configuration { return $this->debug; } - + /** * Sets the debug file * @@ -384,7 +393,7 @@ class Configuration $this->debugFile = $debugFile; return $this; } - + /** * Gets the debug file * @@ -394,7 +403,7 @@ class Configuration { return $this->debugFile; } - + /** * Sets the temp folder path * @@ -407,7 +416,7 @@ class Configuration $this->tempFolderPath = $tempFolderPath; return $this; } - + /** * Gets the temp folder path * @@ -417,7 +426,30 @@ class Configuration { return $this->tempFolderPath; } - + + /** + * Sets if SSL verification should be enabled or disabled + * + * @param boolean $sslVerification True if the certificate should be validated, false otherwise + * + * @return Configuration + */ + public function setSSLVerification($sslVerification) + { + $this->sslVerification = $sslVerification; + return $this; + } + + /** + * Gets if SSL verification should be enabled or disabled + * + * @return boolean True if the certificate should be validated, false otherwise + */ + public function getSSLVerification() + { + return $this->sslVerification; + } + /** * Gets the default configuration instance * @@ -428,10 +460,10 @@ class Configuration if (self::$_defaultConfiguration == null) { self::$_defaultConfiguration = new Configuration(); } - + return self::$_defaultConfiguration; } - + /** * Sets the detault configuration instance * @@ -443,7 +475,7 @@ class Configuration { self::$_defaultConfiguration = $config; } - + /** * Gets the essential information for debugging * @@ -457,8 +489,8 @@ class Configuration $report .= " Swagger Spec Version: {{version}}\n"; $report .= " SDK Package Version: {{artifactVersion}}\n"; $report .= " Temp Folder Path: ".self::getDefaultConfiguration()->getTempFolderPath()."\n"; - + return $report; } - + } diff --git a/modules/swagger-codegen/src/main/resources/ruby/configuration.mustache b/modules/swagger-codegen/src/main/resources/ruby/configuration.mustache index e74cc17573..0385aaffd8 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/configuration.mustache @@ -138,7 +138,7 @@ module {{moduleName}} end def base_url - url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}" + url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') URI.encode(url) end diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/DefaultGeneratorTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/DefaultGeneratorTest.java index 5da6a01763..3ed3b131c8 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/DefaultGeneratorTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/DefaultGeneratorTest.java @@ -17,11 +17,14 @@ import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.charset.StandardCharsets; import java.util.Arrays; +import java.util.List; +import java.util.Map; import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.fail; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertNull; /** * Tests for DefaultGenerator logic @@ -44,6 +47,102 @@ public class DefaultGeneratorTest { folder.delete(); } + @Test + public void testSecurityWithoutGlobal() throws Exception { + final Swagger swagger = new SwaggerParser().read("src/test/resources/2_0/petstore.json"); + CodegenConfig codegenConfig = new JavaClientCodegen(); + + ClientOptInput clientOptInput = new ClientOptInput().opts(new ClientOpts()).swagger(swagger).config(codegenConfig); + + DefaultGenerator gen = new DefaultGenerator(); + gen.opts(clientOptInput); + Map> paths = gen.processPaths(swagger.getPaths()); + + CodegenSecurity apiKey, petstoreAuth; + + // security of "getPetById": api_key + CodegenOperation getPetById = findCodegenOperationByOperationId(paths, "getPetById"); + assertEquals(getPetById.authMethods.size(), 1); + apiKey = getPetById.authMethods.iterator().next(); + assertEquals(apiKey.name, "api_key"); + assertEquals(apiKey.type, "apiKey"); + + // security of "updatePetWithForm": petstore_auth + CodegenOperation updatePetWithForm = findCodegenOperationByOperationId(paths, "updatePetWithForm"); + assertEquals(updatePetWithForm.authMethods.size(), 1); + petstoreAuth = updatePetWithForm.authMethods.iterator().next(); + assertEquals(petstoreAuth.name, "petstore_auth"); + assertEquals(petstoreAuth.type, "oauth2"); + + // security of "loginUser": null (no global security either) + CodegenOperation loginUser = findCodegenOperationByOperationId(paths, "loginUser"); + assertNull(loginUser.authMethods); + } + + @Test + public void testSecurityWithGlobal() throws Exception { + final Swagger swagger = new SwaggerParser().read("src/test/resources/2_0/globalSecurity.json"); + CodegenConfig codegenConfig = new JavaClientCodegen(); + + ClientOptInput clientOptInput = new ClientOptInput().opts(new ClientOpts()).swagger(swagger).config(codegenConfig); + + DefaultGenerator gen = new DefaultGenerator(); + gen.opts(clientOptInput); + Map> paths = gen.processPaths(swagger.getPaths()); + + CodegenSecurity cs, apiKey, apiKey2, petstoreAuth; + + // security of "getPetById": api_key + CodegenOperation getPetById = findCodegenOperationByOperationId(paths, "getPetById"); + assertEquals(getPetById.authMethods.size(), 1); + apiKey = getPetById.authMethods.iterator().next(); + assertEquals(apiKey.name, "api_key"); + assertEquals(apiKey.type, "apiKey"); + + // security of "updatePetWithForm": petstore_auth + CodegenOperation updatePetWithForm = findCodegenOperationByOperationId(paths, "updatePetWithForm"); + assertEquals(updatePetWithForm.authMethods.size(), 1); + petstoreAuth = updatePetWithForm.authMethods.iterator().next(); + assertEquals(petstoreAuth.name, "petstore_auth"); + assertEquals(petstoreAuth.type, "oauth2"); + + // security of "loginUser": api_key, petstore_auth (from global security) + CodegenOperation loginUser = findCodegenOperationByOperationId(paths, "loginUser"); + assertEquals(loginUser.authMethods.size(), 2); + cs = loginUser.authMethods.get(0); + if ("api_key".equals(cs.name)) { + apiKey = cs; + petstoreAuth = loginUser.authMethods.get(1); + } else { + petstoreAuth = cs; + apiKey = loginUser.authMethods.get(1); + } + assertEquals(apiKey.name, "api_key"); + assertEquals(apiKey.type, "apiKey"); + assertEquals(petstoreAuth.name, "petstore_auth"); + assertEquals(petstoreAuth.type, "oauth2"); + + // security of "logoutUser": null (override global security) + CodegenOperation logoutUser = findCodegenOperationByOperationId(paths, "logoutUser"); + assertNull(logoutUser.authMethods); + + // security of "getUserByName": api_key, api_key2 (override global security) + CodegenOperation getUserByName = findCodegenOperationByOperationId(paths, "getUserByName"); + assertEquals(getUserByName.authMethods.size(), 2); + cs = getUserByName.authMethods.get(0); + if ("api_key".equals(cs.name)) { + apiKey = cs; + apiKey2 = getUserByName.authMethods.get(1); + } else { + apiKey2 = cs; + apiKey = getUserByName.authMethods.get(1); + } + assertEquals(apiKey.name, "api_key"); + assertEquals(apiKey.type, "apiKey"); + assertEquals(apiKey2.name, "api_key2"); + assertEquals(apiKey2.type, "apiKey"); + } + @Test public void testSkipOverwrite() throws Exception { final File output = folder.getRoot(); @@ -89,4 +188,15 @@ public class DefaultGeneratorTest { out.close(); } + private CodegenOperation findCodegenOperationByOperationId(Map> paths, String operationId) { + for (List ops : paths.values()) { + for (CodegenOperation co : ops) { + if (operationId.equals(co.operationId)) { + return co; + } + } + } + return null; + } + } diff --git a/modules/swagger-codegen/src/test/resources/2_0/globalSecurity.json b/modules/swagger-codegen/src/test/resources/2_0/globalSecurity.json new file mode 100644 index 0000000000..36fa87664a --- /dev/null +++ b/modules/swagger-codegen/src/test/resources/2_0/globalSecurity.json @@ -0,0 +1,998 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io 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" + } + }, + "security": [] + } + }, + "/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" + } + }, + "security": [ + { + "api_key": [], + "api_key2": [] + } + ] + }, + "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" + }, + "api_key2": { + "type": "apiKey", + "name": "api_key2", + "in": "query" + }, + "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" + } + } + }, + "security": [ + { + "api_key": [], + "petstore_auth": [ + "write:pets", + "read: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" + } + } + } +} diff --git a/pom.xml b/pom.xml index b2132a048b..bd099a798e 100644 --- a/pom.xml +++ b/pom.xml @@ -426,6 +426,7 @@ samples/client/petstore/java/default samples/client/petstore/java/jersey2 samples/client/petstore/java/okhttp-gson + samples/client/petstore/java/retrofit samples/client/petstore/scala samples/server/petstore/spring-mvc diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java index eabb47e818..5eddeb6b9e 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java @@ -365,8 +365,10 @@ public class ApiInvoker { int code = response.getStatusLine().getStatusCode(); String responseString = null; - if(code == 204) + if(code == 204) { responseString = ""; + return responseString; + } else if(code >= 200 && code < 300) { if(response.getEntity() != null) { HttpEntity resEntity = response.getEntity(); diff --git a/samples/client/petstore/java/bin/io/swagger/client/ApiClient.class b/samples/client/petstore/java/bin/io/swagger/client/ApiClient.class new file mode 100644 index 0000000000..db57f1ecc8 Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/ApiClient.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/ApiClientTest.class b/samples/client/petstore/java/bin/io/swagger/client/ApiClientTest.class new file mode 100644 index 0000000000..99c30aef01 Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/ApiClientTest.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/ApiException.class b/samples/client/petstore/java/bin/io/swagger/client/ApiException.class new file mode 100644 index 0000000000..5004d8cf08 Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/ApiException.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/Configuration.class b/samples/client/petstore/java/bin/io/swagger/client/Configuration.class new file mode 100644 index 0000000000..f90a4f4103 Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/Configuration.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/ConfigurationTest.class b/samples/client/petstore/java/bin/io/swagger/client/ConfigurationTest.class new file mode 100644 index 0000000000..f3f80dbccd Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/ConfigurationTest.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/JsonUtil.class b/samples/client/petstore/java/bin/io/swagger/client/JsonUtil.class new file mode 100644 index 0000000000..fd6b693813 Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/JsonUtil.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/StringUtil.class b/samples/client/petstore/java/bin/io/swagger/client/StringUtil.class new file mode 100644 index 0000000000..5283ccc73c Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/StringUtil.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/StringUtilTest.class b/samples/client/petstore/java/bin/io/swagger/client/StringUtilTest.class new file mode 100644 index 0000000000..339bbbf381 Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/StringUtilTest.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/api/PetApi.class b/samples/client/petstore/java/bin/io/swagger/client/api/PetApi.class new file mode 100644 index 0000000000..dd70c18fdb Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/api/PetApi.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/api/StoreApi.class b/samples/client/petstore/java/bin/io/swagger/client/api/StoreApi.class new file mode 100644 index 0000000000..491a30d46c Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/api/StoreApi.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/api/UserApi.class b/samples/client/petstore/java/bin/io/swagger/client/api/UserApi.class new file mode 100644 index 0000000000..1c71a2e89f Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/api/UserApi.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/auth/ApiKeyAuth.class b/samples/client/petstore/java/bin/io/swagger/client/auth/ApiKeyAuth.class new file mode 100644 index 0000000000..c829299e9f Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/auth/ApiKeyAuth.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/auth/ApiKeyAuthTest.class b/samples/client/petstore/java/bin/io/swagger/client/auth/ApiKeyAuthTest.class new file mode 100644 index 0000000000..ff11956d79 Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/auth/ApiKeyAuthTest.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/auth/Authentication.class b/samples/client/petstore/java/bin/io/swagger/client/auth/Authentication.class new file mode 100644 index 0000000000..b00bf5b2dc Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/auth/Authentication.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/auth/HttpBasicAuth.class b/samples/client/petstore/java/bin/io/swagger/client/auth/HttpBasicAuth.class new file mode 100644 index 0000000000..e80e9dbbe8 Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/auth/HttpBasicAuth.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/auth/HttpBasicAuthTest.class b/samples/client/petstore/java/bin/io/swagger/client/auth/HttpBasicAuthTest.class new file mode 100644 index 0000000000..b591b7732d Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/auth/HttpBasicAuthTest.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/auth/OAuth.class b/samples/client/petstore/java/bin/io/swagger/client/auth/OAuth.class new file mode 100644 index 0000000000..9ad51aeea6 Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/auth/OAuth.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/model/Category.class b/samples/client/petstore/java/bin/io/swagger/client/model/Category.class new file mode 100644 index 0000000000..304329daf7 Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/model/Category.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/model/Order$StatusEnum.class b/samples/client/petstore/java/bin/io/swagger/client/model/Order$StatusEnum.class new file mode 100644 index 0000000000..d40e6a0d0a Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/model/Order$StatusEnum.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/model/Order.class b/samples/client/petstore/java/bin/io/swagger/client/model/Order.class new file mode 100644 index 0000000000..e777d21105 Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/model/Order.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/model/Pet$StatusEnum.class b/samples/client/petstore/java/bin/io/swagger/client/model/Pet$StatusEnum.class new file mode 100644 index 0000000000..c13ccdbb1f Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/model/Pet$StatusEnum.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/model/Pet.class b/samples/client/petstore/java/bin/io/swagger/client/model/Pet.class new file mode 100644 index 0000000000..b7f0e5088c Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/model/Pet.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/model/Tag.class b/samples/client/petstore/java/bin/io/swagger/client/model/Tag.class new file mode 100644 index 0000000000..e1af348c63 Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/model/Tag.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/client/model/User.class b/samples/client/petstore/java/bin/io/swagger/client/model/User.class new file mode 100644 index 0000000000..cf0fe38328 Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/client/model/User.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/petstore/test/PetApiTest.class b/samples/client/petstore/java/bin/io/swagger/petstore/test/PetApiTest.class new file mode 100644 index 0000000000..0ef877a081 Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/petstore/test/PetApiTest.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/petstore/test/StoreApiTest.class b/samples/client/petstore/java/bin/io/swagger/petstore/test/StoreApiTest.class new file mode 100644 index 0000000000..0d4d9014bd Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/petstore/test/StoreApiTest.class differ diff --git a/samples/client/petstore/java/bin/io/swagger/petstore/test/UserApiTest.class b/samples/client/petstore/java/bin/io/swagger/petstore/test/UserApiTest.class new file mode 100644 index 0000000000..8086430384 Binary files /dev/null and b/samples/client/petstore/java/bin/io/swagger/petstore/test/UserApiTest.class differ diff --git a/samples/client/petstore/java/default/build.gradle b/samples/client/petstore/java/default/build.gradle new file mode 100644 index 0000000000..baa5ce97b0 --- /dev/null +++ b/samples/client/petstore/java/default/build.gradle @@ -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" +} diff --git a/samples/client/petstore/java/default/gradle.properties b/samples/client/petstore/java/default/gradle.properties new file mode 100644 index 0000000000..05644f0754 --- /dev/null +++ b/samples/client/petstore/java/default/gradle.properties @@ -0,0 +1,2 @@ +# Uncomment to build for Android +#target = android \ No newline at end of file diff --git a/samples/client/petstore/java/default/settings.gradle b/samples/client/petstore/java/default/settings.gradle new file mode 100644 index 0000000000..55640f7512 --- /dev/null +++ b/samples/client/petstore/java/default/settings.gradle @@ -0,0 +1 @@ +rootProject.name = "swagger-java-client" \ No newline at end of file diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiClient.java index 27ab8e3a03..17709ee88d 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiClient.java @@ -39,7 +39,7 @@ import io.swagger.client.auth.HttpBasicAuth; import io.swagger.client.auth.ApiKeyAuth; import io.swagger.client.auth.OAuth; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class ApiClient { private Map hostMap = new HashMap(); private Map defaultHeaderMap = new HashMap(); diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiException.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiException.java index 3822e42b01..c09e4939e9 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiException.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiException.java @@ -3,7 +3,7 @@ package io.swagger.client; import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class ApiException extends Exception { private int code = 0; private Map> responseHeaders = null; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/Configuration.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/Configuration.java index 7cec037532..692018a52d 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/Configuration.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/Configuration.java @@ -1,6 +1,6 @@ package io.swagger.client; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class Configuration { private static ApiClient defaultApiClient = new ApiClient(); diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/JSON.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/JSON.java index 41f916b0fa..3e15ec01d3 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/JSON.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/JSON.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.datatype.joda.*; import java.io.IOException; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class JSON { private ObjectMapper mapper; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/Pair.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/Pair.java index bf84b4d530..bc45efb5ce 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/Pair.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/Pair.java @@ -1,6 +1,6 @@ package io.swagger.client; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class Pair { private String name = ""; private String value = ""; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/StringUtil.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/StringUtil.java index f5346b74f4..c2f943c731 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/StringUtil.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/StringUtil.java @@ -1,6 +1,6 @@ package io.swagger.client; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class StringUtil { /** * Check if the given array contains the given value (with case-insensitive comparison). diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/TypeRef.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/TypeRef.java index 70a2b57171..c30d70add6 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/TypeRef.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/TypeRef.java @@ -3,7 +3,7 @@ package io.swagger.client; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class TypeRef { private final Type type; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/PetApi.java index fd5c75572a..2c7d0be827 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/PetApi.java @@ -17,7 +17,7 @@ import java.io.File; import java.util.Map; import java.util.HashMap; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class PetApi { private ApiClient apiClient; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/StoreApi.java index 7ad51e326c..8cb88dfcd3 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/StoreApi.java @@ -17,7 +17,7 @@ import java.io.File; import java.util.Map; import java.util.HashMap; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class StoreApi { private ApiClient apiClient; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/UserApi.java index b165f06626..8db3eaffac 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/UserApi.java @@ -17,7 +17,7 @@ import java.io.File; import java.util.Map; import java.util.HashMap; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class UserApi { private ApiClient apiClient; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/ApiKeyAuth.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/ApiKeyAuth.java index ebf0e735ef..bc6e2f87de 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/ApiKeyAuth.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/ApiKeyAuth.java @@ -5,7 +5,7 @@ import io.swagger.client.Pair; import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class ApiKeyAuth implements Authentication { private final String location; private final String paramName; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/Authentication.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/Authentication.java index 787b10f35d..45a92c1323 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/Authentication.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/Authentication.java @@ -5,7 +5,7 @@ import io.swagger.client.Pair; import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public interface Authentication { /** Apply authentication settings to header and query params. */ void applyToParams(List queryParams, Map headerParams); diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/HttpBasicAuth.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/HttpBasicAuth.java index 19336699f0..bb14cab5a2 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/HttpBasicAuth.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/HttpBasicAuth.java @@ -8,7 +8,7 @@ import java.util.List; import java.io.UnsupportedEncodingException; import javax.xml.bind.DatatypeConverter; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class HttpBasicAuth implements Authentication { private String username; private String password; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/OAuth.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/OAuth.java index d4ccd9bf95..3e0fade5e8 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/OAuth.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/OAuth.java @@ -5,7 +5,7 @@ import io.swagger.client.Pair; import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class OAuth implements Authentication { @Override public void applyToParams(List queryParams, Map headerParams) { diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Category.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Category.java index 1be35cc437..b12b44dd1c 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Category.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Category.java @@ -9,7 +9,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; @ApiModel(description = "") -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class Category { private Long id = null; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Order.java index 4da1e926be..7e4e43420c 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Order.java @@ -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-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class Order { private Long id = null; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Pet.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Pet.java index 6b947af109..ba49723288 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Pet.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Pet.java @@ -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-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class Pet { private Long id = null; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Tag.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Tag.java index e34e5b727b..6891859078 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Tag.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Tag.java @@ -9,7 +9,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; @ApiModel(description = "") -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class Tag { private Long id = null; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/User.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/User.java index 38d95c8992..271bf3b19d 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/User.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/User.java @@ -9,7 +9,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; @ApiModel(description = "") -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T08:48:59.888-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T10:56:59.550-07:00") public class User { private Long id = null; diff --git a/samples/client/petstore/java/jersey2/build.gradle b/samples/client/petstore/java/jersey2/build.gradle new file mode 100644 index 0000000000..9727e5693e --- /dev/null +++ b/samples/client/petstore/java/jersey2/build.gradle @@ -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" +} diff --git a/samples/client/petstore/java/jersey2/gradle.properties b/samples/client/petstore/java/jersey2/gradle.properties new file mode 100644 index 0000000000..05644f0754 --- /dev/null +++ b/samples/client/petstore/java/jersey2/gradle.properties @@ -0,0 +1,2 @@ +# Uncomment to build for Android +#target = android \ No newline at end of file diff --git a/samples/client/petstore/java/jersey2/settings.gradle b/samples/client/petstore/java/jersey2/settings.gradle new file mode 100644 index 0000000000..498d426abe --- /dev/null +++ b/samples/client/petstore/java/jersey2/settings.gradle @@ -0,0 +1 @@ +rootProject.name = "swagger-petstore-jersey2" \ No newline at end of file diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/PetApi.java index b3ce29f1a3..28231c1080 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/PetApi.java @@ -6,18 +6,16 @@ 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.*; +<<<<<<< HEAD @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-19T23:12:20.646-07:00") +======= +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-16T10:40:45.419+08:00") +>>>>>>> master public class PetApi { private ApiClient apiClient; @@ -243,7 +241,11 @@ public class PetApi { }; final String contentType = apiClient.selectHeaderContentType(contentTypes); +<<<<<<< HEAD String[] authNames = new String[] { "api_key", "petstore_auth" }; +======= + String[] authNames = new String[] { "api_key" }; +>>>>>>> master TypeRef returnType = new TypeRef() {}; diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/StoreApi.java index 34aafea0b6..7fd5fdb57f 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/StoreApi.java @@ -6,18 +6,16 @@ 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.*; +<<<<<<< HEAD @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-19T23:12:20.646-07:00") +======= +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-09T21:30:19.416+08:00") +>>>>>>> master public class StoreApi { private ApiClient apiClient; diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/UserApi.java index 026e18d7d4..38e2e777ad 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/UserApi.java @@ -6,18 +6,16 @@ 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.*; +<<<<<<< HEAD @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-19T23:12:20.646-07:00") +======= +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-09T21:30:19.416+08:00") +>>>>>>> master public class UserApi { private ApiClient apiClient; diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Order.java index f315181195..118292a057 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Order.java @@ -10,7 +10,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; @ApiModel(description = "") +<<<<<<< HEAD @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-19T23:12:20.646-07:00") +======= +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-09T21:30:19.416+08:00") +>>>>>>> master public class Order { private Long id = null; diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Pet.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Pet.java index ca3bcb3168..bd041661bb 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Pet.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Pet.java @@ -12,7 +12,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; @ApiModel(description = "") +<<<<<<< HEAD @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-19T23:12:20.646-07:00") +======= +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-09T21:30:19.416+08:00") +>>>>>>> master public class Pet { private Long id = null; diff --git a/samples/client/petstore/java/okhttp-gson/build.gradle b/samples/client/petstore/java/okhttp-gson/build.gradle index ada6a99257..eea46b819d 100644 --- a/samples/client/petstore/java/okhttp-gson/build.gradle +++ b/samples/client/petstore/java/okhttp-gson/build.gradle @@ -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 -} diff --git a/samples/client/petstore/java/okhttp-gson/gradle.properties b/samples/client/petstore/java/okhttp-gson/gradle.properties new file mode 100644 index 0000000000..05644f0754 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/gradle.properties @@ -0,0 +1,2 @@ +# Uncomment to build for Android +#target = android \ No newline at end of file diff --git a/samples/client/petstore/java/okhttp-gson/settings.gradle b/samples/client/petstore/java/okhttp-gson/settings.gradle new file mode 100644 index 0000000000..b73eec8459 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/settings.gradle @@ -0,0 +1 @@ +rootProject.name = "swagger-petstore-okhttp-gson" \ No newline at end of file diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java index ff6a1e9b55..20d4aa85a2 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java @@ -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; @@ -297,7 +290,11 @@ public class PetApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); +<<<<<<< HEAD String[] authNames = new String[] { "api_key", "petstore_auth" }; +======= + String[] authNames = new String[] { "api_key" }; +>>>>>>> master return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/StoreApi.java index a3fb14bb52..cb780538e1 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/StoreApi.java @@ -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; diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/UserApi.java index ce1bae64a4..a04470b3b4 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/UserApi.java @@ -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; diff --git a/samples/client/petstore/java/retrofit/build.gradle b/samples/client/petstore/java/retrofit/build.gradle new file mode 100644 index 0000000000..710d9da9a5 --- /dev/null +++ b/samples/client/petstore/java/retrofit/build.gradle @@ -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" +} diff --git a/samples/client/petstore/java/retrofit/gradle.properties b/samples/client/petstore/java/retrofit/gradle.properties new file mode 100644 index 0000000000..05644f0754 --- /dev/null +++ b/samples/client/petstore/java/retrofit/gradle.properties @@ -0,0 +1,2 @@ +# Uncomment to build for Android +#target = android \ No newline at end of file diff --git a/samples/client/petstore/java/retrofit/settings.gradle b/samples/client/petstore/java/retrofit/settings.gradle new file mode 100644 index 0000000000..7e540c099d --- /dev/null +++ b/samples/client/petstore/java/retrofit/settings.gradle @@ -0,0 +1 @@ +rootProject.name = "swagger-petstore-retrofit" \ No newline at end of file diff --git a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/CollectionFormats.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/CollectionFormats.java new file mode 100644 index 0000000000..c3cf525751 --- /dev/null +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/CollectionFormats.java @@ -0,0 +1,95 @@ +package io.swagger.client; + +import java.util.Arrays; +import java.util.List; + +public class CollectionFormats { + + public static class CSVParams { + + protected List params; + + public CSVParams() { + } + + public CSVParams(List params) { + this.params = params; + } + + public CSVParams(String... params) { + this.params = Arrays.asList(params); + } + + public List getParams() { + return params; + } + + public void setParams(List params) { + this.params = params; + } + + @Override + public String toString() { + return StringUtil.join(params.toArray(new String[0]), ","); + } + + } + + public static class SSVParams extends CSVParams { + + public SSVParams() { + } + + public SSVParams(List params) { + super(params); + } + + public SSVParams(String... params) { + super(params); + } + + @Override + public String toString() { + return StringUtil.join(params.toArray(new String[0]), " "); + } + } + + public static class TSVParams extends CSVParams { + + public TSVParams() { + } + + public TSVParams(List params) { + super(params); + } + + public TSVParams(String... params) { + super(params); + } + + @Override + public String toString() { + return StringUtil.join( params.toArray(new String[0]), "\t"); + } + } + + public static class PIPESParams extends CSVParams { + + public PIPESParams() { + } + + public PIPESParams(List params) { + super(params); + } + + public PIPESParams(String... params) { + super(params); + } + + @Override + public String toString() { + return StringUtil.join(params.toArray(new String[0]), "|"); + } + } + +} diff --git a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/StringUtil.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/StringUtil.java index bac4881beb..3dccfe0b9a 100644 --- a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/StringUtil.java +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/StringUtil.java @@ -1,6 +1,10 @@ package io.swagger.client; +<<<<<<< HEAD @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-19T23:12:22.261-07:00") +======= +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-11T00:10:38.251+02:00") +>>>>>>> master public class StringUtil { /** * Check if the given array contains the given value (with case-insensitive comparison). diff --git a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/PetApi.java index cd4dbe866a..1746009aa7 100644 --- a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/PetApi.java @@ -1,15 +1,16 @@ package io.swagger.client.api; -import io.swagger.client.model.*; +import io.swagger.client.CollectionFormats.*; 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 +21,7 @@ public interface PetApi { * @return Void */ - @PUT("/pet") + @PUT("/pet") Void updatePet( @Body Pet body ); @@ -29,14 +30,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 cb - ); + ); /** * Add a new pet to the store @@ -46,7 +47,7 @@ public interface PetApi { * @return Void */ - @POST("/pet") + @POST("/pet") Void addPet( @Body Pet body ); @@ -55,14 +56,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 cb - ); + ); /** * Finds Pets by status @@ -72,7 +73,7 @@ public interface PetApi { * @return List */ - @GET("/pet/findByStatus") + @GET("/pet/findByStatus") List findPetsByStatus( @Query("status") List status ); @@ -81,14 +82,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 status, Callback> cb - ); + ); /** * Finds Pets by tags @@ -98,7 +99,7 @@ public interface PetApi { * @return List */ - @GET("/pet/findByTags") + @GET("/pet/findByTags") List findPetsByTags( @Query("tags") List tags ); @@ -107,14 +108,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 tags, Callback> cb - ); + ); /** * Find pet by ID @@ -124,7 +125,7 @@ public interface PetApi { * @return Pet */ - @GET("/pet/{petId}") + @GET("/pet/{petId}") Pet getPetById( @Path("petId") Long petId ); @@ -133,14 +134,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 cb - ); + ); /** * Updates a pet in the store with form data @@ -153,7 +154,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 +165,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 cb - ); + ); /** * Deletes a pet @@ -183,7 +184,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 +194,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 cb - ); + ); /** * uploads an image @@ -213,7 +214,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 +225,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 cb - ); + ); } diff --git a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/StoreApi.java index 1c0a8291d0..4d6d3aa7c0 100644 --- a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/StoreApi.java @@ -1,15 +1,16 @@ package io.swagger.client.api; -import io.swagger.client.model.*; +import io.swagger.client.CollectionFormats.*; 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 +20,21 @@ public interface StoreApi { * @return Map */ - @GET("/store/inventory") + @GET("/store/inventory") Map 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> cb - ); + ); /** * Place an order for a pet @@ -43,7 +44,7 @@ public interface StoreApi { * @return Order */ - @POST("/store/order") + @POST("/store/order") Order placeOrder( @Body Order body ); @@ -52,14 +53,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 cb - ); + ); /** * Find purchase order by ID @@ -69,7 +70,7 @@ public interface StoreApi { * @return Order */ - @GET("/store/order/{orderId}") + @GET("/store/order/{orderId}") Order getOrderById( @Path("orderId") String orderId ); @@ -78,14 +79,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 cb - ); + ); /** * Delete purchase order by ID @@ -95,7 +96,7 @@ public interface StoreApi { * @return Void */ - @DELETE("/store/order/{orderId}") + @DELETE("/store/order/{orderId}") Void deleteOrder( @Path("orderId") String orderId ); @@ -104,13 +105,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 cb - ); + ); } diff --git a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/UserApi.java index 162222bc0f..ff4b456297 100644 --- a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/UserApi.java @@ -1,15 +1,16 @@ package io.swagger.client.api; -import io.swagger.client.model.*; +import io.swagger.client.CollectionFormats.*; 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 +21,7 @@ public interface UserApi { * @return Void */ - @POST("/user") + @POST("/user") Void createUser( @Body User body ); @@ -29,14 +30,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 cb - ); + ); /** * Creates list of users with given input array @@ -46,7 +47,7 @@ public interface UserApi { * @return Void */ - @POST("/user/createWithArray") + @POST("/user/createWithArray") Void createUsersWithArrayInput( @Body List body ); @@ -55,14 +56,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 body, Callback cb - ); + ); /** * Creates list of users with given input array @@ -72,7 +73,7 @@ public interface UserApi { * @return Void */ - @POST("/user/createWithList") + @POST("/user/createWithList") Void createUsersWithListInput( @Body List body ); @@ -81,14 +82,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 body, Callback cb - ); + ); /** * Logs user into the system @@ -99,7 +100,7 @@ public interface UserApi { * @return String */ - @GET("/user/login") + @GET("/user/login") String loginUser( @Query("username") String username, @Query("password") String password ); @@ -109,14 +110,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 cb - ); + ); /** * Logs out current logged in user session @@ -125,21 +126,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 cb - ); + ); /** * Get user by user name @@ -149,7 +150,7 @@ public interface UserApi { * @return User */ - @GET("/user/{username}") + @GET("/user/{username}") User getUserByName( @Path("username") String username ); @@ -158,14 +159,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 cb - ); + ); /** * Updated user @@ -176,7 +177,7 @@ public interface UserApi { * @return Void */ - @PUT("/user/{username}") + @PUT("/user/{username}") Void updateUser( @Path("username") String username, @Body User body ); @@ -186,14 +187,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 cb - ); + ); /** * Delete user @@ -203,7 +204,7 @@ public interface UserApi { * @return Void */ - @DELETE("/user/{username}") + @DELETE("/user/{username}") Void deleteUser( @Path("username") String username ); @@ -212,13 +213,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 cb - ); + ); } diff --git a/samples/client/petstore/ruby/lib/petstore/configuration.rb b/samples/client/petstore/ruby/lib/petstore/configuration.rb index 008be48ee4..04479b53db 100644 --- a/samples/client/petstore/ruby/lib/petstore/configuration.rb +++ b/samples/client/petstore/ruby/lib/petstore/configuration.rb @@ -138,7 +138,7 @@ module Petstore end def base_url - url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}" + url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') URI.encode(url) end diff --git a/samples/client/petstore/ruby/spec/configuration_spec.rb b/samples/client/petstore/ruby/spec/configuration_spec.rb new file mode 100644 index 0000000000..9f86f5602b --- /dev/null +++ b/samples/client/petstore/ruby/spec/configuration_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe Petstore::Configuration do + let(:config) { Petstore::Configuration.instance } + + before(:each) do + Petstore.configure do |c| + c.host = 'petstore.swagger.io' + c.base_path = 'v2' + end + end + + describe '#base_url' do + it 'should have the default value' do + config.base_url.should == 'http://petstore.swagger.io/v2' + end + + it 'should remove trailing slashes' do + [nil, '', '/', '//'].each do |base_path| + config.base_path = base_path + config.base_url.should == 'http://petstore.swagger.io' + end + end + end +end