diff --git a/README.md b/README.md index 1bb54548033..98b69dee3c9 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Check out [Swagger-Spec](https://github.com/OAI/OpenAPI-Specification) for addit - [Ruby Sinatra](#ruby-sinatra) - [Scala Scalatra](#scala-scalatra) - [Java JAX-RS (Java JAX-RS (Jersey v1.18)](#java-jax-rs-jersey-v118) - - [Java JAX-RS (Apache CXF 3)](#java-jax-rs-apache-cxf-3) + - [Java JAX-RS (Apache CXF 2 / 3)](#java-jax-rs-apache-cxf-2--3) - [Java Spring MVC](#java-spring-mvc) - [Haskell Servant](#haskell-servant) - [ASP.NET 5 Web API](#aspnet-5-web-api) @@ -619,7 +619,7 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ -o samples/server/petstore/jaxrs-jersey ``` -### Java JAX-RS (Apache CXF 3) +### Java JAX-RS (Apache CXF 2 / 3) ``` java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ @@ -628,6 +628,23 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ -o samples/server/petstore/jaxrs-cxf ``` +This Codegen only generate a minimalist server stub. You must add the CXF dependency to your classpath (eg: with Maven) +If you are using CXF v2.x, you must provided a custom ```ResourceComparator``` class. This class will help CXF to choose the good resource interface for mapping an incomming request. The default behavior of CXF v2.x is not correct when many resources interface have the same global path. +See: See http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Customselectionbetweenmultipleresources + +You can found this class here: https://github.com/hiveship/CXF2-resource-comparator/blob/master/src/main/java/CXFInterfaceComparator.java +TODO: This class could be directly generated by the Codegen. + +You must register this class into your JAX-RS configuration file: +```xml + + + +``` + +This is no longer necessary if you are using CXF >=v3.x + + ### Java Spring MVC ``` 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 87c8b36aad4..d9cf78037b7 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 @@ -343,7 +343,7 @@ public class DefaultCodegen { } /** - * Return the capitalized file name of the model test + * Return the capitalized file name of the model * * @param name the model name * @return the file name of the model diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java index d69b68aafe7..5321e3a59db 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java @@ -2,20 +2,23 @@ package io.swagger.codegen.languages; import java.io.File; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import io.swagger.codegen.CliOption; import io.swagger.codegen.CodegenConstants; +import io.swagger.codegen.CodegenModel; import io.swagger.codegen.CodegenOperation; +import io.swagger.codegen.CodegenProperty; import io.swagger.models.Operation; public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen -{ +{ public JavaCXFServerCodegen() { super(); - + supportsInheritance = true; sourceFolder = "src/gen/java"; invokerPackage = "io.swagger.api"; artifactId = "swagger-jaxrs-server"; @@ -28,6 +31,11 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen additionalProperties.put("title", title); + typeMapping.put("date", "LocalDate"); + typeMapping.put("DateTime", "javax.xml.datatype.XMLGregorianCalendar"); // Map DateTime fields to Java standart class 'XMLGregorianCalendar' + + importMapping.put("LocalDate", "org.joda.time.LocalDate"); + super.embeddedTemplateDir = templateDir = JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "cxf"; for ( int i = 0; i < cliOptions.size(); i++ ) { @@ -36,21 +44,30 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen break; } } - - cliOptions.add(new CliOption(CodegenConstants.IMPL_FOLDER, CodegenConstants.IMPL_FOLDER_DESC)); + + CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use"); + library.setDefault(DEFAULT_LIBRARY); + + Map supportedLibraries = new LinkedHashMap(); + + supportedLibraries.put(DEFAULT_LIBRARY, "CXF"); + library.setEnum(supportedLibraries); + + cliOptions.add(library); + cliOptions.add(new CliOption(CodegenConstants.IMPL_FOLDER, CodegenConstants.IMPL_FOLDER_DESC)); cliOptions.add(new CliOption("title", "a title describing the application")); } - + @Override public void processOpts() { super.processOpts(); sourceFolder = "gen" + File.separator + "java"; - - modelTemplateFiles.clear(); - modelTemplateFiles.put("entityModel.mustache", ".java"); - - supportingFiles.clear(); + supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen + + //TODO + //final String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/"); + //supportingFiles.add(new SupportingFile("CXF2InterfaceComparator.mustache", invokerFolder, "CXF2InterfaceComparator.java")); } @Override @@ -58,14 +75,24 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen { return "jaxrs-cxf"; } - @Override public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map> operations) { super.addOperationToGroup(tag, resourcePath, operation, co, operations); co.subresourceOperation = !co.path.isEmpty(); } - + + @Override + public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { + super.postProcessModelProperty(model, property); + model.imports.remove("ApiModelProperty"); + model.imports.remove("ApiModel"); + model.imports.remove("JsonSerialize"); + model.imports.remove("ToStringSerializer"); + model.imports.remove("JsonValue"); + model.imports.remove("JsonProperty"); + } + @Override public String getHelp() { 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 121c62eadd1..78f3653671b 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 @@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory; import java.util.*; -public class JavaInflectorServerCodegen extends JavaClientCodegen implements CodegenConfig { +public class JavaInflectorServerCodegen extends JavaClientCodegen { private static final Logger LOGGER = LoggerFactory.getLogger(JavaInflectorServerCodegen.class); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java index 577f7de8412..7320c9320cf 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java @@ -24,265 +24,310 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public class SwiftCodegen extends DefaultCodegen implements CodegenConfig { - public static final String PROJECT_NAME = "projectName"; - public static final String RESPONSE_AS = "responseAs"; - public static final String UNWRAP_REQUIRED = "unwrapRequired"; - public static final String POD_SOURCE = "podSource"; - public static final String POD_AUTHORS = "podAuthors"; - public static final String POD_SOCIAL_MEDIA_URL = "podSocialMediaURL"; - public static final String POD_DOCSET_URL = "podDocsetURL"; - public static final String POD_LICENSE = "podLicense"; - public static final String POD_HOMEPAGE = "podHomepage"; - public static final String POD_SUMMARY = "podSummary"; - public static final String POD_DESCRIPTION = "podDescription"; - public static final String POD_SCREENSHOTS = "podScreenshots"; - public static final String POD_DOCUMENTATION_URL = "podDocumentationURL"; - public static final String SWIFT_USE_API_NAMESPACE = "swiftUseApiNamespace"; - protected static final String LIBRARY_PROMISE_KIT = "PromiseKit"; - protected static final String[] RESPONSE_LIBRARIES = { LIBRARY_PROMISE_KIT }; - protected String projectName = "SwaggerClient"; - protected boolean unwrapRequired; - protected boolean swiftUseApiNamespace; - protected String[] responseAs = new String[0]; - protected String sourceFolder = "Classes" + File.separator + "Swaggers"; - private static final Pattern PATH_PARAM_PATTERN = Pattern.compile("\\{[a-zA-Z_]+\\}"); + public static final String PROJECT_NAME = "projectName"; + public static final String RESPONSE_AS = "responseAs"; + public static final String UNWRAP_REQUIRED = "unwrapRequired"; + public static final String POD_SOURCE = "podSource"; + public static final String POD_AUTHORS = "podAuthors"; + public static final String POD_SOCIAL_MEDIA_URL = "podSocialMediaURL"; + public static final String POD_DOCSET_URL = "podDocsetURL"; + public static final String POD_LICENSE = "podLicense"; + public static final String POD_HOMEPAGE = "podHomepage"; + public static final String POD_SUMMARY = "podSummary"; + public static final String POD_DESCRIPTION = "podDescription"; + public static final String POD_SCREENSHOTS = "podScreenshots"; + public static final String POD_DOCUMENTATION_URL = "podDocumentationURL"; + public static final String SWIFT_USE_API_NAMESPACE = "swiftUseApiNamespace"; + protected static final String LIBRARY_PROMISE_KIT = "PromiseKit"; + protected static final String[] RESPONSE_LIBRARIES = { LIBRARY_PROMISE_KIT }; + protected String projectName = "SwaggerClient"; + protected boolean unwrapRequired; + protected boolean swiftUseApiNamespace; + protected String[] responseAs = new String[0]; + protected String sourceFolder = "Classes" + File.separator + "Swaggers"; + private static final Pattern PATH_PARAM_PATTERN = Pattern.compile("\\{[a-zA-Z_]+\\}"); - @Override - public CodegenType getTag() { - return CodegenType.CLIENT; - } - - @Override - public String getName() { - return "swift"; - } - - @Override - public String getHelp() { - return "Generates a swift client library."; - } - - public SwiftCodegen() { - super(); - outputFolder = "generated-code" + File.separator + "swift"; - modelTemplateFiles.put("model.mustache", ".swift"); - apiTemplateFiles.put("api.mustache", ".swift"); - embeddedTemplateDir = templateDir = "swift"; - apiPackage = File.separator + "APIs"; - modelPackage = File.separator + "Models"; - - languageSpecificPrimitives = new HashSet( - Arrays.asList( - "Int", - "Float", - "Double", - "Bool", - "Void", - "String", - "Character", - "AnyObject") - ); - defaultIncludes = new HashSet( - Arrays.asList( - "NSDate", - "Array", - "Dictionary", - "Set", - "Any", - "Empty", - "AnyObject") - ); - setReservedWordsLowerCase( - Arrays.asList( - "class", "break", "as", "associativity", "deinit", "case", "dynamicType", "convenience", "enum", "continue", - "false", "dynamic", "extension", "default", "is", "didSet", "func", "do", "nil", "final", "import", "else", - "self", "get", "init", "fallthrough", "Self", "infix", "internal", "for", "super", "inout", "let", "if", - "true", "lazy", "operator", "in", "COLUMN", "left", "private", "return", "FILE", "mutating", "protocol", - "switch", "FUNCTION", "none", "public", "where", "LINE", "nonmutating", "static", "while", "optional", - "struct", "override", "subscript", "postfix", "typealias", "precedence", "var", "prefix", "Protocol", - "required", "right", "set", "Type", "unowned", "weak") - ); - - typeMapping = new HashMap(); - typeMapping.put("array", "Array"); - typeMapping.put("List", "Array"); - typeMapping.put("map", "Dictionary"); - typeMapping.put("date", "NSDate"); - typeMapping.put("Date", "NSDate"); - typeMapping.put("DateTime", "NSDate"); - typeMapping.put("boolean", "Bool"); - typeMapping.put("string", "String"); - typeMapping.put("char", "Character"); - typeMapping.put("short", "Int"); - typeMapping.put("int", "Int"); - typeMapping.put("long", "Int"); - typeMapping.put("integer", "Int"); - typeMapping.put("Integer", "Int"); - typeMapping.put("float", "Float"); - typeMapping.put("number", "Double"); - typeMapping.put("double", "Double"); - typeMapping.put("object", "AnyObject"); - typeMapping.put("file", "NSURL"); - //TODO binary should be mapped to byte array - // mapped to String as a workaround - typeMapping.put("binary", "String"); - - importMapping = new HashMap(); - - cliOptions.add(new CliOption(PROJECT_NAME, "Project name in Xcode")); - cliOptions.add(new CliOption(RESPONSE_AS, "Optionally use libraries to manage response. Currently " + - StringUtils.join(RESPONSE_LIBRARIES, ", ") + " are available.")); - cliOptions.add(new CliOption(UNWRAP_REQUIRED, "Treat 'required' properties in response as non-optional " + - "(which would crash the app if api returns null as opposed to required option specified in json schema")); - cliOptions.add(new CliOption(POD_SOURCE, "Source information used for Podspec")); - cliOptions.add(new CliOption(CodegenConstants.POD_VERSION, "Version used for Podspec")); - cliOptions.add(new CliOption(POD_AUTHORS, "Authors used for Podspec")); - cliOptions.add(new CliOption(POD_SOCIAL_MEDIA_URL, "Social Media URL used for Podspec")); - cliOptions.add(new CliOption(POD_DOCSET_URL, "Docset URL used for Podspec")); - cliOptions.add(new CliOption(POD_LICENSE, "License used for Podspec")); - cliOptions.add(new CliOption(POD_HOMEPAGE, "Homepage used for Podspec")); - cliOptions.add(new CliOption(POD_SUMMARY, "Summary used for Podspec")); - cliOptions.add(new CliOption(POD_DESCRIPTION, "Description used for Podspec")); - cliOptions.add(new CliOption(POD_SCREENSHOTS, "Screenshots used for Podspec")); - cliOptions.add(new CliOption(POD_DOCUMENTATION_URL, "Documentation URL used for Podspec")); - cliOptions.add(new CliOption(SWIFT_USE_API_NAMESPACE, "Flag to make all the API classes inner-class of {{projectName}}API")); - } - - @Override - public void processOpts() { - super.processOpts(); - - // Setup project name - if (additionalProperties.containsKey(PROJECT_NAME)) { - setProjectName((String) additionalProperties.get(PROJECT_NAME)); - } else { - additionalProperties.put(PROJECT_NAME, projectName); - } - sourceFolder = projectName + File.separator + sourceFolder; - - // Setup unwrapRequired option, which makes all the properties with "required" non-optional - if (additionalProperties.containsKey(UNWRAP_REQUIRED)) { - setUnwrapRequired(Boolean.parseBoolean(String.valueOf(additionalProperties.get(UNWRAP_REQUIRED)))); - } - additionalProperties.put(UNWRAP_REQUIRED, unwrapRequired); - - // Setup unwrapRequired option, which makes all the properties with "required" non-optional - if (additionalProperties.containsKey(RESPONSE_AS)) { - Object responseAsObject = additionalProperties.get(RESPONSE_AS); - if (responseAsObject instanceof String) { - setResponseAs(((String)responseAsObject).split(",")); - } else { - setResponseAs((String[]) responseAsObject); - } - } - additionalProperties.put(RESPONSE_AS, responseAs); - if (ArrayUtils.contains(responseAs, LIBRARY_PROMISE_KIT)) { - additionalProperties.put("usePromiseKit", true); + @Override + public CodegenType getTag() { + return CodegenType.CLIENT; } - // Setup swiftUseApiNamespace option, which makes all the API classes inner-class of {{projectName}}API - if (additionalProperties.containsKey(SWIFT_USE_API_NAMESPACE)) { - swiftUseApiNamespace = Boolean.parseBoolean(String.valueOf(additionalProperties.get(SWIFT_USE_API_NAMESPACE))); + @Override + public String getName() { + return "swift"; } - additionalProperties.put(SWIFT_USE_API_NAMESPACE, swiftUseApiNamespace); - supportingFiles.add(new SupportingFile("Podspec.mustache", "", projectName + ".podspec")); - supportingFiles.add(new SupportingFile("Cartfile.mustache", "", "Cartfile")); - supportingFiles.add(new SupportingFile("APIHelper.mustache", sourceFolder, "APIHelper.swift")); - supportingFiles.add(new SupportingFile("AlamofireImplementations.mustache", sourceFolder, - "AlamofireImplementations.swift")); - supportingFiles.add(new SupportingFile("Extensions.mustache", sourceFolder, "Extensions.swift")); - supportingFiles.add(new SupportingFile("Models.mustache", sourceFolder, "Models.swift")); - supportingFiles.add(new SupportingFile("APIs.mustache", sourceFolder, "APIs.swift")); - } - - @Override - public String escapeReservedWord(String name) { - return "_" + name; // add an underscore to the name - } - - @Override - public String modelFileFolder() { - return outputFolder + File.separator + sourceFolder + modelPackage().replace('.', File.separatorChar); - } - - @Override - public String apiFileFolder() { - return outputFolder + File.separator + sourceFolder + apiPackage().replace('.', File.separatorChar); - } - - @Override - public String getTypeDeclaration(Property p) { - if (p instanceof ArrayProperty) { - ArrayProperty ap = (ArrayProperty) p; - Property inner = ap.getItems(); - return "[" + getTypeDeclaration(inner) + "]"; - } else if (p instanceof MapProperty) { - MapProperty mp = (MapProperty) p; - Property inner = mp.getAdditionalProperties(); - return "[String:" + getTypeDeclaration(inner) + "]"; + @Override + public String getHelp() { + return "Generates a swift client library."; } - return super.getTypeDeclaration(p); - } - @Override - public String getSwaggerType(Property p) { - String swaggerType = super.getSwaggerType(p); - String type = null; - if (typeMapping.containsKey(swaggerType)) { - type = typeMapping.get(swaggerType); - if (languageSpecificPrimitives.contains(type)) + public SwiftCodegen() { + super(); + outputFolder = "generated-code" + File.separator + "swift"; + modelTemplateFiles.put("model.mustache", ".swift"); + apiTemplateFiles.put("api.mustache", ".swift"); + embeddedTemplateDir = templateDir = "swift"; + apiPackage = File.separator + "APIs"; + modelPackage = File.separator + "Models"; + + languageSpecificPrimitives = new HashSet( + Arrays.asList( + "Int", + "Float", + "Double", + "Bool", + "Void", + "String", + "Character", + "AnyObject") + ); + defaultIncludes = new HashSet( + Arrays.asList( + "NSDate", + "NSURL", // for file + "Array", + "Dictionary", + "Set", + "Any", + "Empty", + "AnyObject") + ); + setReservedWordsLowerCase( + Arrays.asList( + "class", "break", "as", "associativity", "deinit", "case", "dynamicType", "convenience", "enum", "continue", + "false", "dynamic", "extension", "default", "is", "didSet", "func", "do", "nil", "final", "import", "else", + "self", "get", "init", "fallthrough", "Self", "infix", "internal", "for", "super", "inout", "let", "if", + "true", "lazy", "operator", "in", "COLUMN", "left", "private", "return", "FILE", "mutating", "protocol", + "switch", "FUNCTION", "none", "public", "where", "LINE", "nonmutating", "static", "while", "optional", + "struct", "override", "subscript", "postfix", "typealias", "precedence", "var", "prefix", "Protocol", + "required", "right", "set", "Type", "unowned", "weak") + ); + + typeMapping = new HashMap(); + typeMapping.put("array", "Array"); + typeMapping.put("List", "Array"); + typeMapping.put("map", "Dictionary"); + typeMapping.put("date", "NSDate"); + typeMapping.put("Date", "NSDate"); + typeMapping.put("DateTime", "NSDate"); + typeMapping.put("boolean", "Bool"); + typeMapping.put("string", "String"); + typeMapping.put("char", "Character"); + typeMapping.put("short", "Int"); + typeMapping.put("int", "Int"); + typeMapping.put("long", "Int"); + typeMapping.put("integer", "Int"); + typeMapping.put("Integer", "Int"); + typeMapping.put("float", "Float"); + typeMapping.put("number", "Double"); + typeMapping.put("double", "Double"); + typeMapping.put("object", "AnyObject"); + typeMapping.put("file", "NSURL"); + //TODO binary should be mapped to byte array + // mapped to String as a workaround + typeMapping.put("binary", "String"); + + importMapping = new HashMap(); + + cliOptions.add(new CliOption(PROJECT_NAME, "Project name in Xcode")); + cliOptions.add(new CliOption(RESPONSE_AS, "Optionally use libraries to manage response. Currently " + + StringUtils.join(RESPONSE_LIBRARIES, ", ") + " are available.")); + cliOptions.add(new CliOption(UNWRAP_REQUIRED, "Treat 'required' properties in response as non-optional " + + "(which would crash the app if api returns null as opposed to required option specified in json schema")); + cliOptions.add(new CliOption(POD_SOURCE, "Source information used for Podspec")); + cliOptions.add(new CliOption(CodegenConstants.POD_VERSION, "Version used for Podspec")); + cliOptions.add(new CliOption(POD_AUTHORS, "Authors used for Podspec")); + cliOptions.add(new CliOption(POD_SOCIAL_MEDIA_URL, "Social Media URL used for Podspec")); + cliOptions.add(new CliOption(POD_DOCSET_URL, "Docset URL used for Podspec")); + cliOptions.add(new CliOption(POD_LICENSE, "License used for Podspec")); + cliOptions.add(new CliOption(POD_HOMEPAGE, "Homepage used for Podspec")); + cliOptions.add(new CliOption(POD_SUMMARY, "Summary used for Podspec")); + cliOptions.add(new CliOption(POD_DESCRIPTION, "Description used for Podspec")); + cliOptions.add(new CliOption(POD_SCREENSHOTS, "Screenshots used for Podspec")); + cliOptions.add(new CliOption(POD_DOCUMENTATION_URL, "Documentation URL used for Podspec")); + cliOptions.add(new CliOption(SWIFT_USE_API_NAMESPACE, "Flag to make all the API classes inner-class of {{projectName}}API")); + } + + @Override + public void processOpts() { + super.processOpts(); + + // Setup project name + if (additionalProperties.containsKey(PROJECT_NAME)) { + setProjectName((String) additionalProperties.get(PROJECT_NAME)); + } else { + additionalProperties.put(PROJECT_NAME, projectName); + } + sourceFolder = projectName + File.separator + sourceFolder; + + // Setup unwrapRequired option, which makes all the properties with "required" non-optional + if (additionalProperties.containsKey(UNWRAP_REQUIRED)) { + setUnwrapRequired(Boolean.parseBoolean(String.valueOf(additionalProperties.get(UNWRAP_REQUIRED)))); + } + additionalProperties.put(UNWRAP_REQUIRED, unwrapRequired); + + // Setup unwrapRequired option, which makes all the properties with "required" non-optional + if (additionalProperties.containsKey(RESPONSE_AS)) { + Object responseAsObject = additionalProperties.get(RESPONSE_AS); + if (responseAsObject instanceof String) { + setResponseAs(((String)responseAsObject).split(",")); + } else { + setResponseAs((String[]) responseAsObject); + } + } + additionalProperties.put(RESPONSE_AS, responseAs); + if (ArrayUtils.contains(responseAs, LIBRARY_PROMISE_KIT)) { + additionalProperties.put("usePromiseKit", true); + } + + // Setup swiftUseApiNamespace option, which makes all the API classes inner-class of {{projectName}}API + if (additionalProperties.containsKey(SWIFT_USE_API_NAMESPACE)) { + swiftUseApiNamespace = Boolean.parseBoolean(String.valueOf(additionalProperties.get(SWIFT_USE_API_NAMESPACE))); + } + additionalProperties.put(SWIFT_USE_API_NAMESPACE, swiftUseApiNamespace); + + supportingFiles.add(new SupportingFile("Podspec.mustache", "", projectName + ".podspec")); + supportingFiles.add(new SupportingFile("Cartfile.mustache", "", "Cartfile")); + supportingFiles.add(new SupportingFile("APIHelper.mustache", sourceFolder, "APIHelper.swift")); + supportingFiles.add(new SupportingFile("AlamofireImplementations.mustache", sourceFolder, + "AlamofireImplementations.swift")); + supportingFiles.add(new SupportingFile("Extensions.mustache", sourceFolder, "Extensions.swift")); + supportingFiles.add(new SupportingFile("Models.mustache", sourceFolder, "Models.swift")); + supportingFiles.add(new SupportingFile("APIs.mustache", sourceFolder, "APIs.swift")); + } + + @Override + public String escapeReservedWord(String name) { + return "_" + name; // add an underscore to the name + } + + @Override + public String modelFileFolder() { + return outputFolder + File.separator + sourceFolder + modelPackage().replace('.', File.separatorChar); + } + + @Override + public String apiFileFolder() { + return outputFolder + File.separator + sourceFolder + apiPackage().replace('.', File.separatorChar); + } + + @Override + public String getTypeDeclaration(Property p) { + if (p instanceof ArrayProperty) { + ArrayProperty ap = (ArrayProperty) p; + Property inner = ap.getItems(); + return "[" + getTypeDeclaration(inner) + "]"; + } else if (p instanceof MapProperty) { + MapProperty mp = (MapProperty) p; + Property inner = mp.getAdditionalProperties(); + return "[String:" + getTypeDeclaration(inner) + "]"; + } + return super.getTypeDeclaration(p); + } + + @Override + public String getSwaggerType(Property p) { + String swaggerType = super.getSwaggerType(p); + String type = null; + if (typeMapping.containsKey(swaggerType)) { + type = typeMapping.get(swaggerType); + if (languageSpecificPrimitives.contains(type) || defaultIncludes.contains(type)) + return type; + } else + type = swaggerType; return toModelName(type); - } else - type = swaggerType; - return toModelName(type); - } - - @Override - public String toDefaultValue(Property p) { - // nil - return null; - } - - @Override - public String toInstantiationType(Property p) { - if (p instanceof MapProperty) { - MapProperty ap = (MapProperty) p; - String inner = getSwaggerType(ap.getAdditionalProperties()); - return "[String:" + inner + "]"; - } else if (p instanceof ArrayProperty) { - ArrayProperty ap = (ArrayProperty) p; - String inner = getSwaggerType(ap.getItems()); - return "[" + inner + "]"; } - return null; - } - @Override - public CodegenProperty fromProperty(String name, Property p) { - CodegenProperty codegenProperty = super.fromProperty(name, p); - if (codegenProperty.isEnum) { - List> swiftEnums = new ArrayList>(); - List values = (List) codegenProperty.allowableValues.get("values"); - for (String value : values) { - Map map = new HashMap(); - map.put("enum", toSwiftyEnumName(value)); - map.put("raw", value); - swiftEnums.add(map); - } - codegenProperty.allowableValues.put("values", swiftEnums); - codegenProperty.datatypeWithEnum = - StringUtils.left(codegenProperty.datatypeWithEnum, codegenProperty.datatypeWithEnum.length() - "Enum".length()); - // Ensure that the enum type doesn't match a reserved word or - // the variable name doesn't match the generated enum type or the - // Swift compiler will generate an error - if (isReservedWord(codegenProperty.datatypeWithEnum) || - name.equals(codegenProperty.datatypeWithEnum)) { - codegenProperty.datatypeWithEnum = escapeReservedWord(codegenProperty.datatypeWithEnum); - } + /** + * Output the proper model name (capitalized) + * + * @param name the name of the model + * @return capitalized model name + */ + @Override + public String toModelName(String name) { + name = sanitizeName(name); // FIXME parameter should not be assigned. Also declare it as "final" + + if (!StringUtils.isEmpty(modelNameSuffix)) { // set model suffix + name = name + "_" + modelNameSuffix; + } + + if (!StringUtils.isEmpty(modelNamePrefix)) { // set model prefix + name = modelNamePrefix + "_" + name; + } + + // camelize the model name + // phone_number => PhoneNumber + name = camelize(name); + + // model name cannot use reserved keyword, e.g. return + if (isReservedWord(name)) { + String modelName = "Object" + name; + LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName); + return modelName; + } + + return name; + } + + /** + * Return the capitalized file name of the model + * + * @param name the model name + * @return the file name of the model + */ + @Override + public String toModelFilename(String name) { + // should be the same as the model name + return toModelName(name); + } + + @Override + public String toDefaultValue(Property p) { + // nil + return null; + } + + @Override + public String toInstantiationType(Property p) { + if (p instanceof MapProperty) { + MapProperty ap = (MapProperty) p; + String inner = getSwaggerType(ap.getAdditionalProperties()); + return "[String:" + inner + "]"; + } else if (p instanceof ArrayProperty) { + ArrayProperty ap = (ArrayProperty) p; + String inner = getSwaggerType(ap.getItems()); + return "[" + inner + "]"; + } + return null; + } + + @Override + public CodegenProperty fromProperty(String name, Property p) { + CodegenProperty codegenProperty = super.fromProperty(name, p); + if (codegenProperty.isEnum) { + List> swiftEnums = new ArrayList>(); + List values = (List) codegenProperty.allowableValues.get("values"); + for (String value : values) { + Map map = new HashMap(); + map.put("enum", toSwiftyEnumName(value)); + map.put("raw", value); + swiftEnums.add(map); + } + codegenProperty.allowableValues.put("values", swiftEnums); + codegenProperty.datatypeWithEnum = + StringUtils.left(codegenProperty.datatypeWithEnum, codegenProperty.datatypeWithEnum.length() - "Enum".length()); + // Ensure that the enum type doesn't match a reserved word or + // the variable name doesn't match the generated enum type or the + // Swift compiler will generate an error + if (isReservedWord(codegenProperty.datatypeWithEnum) || + name.equals(codegenProperty.datatypeWithEnum)) { + codegenProperty.datatypeWithEnum = escapeReservedWord(codegenProperty.datatypeWithEnum); + } + } + return codegenProperty; } - return codegenProperty; - } @SuppressWarnings("static-method") public String toSwiftyEnumName(String value) { @@ -295,125 +340,129 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig { } - @Override - public String toApiName(String name) { - if(name.length() == 0) - return "DefaultAPI"; - return initialCaps(name) + "API"; - } - - @Override - public String toOperationId(String operationId) { - // throw exception if method name is empty - if (StringUtils.isEmpty(operationId)) { - throw new RuntimeException("Empty method name (operationId) not allowed"); + @Override + public String toApiName(String name) { + if(name.length() == 0) + return "DefaultAPI"; + return initialCaps(name) + "API"; } - // method name cannot use reserved keyword, e.g. return - if (isReservedWord(operationId)) { - throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); + @Override + public String toOperationId(String operationId) { + operationId = camelize(sanitizeName(operationId), true); + + // throw exception if method name is empty. This should not happen but keep the check just in case + if (StringUtils.isEmpty(operationId)) { + throw new RuntimeException("Empty method name (operationId) not allowed"); + } + + // method name cannot use reserved keyword, e.g. return + if (isReservedWord(operationId)) { + String newOperationId = camelize(("call_" + operationId), true); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId); + return newOperationId; + } + + return operationId; } - return camelize(sanitizeName(operationId), true); - } + @Override + public String toVarName(String name) { + // sanitize name + name = sanitizeName(name); - @Override - public String toVarName(String name) { - // sanitize name - name = sanitizeName(name); + // if it's all uppper case, do nothing + if (name.matches("^[A-Z_]*$")) { + return name; + } + + // camelize the variable name + // pet_id => petId + name = camelize(name, true); + + // for reserved word or word starting with number, append _ + if (isReservedWord(name) || name.matches("^\\d.*")) { + name = escapeReservedWord(name); + } - // if it's all uppper case, do nothing - if (name.matches("^[A-Z_]*$")) { return name; } - // camelize the variable name - // pet_id => petId - name = camelize(name, true); + @Override + public String toParamName(String name) { + // sanitize name + name = sanitizeName(name); - // for reserved word or word starting with number, append _ - if (isReservedWord(name) || name.matches("^\\d.*")) { - name = escapeReservedWord(name); - } + // replace - with _ e.g. created-at => created_at + name = name.replaceAll("-", "_"); - return name; - } + // if it's all uppper case, do nothing + if (name.matches("^[A-Z_]*$")) { + return name; + } - @Override - public String toParamName(String name) { - // sanitize name - name = sanitizeName(name); + // camelize(lower) the variable name + // pet_id => petId + name = camelize(name, true); - // replace - with _ e.g. created-at => created_at - name = name.replaceAll("-", "_"); + // for reserved word or word starting with number, append _ + if (isReservedWord(name) || name.matches("^\\d.*")) { + name = escapeReservedWord(name); + } - // if it's all uppper case, do nothing - if (name.matches("^[A-Z_]*$")) { return name; } - // camelize(lower) the variable name - // pet_id => petId - name = camelize(name, true); - - // for reserved word or word starting with number, append _ - if (isReservedWord(name) || name.matches("^\\d.*")) { - name = escapeReservedWord(name); + @Override + public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map definitions, Swagger swagger) { + path = normalizePath(path); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. + List parameters = operation.getParameters(); + parameters = Lists.newArrayList(Iterators.filter(parameters.iterator(), new Predicate() { + @Override + public boolean apply(@Nullable Parameter parameter) { + return !(parameter instanceof HeaderParameter); + } + })); + operation.setParameters(parameters); + return super.fromOperation(path, httpMethod, operation, definitions, swagger); } - return name; - } + private static String normalizePath(String path) { + StringBuilder builder = new StringBuilder(); - @Override - public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map definitions, Swagger swagger) { - path = normalizePath(path); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. - List parameters = operation.getParameters(); - parameters = Lists.newArrayList(Iterators.filter(parameters.iterator(), new Predicate() { - @Override - public boolean apply(@Nullable Parameter parameter) { - return !(parameter instanceof HeaderParameter); - } - })); - operation.setParameters(parameters); - return super.fromOperation(path, httpMethod, operation, definitions, swagger); - } + int cursor = 0; + Matcher matcher = PATH_PARAM_PATTERN.matcher(path); + boolean found = matcher.find(); + while (found) { + String stringBeforeMatch = path.substring(cursor, matcher.start()); + builder.append(stringBeforeMatch); - private static String normalizePath(String path) { - StringBuilder builder = new StringBuilder(); + String group = matcher.group().substring(1, matcher.group().length() - 1); + group = camelize(group, true); + builder + .append("{") + .append(group) + .append("}"); - int cursor = 0; - Matcher matcher = PATH_PARAM_PATTERN.matcher(path); - boolean found = matcher.find(); - while (found) { - String stringBeforeMatch = path.substring(cursor, matcher.start()); - builder.append(stringBeforeMatch); + cursor = matcher.end(); + found = matcher.find(); + } - String group = matcher.group().substring(1, matcher.group().length() - 1); - group = camelize(group, true); - builder - .append("{") - .append(group) - .append("}"); + String stringAfterMatch = path.substring(cursor); + builder.append(stringAfterMatch); - cursor = matcher.end(); - found = matcher.find(); + return builder.toString(); } - String stringAfterMatch = path.substring(cursor); - builder.append(stringAfterMatch); + public void setProjectName(String projectName) { + this.projectName = projectName; + } - return builder.toString(); - } + public void setUnwrapRequired(boolean unwrapRequired) { + this.unwrapRequired = unwrapRequired; + } - public void setProjectName(String projectName) { - this.projectName = projectName; - } - - public void setUnwrapRequired(boolean unwrapRequired) { - this.unwrapRequired = unwrapRequired; - } - - public void setResponseAs(String[] responseAs) { - this.responseAs = responseAs; - } + public void setResponseAs(String[] responseAs) { + this.responseAs = responseAs; + } } diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/CXF2InterfaceComparator.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/CXF2InterfaceComparator.mustache new file mode 100644 index 00000000000..d1fd0bf82c8 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/CXF2InterfaceComparator.mustache @@ -0,0 +1,120 @@ +package {{package}}; + + +import java.lang.reflect.Method; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.Path; + +import org.apache.cxf.jaxrs.ext.ResourceComparator; +import org.apache.cxf.jaxrs.model.ClassResourceInfo; +import org.apache.cxf.jaxrs.model.OperationResourceInfo; +import org.apache.cxf.message.Message; + +/** + * This class only help CXF to decide which resource interface is more suitable. It used Java reflexion to iterate over Java methods but it *DO NOT* select the target method. + */ +public class CXFInterfaceComparator implements ResourceComparator { + + private static final Logger LOGGER = LoggerFactory.getLogger(CXFInterfaceComparator.class); + + @Override + public int compare(ClassResourceInfo cri1, ClassResourceInfo cri2, Message message) { + String requestVerb = (String) message.get(Message.HTTP_REQUEST_METHOD); + String requestURI = (String) message.get(Message.REQUEST_URI); + String requestPath = requestURI.replace((String) message.get(Message.BASE_PATH), ""); + + // remove "/"at the end of requestPath if present + if (requestPath.endsWith("/")){ + requestPath = requestPath.substring(0, requestPath.length()-1); + } + + if (analyseInterface(cri1, requestPath, requestVerb)) { + return -1; // Indicate that 'cri1' interface should be preferred + } else if (analyseInterface(cri2, requestPath, requestVerb)) { + return 1; // Indicate that 'cri2' interface should be preferred + } else { + return 0; // Nothing match, leave CXF decision + } + } + + /** + * Analyse each methods provided to check if there is a match with the + * message request path and request HTTP verb. + * + * @param cri + * the interface to be analysed + * @param requestPath + * the path of the request. Do not contains the host and base + * path + * @return true if a method match the request, false otherwise + */ + private static boolean analyseInterface(ClassResourceInfo cri, String requestPath, String requestVerb) { + assert cri.getServiceClass() != null; + assert cri.getServiceClass().getInterfaces() != null; + assert cri.getServiceClass().getInterfaces()[0] != null; + assert cri.getServiceClass().getInterfaces()[0].getMethods().length > 0; + + Method[] methods = cri.getServiceClass().getInterfaces()[0].getMethods(); + // Java reflexion. Check all the methods of an interface. + for (Method method : methods) { + Path pathAnnotation = method.getAnnotation(javax.ws.rs.Path.class); + if (pathAnnotation != null && pathAnnotation.value() != null) { + String pathValue = pathAnnotation.value(); + String methodHttpVerb = getMethodHttpVerb(method); + + // Always authorize OPTIONS request if the path is matching a method declaration + if (requestVerb.equals(HttpMethod.OPTIONS) && match(pathValue,requestPath)) { + return true; + } + // Also check the HTTP verb since a single path can be match do multiple request, depending of the HTTP request verb. + if (requestVerb.equals(methodHttpVerb) && match(pathValue, requestPath)) { + return true; + } + } + } + return false; + } + + private static String getMethodHttpVerb(Method method) { + if (method.getAnnotation(javax.ws.rs.POST.class) != null) { + return HttpMethod.POST; + } else if (method.getAnnotation(javax.ws.rs.GET.class) != null) { + return HttpMethod.GET; + } else if (method.getAnnotation(javax.ws.rs.PUT.class) != null) { + return HttpMethod.PUT; + } else if (method.getAnnotation(javax.ws.rs.OPTIONS.class) != null) { + return HttpMethod.OPTIONS; + } else if (method.getAnnotation(javax.ws.rs.DELETE.class) != null) { + return HttpMethod.DELETE; + } else if (method.getAnnotation(javax.ws.rs.HEAD.class) != null) { + return HttpMethod.HEAD; + } + assert false; + return null; + } + + /** + * Check whether if the pathValue match with the requestPath parameter. + * Every path params are considered to be declared as '{param}'. The tokens to start and close path params declaration are '{' and '}'. + * + * @param valueFromAnnotation + * @param valueFromRequest + * @return true if there is a match, false otherwise + */ + private static boolean match(String valueFromAnnotation, String valueFromRequest) { + String patternFinal = valueFromAnnotation.replaceAll("\\{(.*?)\\}", "([^/]*)").replace("/", "\\/"); + Matcher matcher = Pattern.compile(patternFinal).matcher(valueFromRequest); + if (matcher.matches()) { + return true; + } + return false; + } + + @Override + public int compare(OperationResourceInfo ori1, OperationResourceInfo ori2, Message message) { + return 0; // Leave CXF decision + } +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api.mustache index 869d1aa63de..57df497e533 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api.mustache @@ -6,7 +6,7 @@ package {{package}}; import javax.ws.rs.*; import javax.ws.rs.core.Response; -@Path("{{contextPath}}") +@Path("/") public interface {{classname}} { {{#operations}} {{#operation}} @@ -14,8 +14,7 @@ public interface {{classname}} { {{#subresourceOperation}}@Path("{{path}}"){{/subresourceOperation}} {{#hasConsumes}}@Consumes({ {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}} {{#hasProduces}}@Produces({ {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} - public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, - {{/hasMore}}{{/allParams}}); + public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}); {{/operation}} } {{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/entityModel.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/entityModel.mustache deleted file mode 100644 index 9aea77c5bf7..00000000000 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/entityModel.mustache +++ /dev/null @@ -1,51 +0,0 @@ -package {{package}}; - -{{#imports}}import {{import}}; -{{/imports}} - -import javax.xml.bind.annotation.XmlRootElement; - -{{#models}} - -{{#model}}{{#description}} -/** - * {{description}} - **/{{/description}} -@XmlRootElement(name="{{classname}}") -public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { - {{#vars}} - {{#isEnum}} - public enum {{datatypeWithEnum}} { - {{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}} - }; - private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}} - private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}} - - {{#vars}} - /**{{#description}} - * {{{description}}}{{/description}}{{#minimum}} - * minimum: {{minimum}}{{/minimum}}{{#maximum}} - * maximum: {{maximum}}{{/maximum}} - **/ - @JsonProperty("{{name}}") - public {{{datatypeWithEnum}}} {{getter}}() { - return {{name}}; - } - public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { - this.{{name}} = {{name}}; - } - - {{/vars}} - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class {{classname}} {\n"); - {{#parent}}sb.append(" " + super.toString()).append("\n");{{/parent}} - {{#vars}}sb.append(" {{name}}: ").append({{name}}).append("\n"); - {{/vars}}sb.append("}\n"); - return sb.toString(); - } -} -{{/model}} -{{/models}} diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/enumClass.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/enumClass.mustache new file mode 100644 index 00000000000..1ef4a61efbe --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/enumClass.mustache @@ -0,0 +1,16 @@ +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlType; + +@XmlType(name="{{classname}}") +@XmlEnum +public enum {{classname}} { + {{#allowableValues}}{{.}}{{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/allowableValues}} + + public String value() { + return name(); + } + + public static {{classname}} fromValue(String v) { + return valueOf(v); + } +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/enumOuterClass.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/enumOuterClass.mustache deleted file mode 100644 index 7aea7b92f22..00000000000 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/enumOuterClass.mustache +++ /dev/null @@ -1,3 +0,0 @@ -public enum {{classname}} { - {{#allowableValues}}{{.}}{{^-last}}, {{/-last}}{{/allowableValues}} -} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/model.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/model.mustache index 578cd064df7..2c383a41a28 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/model.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/model.mustache @@ -1,15 +1,14 @@ package {{package}}; -{{#imports}}import{{import}}; +{{#imports}}import {{import}}; {{/imports}} -{{#serializableModel}}import java.io.Serializable;{{/serializableModel}} {{#models}} {{#model}}{{#description}} /** * {{description}} **/{{/description}} -{{#isEnum}}{{>enumOuterClass}}{{/isEnum}} +{{#isEnum}}{{>enumClass}}{{/isEnum}} {{^isEnum}}{{>pojo}}{{/isEnum}} {{/model}} {{/models}} diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache new file mode 100644 index 00000000000..b42a6d3b3eb --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache @@ -0,0 +1,57 @@ +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +{{#hasVars}} @XmlType(name = "{{classn,ame}}", propOrder = + { {{#vars}}"{{name}}"{{^-last}}, {{/-last}}{{/vars}} +}){{/hasVars}} +{{^hasVars}}@XmlType(name = "{{classname}}"){{/hasVars}} +{{^parent}}@XmlRootElement(name="{{classname}}"){{/parent}} +public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { + {{#vars}}{{#isEnum}} + +{{>enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}} + +{{>enumClass}}{{/items}}{{/items.isEnum}} + + private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}} + + {{#vars}} + /**{{#description}} + * {{{description}}}{{/description}}{{#minimum}} + * minimum: {{minimum}}{{/minimum}}{{#maximum}} + * maximum: {{maximum}}{{/maximum}} + **/ + {{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}} + public {{{datatypeWithEnum}}} {{getter}}() { + return {{name}}; + } + public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { + this.{{name}} = {{name}}; + } + {{/vars}} + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class {{classname}} {\n"); + {{#parent}}sb.append(" ").append(toIndentedString(super.toString())).append("\n");{{/parent}} + {{#vars}}sb.append(" {{name}}: ").append(toIndentedString({{name}})).append("\n"); + {{/vars}}sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private static String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/project/build.properties b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/project/build.properties deleted file mode 100644 index a8c2f849be3..00000000000 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=0.12.0 diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index ae7fb8412b0..49b7f92693e 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -4,6 +4,8 @@ package {{packageName}} import ( "strings" "fmt" + "encoding/json" + "errors" "github.com/dghubble/sling" {{#imports}} "{{import}}" {{/imports}} @@ -68,16 +70,39 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{#hasBodyParam}}{{#bodyParams}}// body params _sling = _sling.BodyJSON({{paramName}}) {{/bodyParams}}{{/hasBodyParam}} +{{#returnType}} var successPayload = new({{returnType}}){{/returnType}} -{{#returnType}} response := new({{returnType}}) - _, err := _sling.ReceiveSuccess(response) - //fmt.Println("{{operationId}} response: ", response, resp, err) - return *response, err -{{/returnType}}{{^returnType}} - _, err := _sling.ReceiveSuccess(nil) - //fmt.Println("{{operationId}} response: void, ", resp, err) - return err -{{/returnType}} + // We use this map (below) so that any arbitrary error JSON can be handled. + // FIXME: This is in the absence of this Go generator honoring the non-2xx + // response (error) models, which needs to be implemented at some point. + var failurePayload map[string]interface{} + + httpResponse, err := _sling.Receive({{#returnType}}successPayload{{/returnType}}{{^returnType}}nil{{/returnType}}, &failurePayload) + + if err == nil { + // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) + if failurePayload != nil { + // If the failurePayload is present, there likely was some kind of non-2xx status + // returned (and a JSON payload error present) + var str []byte + str, err = json.Marshal(failurePayload) + if err == nil { // For safety, check for an error marshalling... probably superfluous + // This will return the JSON error body as a string + err = errors.New(string(str)) + } + } else { + // So, there was no network-type error, and nothing in the failure payload, + // but we should still check the status code + if httpResponse == nil { + // This should never happen... + err = errors.New("No HTTP Response received.") + } else if code := httpResponse.StatusCode; 200 > code || code > 299 { + err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) + } + } + } + + return {{#returnType}}*successPayload, {{/returnType}}err } {{/operation}} {{/operations}} diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/CategoryTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/CategoryTests.cs index 6384ee4179b..41efd2c08df 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/CategoryTests.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/CategoryTests.cs @@ -9,6 +9,8 @@ using IO.Swagger.Model; using IO.Swagger.Client; using System.Reflection; + + namespace IO.Swagger.Test { [TestFixture] @@ -66,3 +68,5 @@ namespace IO.Swagger.Test } } + + diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/OrderTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/OrderTests.cs index 7d0bc854cef..be753c8dabc 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/OrderTests.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/OrderTests.cs @@ -9,6 +9,8 @@ using IO.Swagger.Model; using IO.Swagger.Client; using System.Reflection; + + namespace IO.Swagger.Test { [TestFixture] @@ -102,3 +104,5 @@ namespace IO.Swagger.Test } } + + diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetApiTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetApiTests.cs index 7e3566eb04b..b5ce94521ac 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetApiTests.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetApiTests.cs @@ -11,6 +11,7 @@ using IO.Swagger.Client; using IO.Swagger.Api; using IO.Swagger.Model; + namespace IO.Swagger.Test { [TestFixture] diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetTests.cs index 6b203dbd125..ea618777058 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetTests.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetTests.cs @@ -9,6 +9,8 @@ using IO.Swagger.Model; using IO.Swagger.Client; using System.Reflection; + + namespace IO.Swagger.Test { [TestFixture] @@ -102,3 +104,5 @@ namespace IO.Swagger.Test } } + + diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/StoreApiTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/StoreApiTests.cs index b0eb6293380..6b35eb1a6b3 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/StoreApiTests.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/StoreApiTests.cs @@ -11,6 +11,7 @@ using IO.Swagger.Client; using IO.Swagger.Api; using IO.Swagger.Model; + namespace IO.Swagger.Test { [TestFixture] diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/TagTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/TagTests.cs index ad772584cc5..2348c02e789 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/TagTests.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/TagTests.cs @@ -9,6 +9,8 @@ using IO.Swagger.Model; using IO.Swagger.Client; using System.Reflection; + + namespace IO.Swagger.Test { [TestFixture] @@ -66,3 +68,5 @@ namespace IO.Swagger.Test } } + + diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserApiTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserApiTests.cs index 0d543c384aa..e1467147e71 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserApiTests.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserApiTests.cs @@ -11,6 +11,7 @@ using IO.Swagger.Client; using IO.Swagger.Api; using IO.Swagger.Model; + namespace IO.Swagger.Test { [TestFixture] diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserTests.cs index 4610313b734..473f74cb095 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserTests.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserTests.cs @@ -9,6 +9,8 @@ using IO.Swagger.Model; using IO.Swagger.Client; using System.Reflection; + + namespace IO.Swagger.Test { [TestFixture] @@ -120,3 +122,5 @@ namespace IO.Swagger.Test } } + + diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs index a141c57f79f..4d56e4c1948 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs @@ -7,6 +7,7 @@ using RestSharp; using IO.Swagger.Client; using IO.Swagger.Model; + namespace IO.Swagger.Api { @@ -1308,12 +1309,6 @@ namespace IO.Swagger.Api - // authentication (api_key) required - - if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key"))) - { - localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key"); - } // authentication (petstore_auth) required // oauth required @@ -1321,6 +1316,12 @@ namespace IO.Swagger.Api { localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken; } + // authentication (api_key) required + + if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key"))) + { + localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key"); + } // make the HTTP request @@ -1401,13 +1402,6 @@ namespace IO.Swagger.Api - // authentication (api_key) required - - if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key"))) - { - localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key"); - } - // authentication (petstore_auth) required // oauth required @@ -1416,6 +1410,13 @@ namespace IO.Swagger.Api localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken; } + // authentication (api_key) required + + if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key"))) + { + localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key"); + } + // make the HTTP request IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath, @@ -2037,12 +2038,6 @@ namespace IO.Swagger.Api - // authentication (api_key) required - - if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key"))) - { - localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key"); - } // authentication (petstore_auth) required // oauth required @@ -2050,6 +2045,12 @@ namespace IO.Swagger.Api { localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken; } + // authentication (api_key) required + + if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key"))) + { + localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key"); + } // make the HTTP request @@ -2130,13 +2131,6 @@ namespace IO.Swagger.Api - // authentication (api_key) required - - if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key"))) - { - localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key"); - } - // authentication (petstore_auth) required // oauth required @@ -2145,6 +2139,13 @@ namespace IO.Swagger.Api localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken; } + // authentication (api_key) required + + if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key"))) + { + localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key"); + } + // make the HTTP request IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath, diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/StoreApi.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/StoreApi.cs index e7da7994614..6c0134af16c 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/StoreApi.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/StoreApi.cs @@ -7,6 +7,7 @@ using RestSharp; using IO.Swagger.Client; using IO.Swagger.Model; + namespace IO.Swagger.Api { @@ -903,18 +904,18 @@ namespace IO.Swagger.Api - // authentication (test_api_key_header) required - - if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_header"))) - { - localVarHeaderParams["test_api_key_header"] = Configuration.GetApiKeyWithPrefix("test_api_key_header"); - } // authentication (test_api_key_query) required if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_query"))) { localVarQueryParams["test_api_key_query"] = Configuration.GetApiKeyWithPrefix("test_api_key_query"); } + // authentication (test_api_key_header) required + + if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_header"))) + { + localVarHeaderParams["test_api_key_header"] = Configuration.GetApiKeyWithPrefix("test_api_key_header"); + } // make the HTTP request @@ -995,13 +996,6 @@ namespace IO.Swagger.Api - // authentication (test_api_key_header) required - - if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_header"))) - { - localVarHeaderParams["test_api_key_header"] = Configuration.GetApiKeyWithPrefix("test_api_key_header"); - } - // authentication (test_api_key_query) required if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_query"))) @@ -1009,6 +1003,13 @@ namespace IO.Swagger.Api localVarQueryParams["test_api_key_query"] = Configuration.GetApiKeyWithPrefix("test_api_key_query"); } + // authentication (test_api_key_header) required + + if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_header"))) + { + localVarHeaderParams["test_api_key_header"] = Configuration.GetApiKeyWithPrefix("test_api_key_header"); + } + // make the HTTP request IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath, diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/UserApi.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/UserApi.cs index 193cc501a85..ee8c375dc1f 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/UserApi.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/UserApi.cs @@ -7,6 +7,7 @@ using RestSharp; using IO.Swagger.Client; using IO.Swagger.Model; + namespace IO.Swagger.Api { diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs index c0016a95bdd..5af4256119e 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs @@ -9,6 +9,8 @@ using System.Runtime.Serialization; using Newtonsoft.Json; using Newtonsoft.Json.Converters; + + namespace IO.Swagger.Model { /// @@ -19,6 +21,7 @@ namespace IO.Swagger.Model { /// + /// Initializes a new instance of the class. /// Initializes a new instance of the class. /// /// Id. @@ -126,4 +129,6 @@ namespace IO.Swagger.Model } } + + } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs index 7a063c25865..a22e5e51dcd 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs @@ -9,6 +9,8 @@ using System.Runtime.Serialization; using Newtonsoft.Json; using Newtonsoft.Json.Converters; + + namespace IO.Swagger.Model { /// @@ -36,10 +38,11 @@ namespace IO.Swagger.Model /// /// Order Status [DataMember(Name="status", EmitDefaultValue=true)] - public StatusEnum Status { get; set; } + public StatusEnum? Status { get; set; } /// /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// PetId. /// Quantity. @@ -47,7 +50,7 @@ namespace IO.Swagger.Model /// Order Status. /// Complete. - public Order(long? PetId = null, int? Quantity = null, DateTime? ShipDate = null, string Status = null, bool? Complete = null) + public Order(long? PetId = null, int? Quantity = null, DateTime? ShipDate = null, StatusEnum? Status = null, bool? Complete = null) { this.PetId = PetId; this.Quantity = Quantity; @@ -206,4 +209,6 @@ namespace IO.Swagger.Model } } + + } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs index c9561daabeb..bf38e422f4e 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs @@ -9,6 +9,8 @@ using System.Runtime.Serialization; using Newtonsoft.Json; using Newtonsoft.Json.Converters; + + namespace IO.Swagger.Model { /// @@ -36,10 +38,11 @@ namespace IO.Swagger.Model /// /// pet status in the store [DataMember(Name="status", EmitDefaultValue=true)] - public StatusEnum Status { get; set; } + public StatusEnum? Status { get; set; } /// /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Id. /// Category. @@ -48,7 +51,7 @@ namespace IO.Swagger.Model /// Tags. /// pet status in the store. - public Pet(long? Id = null, Category Category = null, string Name = null, List PhotoUrls = null, List Tags = null, string Status = null) + public Pet(long? Id = null, Category Category = null, string Name = null, List PhotoUrls = null, List Tags = null, StatusEnum? Status = null) { // to ensure "Name" is required (not null) if (Name == null) @@ -224,4 +227,6 @@ namespace IO.Swagger.Model } } + + } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs index e2a748438c8..d756b9c3f13 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs @@ -9,6 +9,8 @@ using System.Runtime.Serialization; using Newtonsoft.Json; using Newtonsoft.Json.Converters; + + namespace IO.Swagger.Model { /// @@ -19,6 +21,7 @@ namespace IO.Swagger.Model { /// + /// Initializes a new instance of the class. /// Initializes a new instance of the class. /// /// Id. @@ -126,4 +129,6 @@ namespace IO.Swagger.Model } } + + } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs index 1da35d8a188..6fdccef9a3e 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs @@ -9,6 +9,8 @@ using System.Runtime.Serialization; using Newtonsoft.Json; using Newtonsoft.Json.Converters; + + namespace IO.Swagger.Model { /// @@ -19,6 +21,7 @@ namespace IO.Swagger.Model { /// + /// Initializes a new instance of the class. /// Initializes a new instance of the class. /// /// Id. @@ -229,4 +232,6 @@ namespace IO.Swagger.Model } } + + } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/TestOrder.cs b/samples/client/petstore/csharp/SwaggerClientTest/TestOrder.cs index 278cc964b18..3fde9520e07 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/TestOrder.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/TestOrder.cs @@ -49,7 +49,7 @@ namespace SwaggerClientTest.TestORder Assert.AreEqual (1982, o.Id); Assert.AreEqual (1020, o.PetId); Assert.AreEqual (1, o.Quantity); - Assert.AreEqual ("placed", o.Status); + Assert.AreEqual (Order.StatusEnum.Placed, o.Status); Assert.AreEqual (true, o.Complete); } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs b/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs index 56b0910140e..1a8f953755d 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs @@ -24,7 +24,7 @@ namespace SwaggerClientTest.TestPet Pet p = new Pet(Name: "Csharp test", PhotoUrls: new List { "http://petstore.com/csharp_test" }); p.Id = petId; //p.Name = "Csharp test"; - p.Status = "available"; + p.Status = Pet.StatusEnum.Available; // create Category object Category category = new Category(); category.Id = 56; @@ -82,7 +82,7 @@ namespace SwaggerClientTest.TestPet Assert.IsInstanceOf (response, "Response is a Pet"); Assert.AreEqual ("Csharp test", response.Name); - Assert.AreEqual ("available", response.Status); + Assert.AreEqual (Pet.StatusEnum.Available, response.Status); Assert.IsInstanceOf> (response.Tags, "Response.Tags is a Array"); Assert.AreEqual (petId, response.Tags [0].Id); @@ -114,7 +114,7 @@ namespace SwaggerClientTest.TestPet Assert.IsInstanceOf (response, "Response is a Pet"); Assert.AreEqual ("Csharp test", response.Name); - Assert.AreEqual ("available", response.Status); + Assert.AreEqual (Pet.StatusEnum.Available, response.Status); Assert.IsInstanceOf> (response.Tags, "Response.Tags is a Array"); Assert.AreEqual (petId, response.Tags [0].Id); @@ -143,7 +143,7 @@ namespace SwaggerClientTest.TestPet Assert.IsInstanceOf (response, "Response is a Pet"); Assert.AreEqual ("Csharp test", response.Name); - Assert.AreEqual ("available", response.Status); + Assert.AreEqual (Pet.StatusEnum.Available, response.Status); Assert.IsInstanceOf> (response.Tags, "Response.Tags is a Array"); Assert.AreEqual (petId, response.Tags [0].Id); @@ -202,7 +202,7 @@ namespace SwaggerClientTest.TestPet Assert.IsInstanceOf> (response.Tags, "Response.Tags is a Array"); Assert.AreEqual ("new form name", response.Name); - Assert.AreEqual ("pending", response.Status); + Assert.AreEqual (Pet.StatusEnum.Pending, response.Status); Assert.AreEqual (petId, response.Tags [0].Id); Assert.AreEqual (56, response.Category.Id); @@ -259,7 +259,7 @@ namespace SwaggerClientTest.TestPet Pet p1 = new Pet(Name: "Csharp test", PhotoUrls: new List { "http://petstore.com/csharp_test"} ); p1.Id = petId; //p1.Name = "Csharp test"; - p1.Status = "available"; + p1.Status = Pet.StatusEnum.Available; // create Category object Category category1 = new Category(); category1.Id = 56; @@ -278,7 +278,7 @@ namespace SwaggerClientTest.TestPet Pet p2 = new Pet(Name: "Csharp test", PhotoUrls: new List { "http://petstore.com/csharp_test"} ); p2.Id = petId; p2.Name = "Csharp test"; - p2.Status = "available"; + p2.Status = Pet.StatusEnum.Available; // create Category object Category category2 = new Category(); category2.Id = 56; diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift index ca260a2b92a..595907df1be 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift @@ -166,20 +166,20 @@ public class PetAPI: APIBase { - OAuth: - type: oauth2 - name: petstore_auth - - examples: [{contentType=application/json, example=[ { - "photoUrls" : [ "aeiou" ], - "name" : "doggie", + - examples: [{example=[ { + "tags" : [ { + "id" : 123456789, + "name" : "aeiou" + } ], "id" : 123456789, "category" : { - "name" : "aeiou", - "id" : 123456789 + "id" : 123456789, + "name" : "aeiou" }, - "tags" : [ { - "name" : "aeiou", - "id" : 123456789 - } ], - "status" : "aeiou" -} ]}, {contentType=application/xml, example= + "status" : "aeiou", + "name" : "doggie", + "photoUrls" : [ "aeiou" ] +} ], contentType=application/json}, {example= 123456 doggie @@ -188,21 +188,21 @@ public class PetAPI: APIBase { string -}] - - examples: [{contentType=application/json, example=[ { - "photoUrls" : [ "aeiou" ], - "name" : "doggie", +, contentType=application/xml}] + - examples: [{example=[ { + "tags" : [ { + "id" : 123456789, + "name" : "aeiou" + } ], "id" : 123456789, "category" : { - "name" : "aeiou", - "id" : 123456789 + "id" : 123456789, + "name" : "aeiou" }, - "tags" : [ { - "name" : "aeiou", - "id" : 123456789 - } ], - "status" : "aeiou" -} ]}, {contentType=application/xml, example= + "status" : "aeiou", + "name" : "doggie", + "photoUrls" : [ "aeiou" ] +} ], contentType=application/json}, {example= 123456 doggie @@ -211,7 +211,7 @@ public class PetAPI: APIBase { string -}] +, contentType=application/xml}] - parameter status: (query) Status values that need to be considered for query @@ -272,20 +272,20 @@ public class PetAPI: APIBase { - OAuth: - type: oauth2 - name: petstore_auth - - examples: [{contentType=application/json, example=[ { - "photoUrls" : [ "aeiou" ], - "name" : "doggie", + - examples: [{example=[ { + "tags" : [ { + "id" : 123456789, + "name" : "aeiou" + } ], "id" : 123456789, "category" : { - "name" : "aeiou", - "id" : 123456789 + "id" : 123456789, + "name" : "aeiou" }, - "tags" : [ { - "name" : "aeiou", - "id" : 123456789 - } ], - "status" : "aeiou" -} ]}, {contentType=application/xml, example= + "status" : "aeiou", + "name" : "doggie", + "photoUrls" : [ "aeiou" ] +} ], contentType=application/json}, {example= 123456 doggie @@ -294,21 +294,21 @@ public class PetAPI: APIBase { string -}] - - examples: [{contentType=application/json, example=[ { - "photoUrls" : [ "aeiou" ], - "name" : "doggie", +, contentType=application/xml}] + - examples: [{example=[ { + "tags" : [ { + "id" : 123456789, + "name" : "aeiou" + } ], "id" : 123456789, "category" : { - "name" : "aeiou", - "id" : 123456789 + "id" : 123456789, + "name" : "aeiou" }, - "tags" : [ { - "name" : "aeiou", - "id" : 123456789 - } ], - "status" : "aeiou" -} ]}, {contentType=application/xml, example= + "status" : "aeiou", + "name" : "doggie", + "photoUrls" : [ "aeiou" ] +} ], contentType=application/json}, {example= 123456 doggie @@ -317,7 +317,7 @@ public class PetAPI: APIBase { string -}] +, contentType=application/xml}] - parameter tags: (query) Tags to filter by @@ -375,26 +375,26 @@ public class PetAPI: APIBase { - GET /pet/{petId} - Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions - - OAuth: - - type: oauth2 - - name: petstore_auth - API Key: - type: apiKey api_key - name: api_key - - examples: [{contentType=application/json, example={ - "photoUrls" : [ "aeiou" ], - "name" : "doggie", + - OAuth: + - type: oauth2 + - name: petstore_auth + - examples: [{example={ + "tags" : [ { + "id" : 123456789, + "name" : "aeiou" + } ], "id" : 123456789, "category" : { - "name" : "aeiou", - "id" : 123456789 + "id" : 123456789, + "name" : "aeiou" }, - "tags" : [ { - "name" : "aeiou", - "id" : 123456789 - } ], - "status" : "aeiou" -}}, {contentType=application/xml, example= + "status" : "aeiou", + "name" : "doggie", + "photoUrls" : [ "aeiou" ] +}, contentType=application/json}, {example= 123456 doggie @@ -403,21 +403,21 @@ public class PetAPI: APIBase { string -}] - - examples: [{contentType=application/json, example={ - "photoUrls" : [ "aeiou" ], - "name" : "doggie", +, contentType=application/xml}] + - examples: [{example={ + "tags" : [ { + "id" : 123456789, + "name" : "aeiou" + } ], "id" : 123456789, "category" : { - "name" : "aeiou", - "id" : 123456789 + "id" : 123456789, + "name" : "aeiou" }, - "tags" : [ { - "name" : "aeiou", - "id" : 123456789 - } ], - "status" : "aeiou" -}}, {contentType=application/xml, example= + "status" : "aeiou", + "name" : "doggie", + "photoUrls" : [ "aeiou" ] +}, contentType=application/json}, {example= 123456 doggie @@ -426,7 +426,7 @@ public class PetAPI: APIBase { string -}] +, contentType=application/xml}] - parameter petId: (path) ID of pet that needs to be fetched @@ -678,14 +678,14 @@ public class PetAPI: APIBase { - GET /pet/{petId}?testing_byte_array=true - Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions - - OAuth: - - type: oauth2 - - name: petstore_auth - API Key: - type: apiKey api_key - name: api_key - - examples: [{contentType=application/json, example=""}, {contentType=application/xml, example=not implemented io.swagger.models.properties.BinaryProperty@55e6ae9e}] - - examples: [{contentType=application/json, example=""}, {contentType=application/xml, example=not implemented io.swagger.models.properties.BinaryProperty@55e6ae9e}] + - OAuth: + - type: oauth2 + - name: petstore_auth + - examples: [{example="", contentType=application/json}, {example=not implemented io.swagger.models.properties.BinaryProperty@55e6ae9e, contentType=application/xml}] + - examples: [{example="", contentType=application/json}, {example=not implemented io.swagger.models.properties.BinaryProperty@55e6ae9e, contentType=application/xml}] - parameter petId: (path) ID of pet that needs to be fetched diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift index e8511765a97..f53163915ef 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift @@ -55,36 +55,36 @@ public class StoreAPI: APIBase { - API Key: - type: apiKey x-test_api_client_secret - name: test_api_client_secret - - examples: [{contentType=application/json, example=[ { - "petId" : 123456789, - "quantity" : 123, + - examples: [{example=[ { "id" : 123456789, - "shipDate" : "2000-01-23T04:56:07.000+0000", + "petId" : 123456789, "complete" : true, - "status" : "aeiou" -} ]}, {contentType=application/xml, example= + "status" : "aeiou", + "quantity" : 123, + "shipDate" : "2000-01-23T04:56:07.000+0000" +} ], contentType=application/json}, {example= 123456 123456 0 2000-01-23T04:56:07.000Z string true -}] - - examples: [{contentType=application/json, example=[ { - "petId" : 123456789, - "quantity" : 123, +, contentType=application/xml}] + - examples: [{example=[ { "id" : 123456789, - "shipDate" : "2000-01-23T04:56:07.000+0000", + "petId" : 123456789, "complete" : true, - "status" : "aeiou" -} ]}, {contentType=application/xml, example= + "status" : "aeiou", + "quantity" : 123, + "shipDate" : "2000-01-23T04:56:07.000+0000" +} ], contentType=application/json}, {example= 123456 123456 0 2000-01-23T04:56:07.000Z string true -}] +, contentType=application/xml}] - parameter status: (query) Status value that needs to be considered for query @@ -143,12 +143,12 @@ public class StoreAPI: APIBase { - API Key: - type: apiKey api_key - name: api_key - - examples: [{contentType=application/json, example={ + - examples: [{example={ "key" : 123 -}}, {contentType=application/xml, example=not implemented io.swagger.models.properties.MapProperty@d1e580af}] - - examples: [{contentType=application/json, example={ +}, contentType=application/json}, {example=not implemented io.swagger.models.properties.MapProperty@d1e580af, contentType=application/xml}] + - examples: [{example={ "key" : 123 -}}, {contentType=application/xml, example=not implemented io.swagger.models.properties.MapProperty@d1e580af}] +}, contentType=application/json}, {example=not implemented io.swagger.models.properties.MapProperty@d1e580af, contentType=application/xml}] - returns: RequestBuilder<[String:Int]> */ @@ -208,36 +208,36 @@ public class StoreAPI: APIBase { - API Key: - type: apiKey x-test_api_client_secret - name: test_api_client_secret - - examples: [{contentType=application/json, example={ - "petId" : 123456789, - "quantity" : 123, + - examples: [{example={ "id" : 123456789, - "shipDate" : "2000-01-23T04:56:07.000+0000", + "petId" : 123456789, "complete" : true, - "status" : "aeiou" -}}, {contentType=application/xml, example= + "status" : "aeiou", + "quantity" : 123, + "shipDate" : "2000-01-23T04:56:07.000+0000" +}, contentType=application/json}, {example= 123456 123456 0 2000-01-23T04:56:07.000Z string true -}] - - examples: [{contentType=application/json, example={ - "petId" : 123456789, - "quantity" : 123, +, contentType=application/xml}] + - examples: [{example={ "id" : 123456789, - "shipDate" : "2000-01-23T04:56:07.000+0000", + "petId" : 123456789, "complete" : true, - "status" : "aeiou" -}}, {contentType=application/xml, example= + "status" : "aeiou", + "quantity" : 123, + "shipDate" : "2000-01-23T04:56:07.000+0000" +}, contentType=application/json}, {example= 123456 123456 0 2000-01-23T04:56:07.000Z string true -}] +, contentType=application/xml}] - parameter body: (body) order placed for purchasing the pet @@ -292,42 +292,42 @@ public class StoreAPI: APIBase { - GET /store/order/{orderId} - For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - - API Key: - - type: apiKey test_api_key_query (QUERY) - - name: test_api_key_query - API Key: - type: apiKey test_api_key_header - name: test_api_key_header - - examples: [{contentType=application/json, example={ - "petId" : 123456789, - "quantity" : 123, + - API Key: + - type: apiKey test_api_key_query (QUERY) + - name: test_api_key_query + - examples: [{example={ "id" : 123456789, - "shipDate" : "2000-01-23T04:56:07.000+0000", + "petId" : 123456789, "complete" : true, - "status" : "aeiou" -}}, {contentType=application/xml, example= + "status" : "aeiou", + "quantity" : 123, + "shipDate" : "2000-01-23T04:56:07.000+0000" +}, contentType=application/json}, {example= 123456 123456 0 2000-01-23T04:56:07.000Z string true -}] - - examples: [{contentType=application/json, example={ - "petId" : 123456789, - "quantity" : 123, +, contentType=application/xml}] + - examples: [{example={ "id" : 123456789, - "shipDate" : "2000-01-23T04:56:07.000+0000", + "petId" : 123456789, "complete" : true, - "status" : "aeiou" -}}, {contentType=application/xml, example= + "status" : "aeiou", + "quantity" : 123, + "shipDate" : "2000-01-23T04:56:07.000+0000" +}, contentType=application/json}, {example= 123456 123456 0 2000-01-23T04:56:07.000Z string true -}] +, contentType=application/xml}] - parameter orderId: (path) ID of pet that needs to be fetched diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift index dffc01db15f..7d304039bb0 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift @@ -213,8 +213,8 @@ public class UserAPI: APIBase { - GET /user/login - - - examples: [{contentType=application/json, example="aeiou"}, {contentType=application/xml, example=string}] - - examples: [{contentType=application/json, example="aeiou"}, {contentType=application/xml, example=string}] + - examples: [{example="aeiou", contentType=application/json}, {example=string, contentType=application/xml}] + - examples: [{example="aeiou", contentType=application/json}, {example=string, contentType=application/xml}] - parameter username: (query) The user name for login - parameter password: (query) The password for login in clear text @@ -325,7 +325,7 @@ public class UserAPI: APIBase { - GET /user/{username} - - - examples: [{contentType=application/json, example={ + - examples: [{example={ "id" : 1, "username" : "johnp", "firstName" : "John", @@ -334,7 +334,7 @@ public class UserAPI: APIBase { "password" : "-secret-", "phone" : "0123456789", "userStatus" : 0 -}}] +}, contentType=application/json}] - parameter username: (path) The name that needs to be fetched. Use user1 for testing. diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models.swift index f9b6c5ade48..04c07fa97ff 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models.swift @@ -124,24 +124,6 @@ class Decoders { fatalError("formatter failed to parse \(source)") } - // Decoder for [Order] - Decoders.addDecoder(clazz: [Order].self) { (source: AnyObject) -> [Order] in - return Decoders.decode(clazz: [Order].self, source: source) - } - // Decoder for Order - Decoders.addDecoder(clazz: Order.self) { (source: AnyObject) -> Order in - let sourceDictionary = source as! [NSObject:AnyObject] - let instance = Order() - instance.id = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["id"]) - instance.petId = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["petId"]) - instance.quantity = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["quantity"]) - instance.shipDate = Decoders.decodeOptional(clazz: NSDate.self, source: sourceDictionary["shipDate"]) - instance.status = Order.Status(rawValue: (sourceDictionary["status"] as? String) ?? "") - instance.complete = Decoders.decodeOptional(clazz: Bool.self, source: sourceDictionary["complete"]) - return instance - } - - // Decoder for [User] Decoders.addDecoder(clazz: [User].self) { (source: AnyObject) -> [User] in return Decoders.decode(clazz: [User].self, source: source) @@ -176,20 +158,6 @@ class Decoders { } - // Decoder for [Tag] - Decoders.addDecoder(clazz: [Tag].self) { (source: AnyObject) -> [Tag] in - return Decoders.decode(clazz: [Tag].self, source: source) - } - // Decoder for Tag - Decoders.addDecoder(clazz: Tag.self) { (source: AnyObject) -> Tag in - let sourceDictionary = source as! [NSObject:AnyObject] - let instance = Tag() - instance.id = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["id"]) - instance.name = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["name"]) - return instance - } - - // Decoder for [Pet] Decoders.addDecoder(clazz: [Pet].self) { (source: AnyObject) -> [Pet] in return Decoders.decode(clazz: [Pet].self, source: source) @@ -207,6 +175,38 @@ class Decoders { return instance } + + // Decoder for [Tag] + Decoders.addDecoder(clazz: [Tag].self) { (source: AnyObject) -> [Tag] in + return Decoders.decode(clazz: [Tag].self, source: source) + } + // Decoder for Tag + Decoders.addDecoder(clazz: Tag.self) { (source: AnyObject) -> Tag in + let sourceDictionary = source as! [NSObject:AnyObject] + let instance = Tag() + instance.id = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["id"]) + instance.name = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["name"]) + return instance + } + + + // Decoder for [Order] + Decoders.addDecoder(clazz: [Order].self) { (source: AnyObject) -> [Order] in + return Decoders.decode(clazz: [Order].self, source: source) + } + // Decoder for Order + Decoders.addDecoder(clazz: Order.self) { (source: AnyObject) -> Order in + let sourceDictionary = source as! [NSObject:AnyObject] + let instance = Order() + instance.id = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["id"]) + instance.petId = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["petId"]) + instance.quantity = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["quantity"]) + instance.shipDate = Decoders.decodeOptional(clazz: NSDate.self, source: sourceDictionary["shipDate"]) + instance.status = Order.Status(rawValue: (sourceDictionary["status"] as? String) ?? "") + instance.complete = Decoders.decodeOptional(clazz: Bool.self, source: sourceDictionary["complete"]) + return instance + } + } } } diff --git a/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/api/PetApi.java b/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/api/PetApi.java index 62251207319..9d7192ff535 100644 --- a/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/api/PetApi.java +++ b/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/api/PetApi.java @@ -6,7 +6,7 @@ import java.io.File; import javax.ws.rs.*; import javax.ws.rs.core.Response; -@Path("/v2") +@Path("/") public interface PetApi { @PUT @Path("/pet") @@ -37,28 +37,23 @@ public interface PetApi { @Path("/pet/{petId}") @Consumes({ "application/x-www-form-urlencoded" }) @Produces({ "application/json", "application/xml" }) - public Response updatePetWithForm(@PathParam("petId") String petId, - @Multipart(value = "name", required = false) String name, - @Multipart(value = "status", required = false) String status); + public Response updatePetWithForm(@PathParam("petId") String petId,@Multipart(value = "name", required = false) String name,@Multipart(value = "status", required = false) String status); @DELETE @Path("/pet/{petId}") @Produces({ "application/json", "application/xml" }) - public Response deletePet(@PathParam("petId") Long petId, - @HeaderParam("api_key") String apiKey); + public Response deletePet(@PathParam("petId") Long petId,@HeaderParam("api_key") String apiKey); @POST @Path("/pet/{petId}/uploadImage") @Consumes({ "multipart/form-data" }) @Produces({ "application/json", "application/xml" }) - public Response uploadFile(@PathParam("petId") Long petId, - @Multipart(value = "additionalMetadata", required = false) String additionalMetadata, - @Multipart(value = "file", required = false) InputStream fileInputStream, + public Response uploadFile(@PathParam("petId") Long petId,@Multipart(value = "additionalMetadata", required = false) String additionalMetadata, @Multipart(value = "file", required = false) InputStream fileInputStream, @Multipart(value = "file" , required = false) Attachment fileDetail); @GET @Path("/pet/{petId}?testing_byte_array=true") @Produces({ "application/json", "application/xml" }) - public Response getPetByIdWithByteArray(@PathParam("petId") Long petId); + public Response petPetIdtestingByteArraytrueGet(@PathParam("petId") Long petId); @POST @Path("/pet?testing_byte_array=true") @Consumes({ "application/json", "application/xml" }) diff --git a/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/api/StoreApi.java b/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/api/StoreApi.java index 4738649215d..f6729e7fafb 100644 --- a/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/api/StoreApi.java +++ b/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/api/StoreApi.java @@ -6,7 +6,7 @@ import io.swagger.model.Order; import javax.ws.rs.*; import javax.ws.rs.core.Response; -@Path("/v2") +@Path("/") public interface StoreApi { @GET @Path("/store/inventory") diff --git a/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/api/UserApi.java b/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/api/UserApi.java index 840331009b1..88027929085 100644 --- a/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/api/UserApi.java +++ b/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/api/UserApi.java @@ -1,12 +1,12 @@ package io.swagger.api; import io.swagger.model.User; -import java.util.*; +import java.util.List; import javax.ws.rs.*; import javax.ws.rs.core.Response; -@Path("/v2") +@Path("/") public interface UserApi { @POST @Path("/user") @@ -27,8 +27,7 @@ public interface UserApi { @Path("/user/login") @Produces({ "application/json", "application/xml" }) - public Response loginUser(@QueryParam("username") String username, - @QueryParam("password") String password); + public Response loginUser(@QueryParam("username") String username,@QueryParam("password") String password); @GET @Path("/user/logout") @@ -43,8 +42,7 @@ public interface UserApi { @Path("/user/{username}") @Produces({ "application/json", "application/xml" }) - public Response updateUser(@PathParam("username") String username, - User body); + public Response updateUser(@PathParam("username") String username,User body); @DELETE @Path("/user/{username}") diff --git a/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/Category.java b/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/Category.java index c4dcc713964..d34537dc435 100644 --- a/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/Category.java +++ b/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/Category.java @@ -1,54 +1,69 @@ package io.swagger.model; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonValue; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; + + +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; - +@XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = + { "id", "name" +}) @XmlRootElement(name="Category") public class Category { - + private Long id = null; - + private String name = null; /** **/ - @JsonProperty("id") + public Long getId() { return id; } public void setId(Long id) { this.id = id; } - /** **/ - @JsonProperty("name") + public String getName() { return name; } public void setName(String name) { this.name = name; } - @Override - public String toString() { + public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class Category {\n"); - sb.append(" id: ").append(id).append("\n"); - sb.append(" name: ").append(name).append("\n"); - sb.append("}\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append("}"); return sb.toString(); } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private static String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } } + diff --git a/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/Order.java b/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/Order.java index 333d1b8b604..60ffccbd8f9 100644 --- a/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/Order.java +++ b/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/Order.java @@ -1,115 +1,139 @@ package io.swagger.model; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonValue; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import java.util.Date; + + +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; - +@XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = + { "id", "petId", "quantity", "shipDate", "status", "complete" +}) @XmlRootElement(name="Order") public class Order { - + private Long id = null; - + private Long petId = null; - + private Integer quantity = null; - - private Date shipDate = null; - - public enum StatusEnum { - placed, approved, delivered, - }; + + private javax.xml.datatype.XMLGregorianCalendar shipDate = null; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlType; + +@XmlType(name="Order") +@XmlEnum +public enum Order { + {values=[placed, approved, delivered], enumVars=[{name=PLACED, value=placed}, {name=APPROVED, value=approved}, {name=DELIVERED, value=delivered}]}, + + public String value() { + return name(); + } + + public static Order fromValue(String v) { + return valueOf(v); + } +} + private StatusEnum status = null; - + private Boolean complete = null; /** **/ - @JsonProperty("id") + public Long getId() { return id; } public void setId(Long id) { this.id = id; } - /** **/ - @JsonProperty("petId") + public Long getPetId() { return petId; } public void setPetId(Long petId) { this.petId = petId; } - /** **/ - @JsonProperty("quantity") + public Integer getQuantity() { return quantity; } public void setQuantity(Integer quantity) { this.quantity = quantity; } - /** **/ - @JsonProperty("shipDate") - public Date getShipDate() { + + public javax.xml.datatype.XMLGregorianCalendar getShipDate() { return shipDate; } - public void setShipDate(Date shipDate) { + public void setShipDate(javax.xml.datatype.XMLGregorianCalendar shipDate) { this.shipDate = shipDate; } - /** * Order Status **/ - @JsonProperty("status") + public StatusEnum getStatus() { return status; } public void setStatus(StatusEnum status) { this.status = status; } - /** **/ - @JsonProperty("complete") + public Boolean getComplete() { return complete; } public void setComplete(Boolean complete) { this.complete = complete; } - @Override - public String toString() { + public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class Order {\n"); - sb.append(" id: ").append(id).append("\n"); - sb.append(" petId: ").append(petId).append("\n"); - sb.append(" quantity: ").append(quantity).append("\n"); - sb.append(" shipDate: ").append(shipDate).append("\n"); - sb.append(" status: ").append(status).append("\n"); - sb.append(" complete: ").append(complete).append("\n"); - sb.append("}\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" petId: ").append(toIndentedString(petId)).append("\n"); + sb.append(" quantity: ").append(toIndentedString(quantity)).append("\n"); + sb.append(" shipDate: ").append(toIndentedString(shipDate)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" complete: ").append(toIndentedString(complete)).append("\n"); + sb.append("}"); return sb.toString(); } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private static String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } } + diff --git a/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/Pet.java b/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/Pet.java index 53fa2ef229d..979781f19e0 100644 --- a/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/Pet.java +++ b/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/Pet.java @@ -1,117 +1,143 @@ package io.swagger.model; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonValue; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; import io.swagger.model.Category; import io.swagger.model.Tag; -import java.util.*; +import java.util.ArrayList; +import java.util.List; + + +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; - +@XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = + { "id", "category", "name", "photoUrls", "tags", "status" +}) @XmlRootElement(name="Pet") public class Pet { - + private Long id = null; - + private Category category = null; - + private String name = null; - + private List photoUrls = new ArrayList(); - + private List tags = new ArrayList(); - - public enum StatusEnum { - available, pending, sold, - }; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlType; + +@XmlType(name="Pet") +@XmlEnum +public enum Pet { + {values=[available, pending, sold], enumVars=[{name=AVAILABLE, value=available}, {name=PENDING, value=pending}, {name=SOLD, value=sold}]}, + + public String value() { + return name(); + } + + public static Pet fromValue(String v) { + return valueOf(v); + } +} + private StatusEnum status = null; /** **/ - @JsonProperty("id") + public Long getId() { return id; } public void setId(Long id) { this.id = id; } - /** **/ - @JsonProperty("category") + public Category getCategory() { return category; } public void setCategory(Category category) { this.category = category; } - /** **/ - @JsonProperty("name") + public String getName() { return name; } public void setName(String name) { this.name = name; } - /** **/ - @JsonProperty("photoUrls") + public List getPhotoUrls() { return photoUrls; } public void setPhotoUrls(List photoUrls) { this.photoUrls = photoUrls; } - /** **/ - @JsonProperty("tags") + public List getTags() { return tags; } public void setTags(List tags) { this.tags = tags; } - /** * pet status in the store **/ - @JsonProperty("status") + public StatusEnum getStatus() { return status; } public void setStatus(StatusEnum status) { this.status = status; } - @Override - public String toString() { + public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class Pet {\n"); - sb.append(" id: ").append(id).append("\n"); - sb.append(" category: ").append(category).append("\n"); - sb.append(" name: ").append(name).append("\n"); - sb.append(" photoUrls: ").append(photoUrls).append("\n"); - sb.append(" tags: ").append(tags).append("\n"); - sb.append(" status: ").append(status).append("\n"); - sb.append("}\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" category: ").append(toIndentedString(category)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" photoUrls: ").append(toIndentedString(photoUrls)).append("\n"); + sb.append(" tags: ").append(toIndentedString(tags)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append("}"); return sb.toString(); } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private static String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } } + diff --git a/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/Tag.java b/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/Tag.java index 933dda70086..b2a2bcaaff9 100644 --- a/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/Tag.java +++ b/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/Tag.java @@ -1,54 +1,69 @@ package io.swagger.model; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonValue; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; + + +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; - +@XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = + { "id", "name" +}) @XmlRootElement(name="Tag") public class Tag { - + private Long id = null; - + private String name = null; /** **/ - @JsonProperty("id") + public Long getId() { return id; } public void setId(Long id) { this.id = id; } - /** **/ - @JsonProperty("name") + public String getName() { return name; } public void setName(String name) { this.name = name; } - @Override - public String toString() { + public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class Tag {\n"); - sb.append(" id: ").append(id).append("\n"); - sb.append(" name: ").append(name).append("\n"); - sb.append("}\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append("}"); return sb.toString(); } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private static String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } } + diff --git a/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/User.java b/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/User.java index a8da05deac7..8683a630e5c 100644 --- a/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/User.java +++ b/samples/server/petstore/jaxrs-cxf/gen/java/io/swagger/model/User.java @@ -1,139 +1,148 @@ package io.swagger.model; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonValue; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; + + +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; - +@XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = + { "id", "username", "firstName", "lastName", "email", "password", "phone", "userStatus" +}) @XmlRootElement(name="User") public class User { - + private Long id = null; - + private String username = null; - + private String firstName = null; - + private String lastName = null; - + private String email = null; - + private String password = null; - + private String phone = null; - + private Integer userStatus = null; /** **/ - @JsonProperty("id") + public Long getId() { return id; } public void setId(Long id) { this.id = id; } - /** **/ - @JsonProperty("username") + public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } - /** **/ - @JsonProperty("firstName") + public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } - /** **/ - @JsonProperty("lastName") + public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } - /** **/ - @JsonProperty("email") + public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } - /** **/ - @JsonProperty("password") + public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } - /** **/ - @JsonProperty("phone") + public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } - /** * User Status **/ - @JsonProperty("userStatus") + public Integer getUserStatus() { return userStatus; } public void setUserStatus(Integer userStatus) { this.userStatus = userStatus; } - @Override - public String toString() { + public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class User {\n"); - sb.append(" id: ").append(id).append("\n"); - sb.append(" username: ").append(username).append("\n"); - sb.append(" firstName: ").append(firstName).append("\n"); - sb.append(" lastName: ").append(lastName).append("\n"); - sb.append(" email: ").append(email).append("\n"); - sb.append(" password: ").append(password).append("\n"); - sb.append(" phone: ").append(phone).append("\n"); - sb.append(" userStatus: ").append(userStatus).append("\n"); - sb.append("}\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" username: ").append(toIndentedString(username)).append("\n"); + sb.append(" firstName: ").append(toIndentedString(firstName)).append("\n"); + sb.append(" lastName: ").append(toIndentedString(lastName)).append("\n"); + sb.append(" email: ").append(toIndentedString(email)).append("\n"); + sb.append(" password: ").append(toIndentedString(password)).append("\n"); + sb.append(" phone: ").append(toIndentedString(phone)).append("\n"); + sb.append(" userStatus: ").append(toIndentedString(userStatus)).append("\n"); + sb.append("}"); return sb.toString(); } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private static String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } } +