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