diff --git a/README.md b/README.md index b43351aa619..2a5c8641ac2 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,23 @@ -# Swagger Code Generator +# FotitionSDK -[![Build Status](https://travis-ci.org/swagger-api/swagger-codegen.png)](https://travis-ci.org/swagger-api/swagger-codegen) +## Requirements -## Overview -This is the swagger codegen project, which allows generation of client libraries automatically from a Swagger-compliant server. +The API client library requires ARC (Automatic Reference Counting) to be enabled in your Xcode project. -Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additional information about the Swagger project, including additional libraries with support for other languages and more. +## Installation -## Build and run using docker +To install it, put the API client library in your project and then simply add the following line to your Podfile: +```ruby +pod "FotitionSDK", :path => "/path/to/lib" ``` -git clone https://github.com/swagger-api/swagger-codegen -cd swagger-codegen +## Recommendation -./run-in-docker.sh mvn package - ``` +It's recommended to create an instance of ApiClient per thread in a multithreaded environment to avoid any potential issue. -Build a nodejs server stub: +## Author - ``` -./run-in-docker.sh generate \ - -i http://petstore.swagger.io/v2/swagger.json \ - -l nodejs \ - -o samples/server/petstore/nodejs - ``` - -## Compatibility -The Swagger Specification has undergone 3 revisions since initial creation in 2010. The swagger-codegen project has the following compatibilies with the swagger specification: Swagger Codegen Version | Release Date | Swagger Spec compatibility | Notes -------------------------- | ------------ | -------------------------- | ----- diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FotitionClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FotitionClientCodegen.java deleted file mode 100644 index 50c58a050a6..00000000000 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FotitionClientCodegen.java +++ /dev/null @@ -1,362 +0,0 @@ -package io.swagger.codegen.languages; - -import io.swagger.codegen.CliOption; -import io.swagger.codegen.CodegenConfig; -import io.swagger.codegen.CodegenProperty; -import io.swagger.codegen.CodegenType; -import io.swagger.codegen.DefaultCodegen; -import io.swagger.codegen.SupportingFile; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.MapProperty; -import io.swagger.models.properties.Property; - -import java.io.File; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; - - -public class FotitionClientCodegen extends DefaultCodegen implements CodegenConfig { - - protected Set foundationClasses = new HashSet(); - protected String sourceFolder = "fotition-objc-client"; - protected String classPrefix = "FT"; - protected String projectName = "fotition-objc-client"; - - public FotitionClientCodegen() { - outputFolder = "generated-code" + File.separator + "fotition-objc"; - modelTemplateFiles.put("model-header.mustache", ".h"); - modelTemplateFiles.put("model-body.mustache", ".m"); - apiTemplateFiles.put("api-header.mustache", ".h"); - apiTemplateFiles.put("api-body.mustache", ".m"); - templateDir = "fotition-objc"; - modelPackage = ""; - - defaultIncludes = new HashSet( - Arrays.asList( - "bool", - "BOOL", - "int", - "NSString", - "NSObject", - "NSArray", - "NSNumber", - "NSDate", - "NSDictionary", - "NSMutableArray", - "NSMutableDictionary") - ); - languageSpecificPrimitives = new HashSet( - Arrays.asList( - "NSNumber", - "NSString", - "NSObject", - "NSDate", - "bool", - "BOOL") - ); - - // ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm - reservedWords = new HashSet( - Arrays.asList( - "auto", "else", "long", "switch", - "break", "enum", "register", "typedef", - "case", "extern", "return", "union", - "char", "float", "short", "unsigned", - "const", "for", "signed", "void", - "continue", "goto", "sizeof", "volatile", - "default", "if", "id", "static", "while", - "do", "int", "struct", "_Packed", - "double", "protocol", "interface", "implementation", - "NSObject", "NSInteger", "NSNumber", "CGFloat", - "property", "nonatomic", "retain", "strong", - "weak", "unsafe_unretained", "readwrite", "readonly" - )); - - typeMapping = new HashMap(); - typeMapping.put("enum", "NSString"); - typeMapping.put("Date", "NSDate"); - typeMapping.put("DateTime", "NSDate"); - typeMapping.put("boolean", "NSNumber"); - typeMapping.put("string", "NSString"); - typeMapping.put("integer", "NSNumber"); - typeMapping.put("int", "NSNumber"); - typeMapping.put("float", "NSNumber"); - typeMapping.put("long", "NSNumber"); - typeMapping.put("double", "NSNumber"); - typeMapping.put("array", "NSArray"); - typeMapping.put("map", "NSDictionary"); - typeMapping.put("number", "NSNumber"); - typeMapping.put("List", "NSArray"); - typeMapping.put("object", "NSObject"); - - importMapping = new HashMap(); - - foundationClasses = new HashSet( - Arrays.asList( - "NSNumber", - "NSObject", - "NSString", - "NSDate", - "NSDictionary") - ); - - instantiationTypes.put("array", "NSMutableArray"); - instantiationTypes.put("map", "NSMutableDictionary"); - - cliOptions.add(new CliOption("classPrefix", "prefix for generated classes")); - cliOptions.add(new CliOption("sourceFolder", "source folder for generated code")); - cliOptions.add(new CliOption("projectName", "name of the Xcode project in generated Podfile")); - } - - public CodegenType getTag() { - return CodegenType.CLIENT; - } - - public String getName() { - return "fotition-objc"; - } - - public String getHelp() { - return "Generates an Objective-C client library for Fotition."; - } - - @Override - public void processOpts() { - super.processOpts(); - - if (additionalProperties.containsKey("sourceFolder")) { - this.setSourceFolder((String) additionalProperties.get("sourceFolder")); - } - - if (additionalProperties.containsKey("classPrefix")) { - this.setClassPrefix((String) additionalProperties.get("classPrefix")); - } - - if (additionalProperties.containsKey("projectName")) { - this.setProjectName((String) additionalProperties.get("projectName")); - } else { - additionalProperties.put("projectName", projectName); - } - - supportingFiles.add(new SupportingFile("FTObject.h", sourceFolder, "FTObject.h")); - supportingFiles.add(new SupportingFile("FTObject.m", sourceFolder, "FTObject.m")); - supportingFiles.add(new SupportingFile("FTQueryParamCollection.h", sourceFolder, "FTQueryParamCollection.h")); - supportingFiles.add(new SupportingFile("FTQueryParamCollection.m", sourceFolder, "FTQueryParamCollection.m")); - supportingFiles.add(new SupportingFile("FotitionAPIClient.h", sourceFolder, "FotitionAPIClient.h")); - supportingFiles.add(new SupportingFile("FotitionAPIClient.m", sourceFolder, "FotitionAPIClient.m")); - supportingFiles.add(new SupportingFile("FTFile.h", sourceFolder, "FTFile.h")); - supportingFiles.add(new SupportingFile("FTFile.m", sourceFolder, "FTFile.m")); - supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.m", sourceFolder, "JSONValueTransformer+ISO8601.m")); - supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.h", sourceFolder, "JSONValueTransformer+ISO8601.h")); - supportingFiles.add(new SupportingFile("FTConfiguration-body.mustache", sourceFolder, "FTConfiguration.m")); - supportingFiles.add(new SupportingFile("FTConfiguration-header.mustache", sourceFolder, "FTConfiguration.h")); - supportingFiles.add(new SupportingFile("Podfile.mustache", "", "Podfile")); - } - - @Override - public String toInstantiationType(Property p) { - if (p instanceof MapProperty) { - MapProperty ap = (MapProperty) p; - String inner = getSwaggerType(ap.getAdditionalProperties()); - return instantiationTypes.get("map"); - } else if (p instanceof ArrayProperty) { - ArrayProperty ap = (ArrayProperty) p; - String inner = getSwaggerType(ap.getItems()); - return instantiationTypes.get("array"); - } else { - return null; - } - } - - @Override - public String getTypeDeclaration(String name) { - if (languageSpecificPrimitives.contains(name) && !foundationClasses.contains(name)) { - return name; - } else { - return name + "*"; - } - } - - @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) && !foundationClasses.contains(type)) { - return toModelName(type); - } - } else { - type = swaggerType; - } - return toModelName(type); - } - - @Override - public String getTypeDeclaration(Property p) { - if (p instanceof ArrayProperty) { - ArrayProperty ap = (ArrayProperty) p; - Property inner = ap.getItems(); - String innerType = getSwaggerType(inner); - - // In this codition, type of property p is array of primitive, - // return container type with pointer, e.g. `NSArray*' - if (languageSpecificPrimitives.contains(innerType)) { - return getSwaggerType(p) + "*"; - } - - // In this codition, type of property p is array of model, - // return container type combine inner type with pointer, e.g. `NSArray*' - String innerTypeDeclaration = getTypeDeclaration(inner); - - if (innerTypeDeclaration.endsWith("*")) { - innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1); - } - - return getSwaggerType(p) + "<" + innerTypeDeclaration + ">*"; - } else { - String swaggerType = getSwaggerType(p); - - // In this codition, type of p is objective-c primitive type, e.g. `NSSNumber', - // return type of p with pointer, e.g. `NSNumber*' - if (languageSpecificPrimitives.contains(swaggerType) && - foundationClasses.contains(swaggerType)) { - return swaggerType + "*"; - } - // In this codition, type of p is c primitive type, e.g. `bool', - // return type of p, e.g. `bool' - else if (languageSpecificPrimitives.contains(swaggerType)) { - return swaggerType; - } - // In this codition, type of p is objective-c object type, e.g. `FTPet', - // return type of p with pointer, e.g. `FTPet*' - else { - return swaggerType + "*"; - } - } - } - - @Override - public String toModelName(String type) { - type = type.replaceAll("[^0-9a-zA-Z_]", "_"); - - // language build-in classes - if (typeMapping.keySet().contains(type) || - foundationClasses.contains(type) || - importMapping.values().contains(type) || - defaultIncludes.contains(type) || - languageSpecificPrimitives.contains(type)) { - return camelize(type); - } - // custom classes - else { - return classPrefix + camelize(type); - } - } - - @Override - public String toModelFilename(String name) { - // should be the same as the model name - return toModelName(name); - } - - @Override - protected void setNonArrayMapProperty(CodegenProperty property, String type) { - super.setNonArrayMapProperty(property, type); - if ("NSDictionary".equals(type)) { - property.setter = "initWithDictionary"; - } else { - property.setter = "initWithValues"; - } - } - - @Override - public String toModelImport(String name) { - if ("".equals(modelPackage())) { - return name; - } else { - return modelPackage() + "." + name; - } - } - - @Override - public String toDefaultValue(Property p) { - return null; - } - - @Override - public String apiFileFolder() { - return outputFolder + File.separator + sourceFolder; - } - - @Override - public String modelFileFolder() { - return outputFolder + File.separator + sourceFolder; - } - - @Override - public String toApiName(String name) { - return classPrefix + camelize(name) + "Api"; - } - - public String toApiFilename(String name) { - return classPrefix + camelize(name) + "Api"; - } - - @Override - public String toVarName(String name) { - // replace non-word characters to `_` - // e.g. `created-at` to `created_at` - name = name.replaceAll("[^a-zA-Z0-9_]", "_"); - - // if it's all upper case, do noting - if (name.matches("^[A-Z_]$")) { - return name; - } - - // camelize (lower first character) the variable name - // e.g. `pet_id` to `petId` - name = camelize(name, true); - - // for reserved word or word starting with number, prepend `_` - if (reservedWords.contains(name) || name.matches("^\\d.*")) { - name = escapeReservedWord(name); - } - - return name; - } - - @Override - public String toParamName(String name) { - // should be the same as variable name - return toVarName(name); - } - - public String escapeReservedWord(String name) { - return "_" + name; - } - - @Override - public String toOperationId(String operationId) { - // method name cannot use reserved keyword, e.g. return - if (reservedWords.contains(operationId)) { - throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); - } - - return camelize(operationId, true); - } - - public void setSourceFolder(String sourceFolder) { - this.sourceFolder = sourceFolder; - } - - public void setClassPrefix(String classPrefix) { - this.classPrefix = classPrefix; - } - - public void setProjectName(String projectName) { - this.projectName = projectName; - } -} diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FotitionSwiftGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FotitionSwiftGenerator.java deleted file mode 100644 index 4978f6c31d9..00000000000 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FotitionSwiftGenerator.java +++ /dev/null @@ -1,265 +0,0 @@ -package io.swagger.codegen.languages; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; -import io.swagger.codegen.CodegenConfig; -import io.swagger.codegen.CodegenOperation; -import io.swagger.codegen.CodegenProperty; -import io.swagger.codegen.CodegenType; -import io.swagger.codegen.DefaultCodegen; -import io.swagger.codegen.SupportingFile; -import io.swagger.models.Model; -import io.swagger.models.Operation; -import io.swagger.models.parameters.HeaderParameter; -import io.swagger.models.parameters.Parameter; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.MapProperty; -import io.swagger.models.properties.Property; -import org.apache.commons.lang.StringUtils; - -import javax.annotation.Nullable; -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class FotitionSwiftGenerator extends DefaultCodegen implements CodegenConfig { - private static final Pattern PATH_PARAM_PATTERN = Pattern.compile("\\{[a-zA-Z_]+\\}"); - protected String sourceFolder = "Classes/Swaggers"; - - public FotitionSwiftGenerator() { - super(); - outputFolder = "generated-code/swift"; - modelTemplateFiles.put("model.mustache", ".swift"); - apiTemplateFiles.put("api.mustache", ".swift"); - templateDir = "fotition-swift"; - apiPackage = "/APIs"; - modelPackage = "/Models"; - - // Inject application name - String appName = System.getProperty("appName"); - if (appName == null) { - appName = "SwaggerClient"; - } - additionalProperties.put("projectName", appName); - - // Inject base url override - String basePathOverride = System.getProperty("basePathOverride"); - if (basePathOverride != null) { - additionalProperties.put("basePathOverride", basePathOverride); - } - - sourceFolder = appName + "/" + sourceFolder; - - supportingFiles.add(new SupportingFile("Cartfile.mustache", "", "Cartfile")); - supportingFiles.add(new SupportingFile("APIHelper.mustache", sourceFolder, "APIHelper.swift")); - supportingFiles.add(new SupportingFile("AlamofireImplementations.mustache", sourceFolder, "AlamofireImplementations.swift")); - supportingFiles.add(new SupportingFile("Extensions.mustache", sourceFolder, "Extensions.swift")); - supportingFiles.add(new SupportingFile("Models.mustache", sourceFolder, "Models.swift")); - supportingFiles.add(new SupportingFile("APIs.mustache", sourceFolder, "APIs.swift")); - - languageSpecificPrimitives = new HashSet( - Arrays.asList( - "Int", - "Float", - "Double", - "Bool", - "Void", - "String", - "Character") - ); - defaultIncludes = new HashSet( - Arrays.asList( - "NSDate", - "Array", - "Dictionary", - "Set", - "Any", - "Empty", - "AnyObject") - ); - reservedWords = new HashSet( - 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", "NSData"); - - importMapping = new HashMap(); - } - - private static String normalizePath(String path) { - StringBuilder builder = new StringBuilder(); - - int cursor = 0; - Matcher matcher = PATH_PARAM_PATTERN.matcher(path); - boolean found = matcher.find(); - while (found) { - String stringBeforeMatch = path.substring(cursor, matcher.start()); - builder.append(stringBeforeMatch); - - String group = matcher.group().substring(1, matcher.group().length() - 1); - group = camelize(group, true); - builder - .append("{") - .append(group) - .append("}"); - - cursor = matcher.end(); - found = matcher.find(); - } - - String stringAfterMatch = path.substring(cursor); - builder.append(stringAfterMatch); - - return builder.toString(); - } - - public CodegenType getTag() { - return CodegenType.CLIENT; - } - - public String getName() { - return "swift"; - } - - public String getHelp() { - return "Generates a swift client library."; - } - - @Override - public String escapeReservedWord(String name) { - return "_" + name; // add an underscore to the name - } - - @Override - public String modelFileFolder() { - return outputFolder + "/" + sourceFolder + modelPackage().replace('.', File.separatorChar); - } - - @Override - public String apiFileFolder() { - return outputFolder + "/" + sourceFolder + apiPackage().replace('.', File.separatorChar); - } - - @Override - public String getTypeDeclaration(Property p) { - if (p instanceof ArrayProperty) { - ArrayProperty ap = (ArrayProperty) p; - Property inner = ap.getItems(); - return "[" + getTypeDeclaration(inner) + "]"; - } else if (p instanceof MapProperty) { - MapProperty mp = (MapProperty) p; - Property inner = mp.getAdditionalProperties(); - return "[String:" + getTypeDeclaration(inner) + "]"; - } - return super.getTypeDeclaration(p); - } - - @Override - public String getSwaggerType(Property p) { - String swaggerType = super.getSwaggerType(p); - String type = null; - if (typeMapping.containsKey(swaggerType)) { - type = typeMapping.get(swaggerType); - if (languageSpecificPrimitives.contains(type)) { - return toModelName(type); - } - } else { - type = swaggerType; - } - return toModelName(type); - } - - @Override - public String toDefaultValue(Property p) { - // nil - return null; - } - - @Override - public String toInstantiationType(Property p) { - if (p instanceof MapProperty) { - MapProperty ap = (MapProperty) p; - String inner = getSwaggerType(ap.getAdditionalProperties()); - return "[String:" + inner + "]"; - } else if (p instanceof ArrayProperty) { - ArrayProperty ap = (ArrayProperty) p; - String inner = getSwaggerType(ap.getItems()); - return "[" + inner + "]"; - } - return null; - } - - @Override - public CodegenProperty fromProperty(String name, Property p) { - CodegenProperty codegenProperty = super.fromProperty(name, p); - if (codegenProperty.isEnum) { - List> swiftEnums = new ArrayList>(); - List values = (List) codegenProperty.allowableValues.get("values"); - for (String value : values) { - Map map = new HashMap(); - map.put("enum", StringUtils.capitalize(value)); - map.put("raw", value); - swiftEnums.add(map); - } - codegenProperty.allowableValues.put("values", swiftEnums); - codegenProperty.datatypeWithEnum = - StringUtils.left(codegenProperty.datatypeWithEnum, codegenProperty.datatypeWithEnum.length() - "Enum".length()); - } - return codegenProperty; - } - - @Override - public String toApiName(String name) { - if (name.length() == 0) { - return "DefaultAPI"; - } - return initialCaps(name) + "API"; - } - - @Override - public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map definitions) { - path = normalizePath(path); - 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); - } -} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ObjcClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ObjcClientCodegen.java index cb6ec79a984..29469cf7073 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ObjcClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ObjcClientCodegen.java @@ -23,6 +23,11 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { protected String podName = "SwaggerClient"; protected String podVersion = "1.0.0"; protected String classPrefix = "SWG"; + protected String authorName = "Swagger"; + protected String authorEmail = "swagger@swagger.io"; + protected String license = "MIT"; + protected String gitRepoURL = "https://github.com/swagger-api/swagger-codegen"; + public ObjcClientCodegen() { super(); @@ -112,6 +117,10 @@ public ObjcClientCodegen() { cliOptions.add(new CliOption("classPrefix", "prefix for generated classes (convention: Abbreviation of pod name e.g. `HN` for `HackerNews`), default: `SWG`")); cliOptions.add(new CliOption("podName", "cocoapods package name (convention: CameCase), default: `SwaggerClient`")); cliOptions.add(new CliOption("podVersion", "cocoapods package version, default: `1.0.0`")); + cliOptions.add(new CliOption("authorName", "Name to use in the podspec file, default: `Swagger`")); + cliOptions.add(new CliOption("authorEmail", "Email to use in the podspec file, default: `swagger@swagger.io`")); + cliOptions.add(new CliOption("gitRepoURL", "URL for the git repo where this podspec should point to, default: `https://github.com/swagger-api/swagger-codegen`")); + cliOptions.add(new CliOption("license", "License to use in the podspec file, default: `MIT`")); } public CodegenType getTag() { @@ -141,10 +150,30 @@ public void processOpts() { if (additionalProperties.containsKey("classPrefix")) { setClassPrefix((String) additionalProperties.get("classPrefix")); } + + if (additionalProperties.containsKey("authorName")) { + setAuthorName((String) additionalProperties.get("authorName")); + } + + if (additionalProperties.containsKey("authorEmail")) { + setAuthorEmail((String) additionalProperties.get("authorEmail")); + } + + if (additionalProperties.containsKey("gitRepoURL")) { + setGitRepoURL((String) additionalProperties.get("gitRepoURL")); + } + + if (additionalProperties.containsKey("license")) { + setLicense((String) additionalProperties.get("license")); + } additionalProperties.put("podName", podName); additionalProperties.put("podVersion", podVersion); additionalProperties.put("classPrefix", classPrefix); + additionalProperties.put("authorName", authorName); + additionalProperties.put("authorEmail", authorEmail); + additionalProperties.put("gitRepoURL", gitRepoURL); + additionalProperties.put("license", license); String swaggerFolder = podName; @@ -385,4 +414,20 @@ public void setPodName(String podName) { public void setPodVersion(String podVersion) { this.podVersion = podVersion; } + + public void setAuthorEmail(String authorEmail) { + this.authorEmail = authorEmail; + } + + public void setAuthorName(String authorName) { + this.authorName = authorName; + } + + public void setGitRepoURL(String gitRepoURL) { + this.gitRepoURL = gitRepoURL; + } + + public void setLicense(String license) { + this.license = license; + } } diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/FTConfiguration-body.mustache b/modules/swagger-codegen/src/main/resources/fotition-objc/FTConfiguration-body.mustache deleted file mode 100644 index aebd85dfe9a..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/FTConfiguration-body.mustache +++ /dev/null @@ -1,99 +0,0 @@ -#import "FTConfiguration.h" - -@interface FTConfiguration () - -@property (readwrite, nonatomic, strong) NSMutableDictionary *mutableApiKey; -@property (readwrite, nonatomic, strong) NSMutableDictionary *mutableApiKeyPrefix; - -@end - -@implementation FTConfiguration - -#pragma mark - Singletion Methods - -+ (instancetype) sharedConfig { - static FTConfiguration *shardConfig = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - shardConfig = [[self alloc] init]; - }); - return shardConfig; -} - -#pragma mark - Initialize Methods - -- (instancetype) init { - self = [super init]; - if (self) { - self.username = @""; - self.password = @""; - self.mutableApiKey = [NSMutableDictionary dictionary]; - self.mutableApiKeyPrefix = [NSMutableDictionary dictionary]; - } - return self; -} - -#pragma mark - Instance Methods - -- (NSString *) getApiKeyWithPrefix:(NSString *)key { - if ([self.apiKeyPrefix objectForKey:key] && [self.apiKey objectForKey:key]) { - return [NSString stringWithFormat:@"%@ %@", [self.apiKeyPrefix objectForKey:key], [self.apiKey objectForKey:key]]; - } - else if ([self.apiKey objectForKey:key]) { - return [NSString stringWithFormat:@"%@", [self.apiKey objectForKey:key]]; - } - else { - return @""; - } -} - -- (NSString *) getBasicAuthToken { - NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", self.username, self.password]; - NSData *data = [basicAuthCredentials dataUsingEncoding:NSUTF8StringEncoding]; - basicAuthCredentials = [NSString stringWithFormat:@"Basic %@", [data base64EncodedStringWithOptions:0]]; - - return basicAuthCredentials; -} - -#pragma mark - Setter Methods - -- (void) setValue:(NSString *)value forApiKeyField:(NSString *)field { - [self.mutableApiKey setValue:value forKey:field]; -} - -- (void) setValue:(NSString *)value forApiKeyPrefixField:(NSString *)field { - [self.mutableApiKeyPrefix setValue:value forKey:field]; -} - -#pragma mark - Getter Methods - -- (NSDictionary *) apiKey { - return [NSDictionary dictionaryWithDictionary:self.mutableApiKey]; -} - -- (NSDictionary *) apiKeyPrefix { - return [NSDictionary dictionaryWithDictionary:self.mutableApiKeyPrefix]; -} - -#pragma mark - - -- (NSDictionary *) authSettings { - return @{ {{#authMethods}}{{#isApiKey}} - @"{{name}}": @{ - @"type": @"api_key", - @"in": {{#isKeyInHeader}}@"header"{{/isKeyInHeader}}{{#isKeyInQuery}}@"query"{{/isKeyInQuery}}, - @"key": @"{{keyParamName}}", - @"value": [self getApiKeyWithPrefix:@"{{keyParamName}}"] - }, - {{/isApiKey}}{{#isBasic}} - @"{{name}}": @{ - @"type": @"basic", - @"in": @"header", - @"key": @"Authorization", - @"value": [self getBasicAuthToken] - }, - {{/isBasic}}{{/authMethods}} - }; -} - -@end diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/FTConfiguration-header.mustache b/modules/swagger-codegen/src/main/resources/fotition-objc/FTConfiguration-header.mustache deleted file mode 100644 index 5c8cc96953c..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/FTConfiguration-header.mustache +++ /dev/null @@ -1,56 +0,0 @@ -#import - -@interface FTConfiguration : NSObject - - -/** - * Api key values for Api Key type Authentication - * - * To add or remove api key, use `setValue:forApiKeyField:`. - */ -@property (readonly, nonatomic, strong) NSDictionary *apiKey; - -/** - * Api key prefix values to be prepend to the respective api key - * - * To add or remove prefix, use `setValue:forApiKeyPrefixField:`. - */ -@property (readonly, nonatomic, strong) NSDictionary *apiKeyPrefix; - -/** - * Usename and Password for Basic type Authentication - */ -@property (nonatomic) NSString *username; -@property (nonatomic) NSString *password; - -/** - * Get configuration singleton instance - */ -+ (instancetype) sharedConfig; - -/** - * Sets field in `apiKey` - */ -- (void) setValue:(NSString *)value forApiKeyField:(NSString*)field; - -/** - * Sets field in `apiKeyPrefix` - */ -- (void) setValue:(NSString *)value forApiKeyPrefixField:(NSString *)field; - -/** - * Get API key (with prefix if set) - */ -- (NSString *) getApiKeyWithPrefix:(NSString *) key; - -/** - * Get Basic Auth token - */ -- (NSString *) getBasicAuthToken; - -/** - * Get Authentication Setings - */ -- (NSDictionary *) authSettings; - -@end diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/FTFile.h b/modules/swagger-codegen/src/main/resources/fotition-objc/FTFile.h deleted file mode 100644 index 18f126885e5..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/FTFile.h +++ /dev/null @@ -1,14 +0,0 @@ -#import - -@interface FTFile : NSObject - -@property(nonatomic, readonly) NSString* name; -@property(nonatomic, readonly) NSString* mimeType; -@property(nonatomic, readonly) NSData* data; -@property(nonatomic) NSString* paramName; - -- (id) initWithNameData: (NSString*) filename - mimeType: (NSString*) mimeType - data: (NSData*) data; - -@end \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/FTFile.m b/modules/swagger-codegen/src/main/resources/fotition-objc/FTFile.m deleted file mode 100644 index 5f0b7934125..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/FTFile.m +++ /dev/null @@ -1,26 +0,0 @@ -#import "FTFile.h" - -@implementation FTFile - -@synthesize name = _name; -@synthesize mimeType = _mimeType; -@synthesize data = _data; - -- (id) init { - self = [super init]; - return self; -} - -- (id) initWithNameData: (NSString*) filename - mimeType: (NSString*) fileMimeType - data: (NSData*) data { - self = [super init]; - if(self) { - _name = filename; - _mimeType = fileMimeType; - _data = data; - } - return self; -} - -@end \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/FTObject.h b/modules/swagger-codegen/src/main/resources/fotition-objc/FTObject.h deleted file mode 100644 index 6b861585c6d..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/FTObject.h +++ /dev/null @@ -1,5 +0,0 @@ -#import -#import "JSONModel.h" - -@interface FTObject : JSONModel -@end diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/FTObject.m b/modules/swagger-codegen/src/main/resources/fotition-objc/FTObject.m deleted file mode 100644 index 833c1b85019..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/FTObject.m +++ /dev/null @@ -1,4 +0,0 @@ -#import "FTObject.h" - -@implementation FTObject -@end diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/FTQueryParamCollection.h b/modules/swagger-codegen/src/main/resources/fotition-objc/FTQueryParamCollection.h deleted file mode 100644 index b6ed93a256c..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/FTQueryParamCollection.h +++ /dev/null @@ -1,11 +0,0 @@ -#import - -@interface FTQueryParamCollection : NSObject - -@property(nonatomic, readonly) NSArray* values; -@property(nonatomic, readonly) NSString* format; - -- (id) initWithValuesAndFormat: (NSArray*) values - format: (NSString*) format; - -@end diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/FTQueryParamCollection.m b/modules/swagger-codegen/src/main/resources/fotition-objc/FTQueryParamCollection.m deleted file mode 100644 index a1506e19e34..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/FTQueryParamCollection.m +++ /dev/null @@ -1,16 +0,0 @@ -#import "FTQueryParamCollection.h" - -@implementation FTQueryParamCollection - -@synthesize values = _values; -@synthesize format = _format; - -- (id) initWithValuesAndFormat: (NSArray*) values - format: (NSString*) format { - _values = values; - _format = format; - - return self; -} - -@end diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/FotitionAPIClient.h b/modules/swagger-codegen/src/main/resources/fotition-objc/FotitionAPIClient.h deleted file mode 100644 index 10f7afb1a2a..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/FotitionAPIClient.h +++ /dev/null @@ -1,216 +0,0 @@ -#import -#import "AFHTTPRequestOperationManager.h" - -/** - * A key for `NSError` user info dictionaries. - * - * The corresponding value is the parsed response body for an HTTP error. - */ -extern NSString *const FotitionResponseObjectErrorKey; - - -@interface FotitionAPIClient : AFHTTPRequestOperationManager - -@property(nonatomic, assign) NSURLRequestCachePolicy cachePolicy; -@property(nonatomic, assign) NSTimeInterval timeoutInterval; -@property(nonatomic, assign) BOOL logRequests; -@property(nonatomic, assign) BOOL logCacheHits; -@property(nonatomic, assign) BOOL logServerResponses; -@property(nonatomic, assign) BOOL logJSON; -@property(nonatomic, assign) BOOL logHTTP; -@property(nonatomic, readonly) NSOperationQueue* queue; - -/** - * Get the Api Client instance from pool - * - * @param baseUrl The base url of api client. - * - * @return The FotitionAPIClient instance. - */ -+(FotitionAPIClient *)sharedClientFromPool:(NSString *)baseUrl; - -/** - * Get the operations queue - * - * @return The `shardQueue` static variable. - */ -+(NSOperationQueue*) sharedQueue; - -/** - * Turn on logging - * - * @param state logging state, must be `YES` or `NO` - */ -+(void)setLoggingEnabled:(bool) state; - -/** - * Clear Cache - */ -+(void)clearCache; - -/** - * Turn on cache - * - * @param enabled If the cached is enable, must be `YES` or `NO` - */ -+(void)setCacheEnabled:(BOOL) enabled; - -/** - * Get the request queue size - * - * @return The size of `queuedRequests` static variable. - */ -+(unsigned long)requestQueueSize; - -/** - * Set the client unreachable - * - * @param state off line state, must be `YES` or `NO` - */ -+(void) setOfflineState:(BOOL) state; - -/** - * Get the client reachability - * - * @return The client reachability. - */ -+(AFNetworkReachabilityStatus) getReachabilityStatus; - -/** - * Get the next request id - * - * @return The next executed request id. - */ -+(NSNumber*) nextRequestId; - -/** - * Generate request id and add it to the queue - * - * @return The next executed request id. - */ -+(NSNumber*) queueRequest; - -/** - * Remove request id from the queue - * - * @param requestId The request which will be removed. - */ -+(void) cancelRequest:(NSNumber*)requestId; - -/** - * URL encode NSString - * - * @param unescaped The string which will be escaped. - * - * @return The escaped string. - */ -+(NSString*) escape:(id)unescaped; - -/** - * Customize the behavior when the reachability changed - * - * @param changeBlock The block will be executed when the reachability changed. - */ -+(void) setReachabilityChangeBlock:(void(^)(int))changeBlock; - -/** - * Set the client reachability strategy - * - * @param host The host of FotitionAPIClient. - */ -+(void) configureCacheReachibilityForHost:(NSString*)host; - -/** - * Detect Accept header from accepts NSArray - * - * @param accepts NSArray of header - * - * @return The Accept header - */ -+(NSString *) selectHeaderAccept:(NSArray *)accepts; - -/** - * Detect Content-Type header from contentTypes NSArray - * - * @param contentTypes NSArray of header - * - * @return The Content-Type header - */ -+(NSString *) selectHeaderContentType:(NSArray *)contentTypes; - -/** - * Set header for request - * - * @param value The header value - * @param forKey The header key - */ --(void)setHeaderValue:(NSString*) value - forKey:(NSString*) forKey; - -/** - * Update header parameters and query parameters for authentication - * - * @param headers The header parameter will be udpated, passed by pointer to pointer. - * @param querys The query parameters will be updated, passed by pointer to pointer. - * @param authSettings The authentication names NSArray. - */ -- (void) updateHeaderParams:(NSDictionary **)headers - queryParams:(NSDictionary **)querys - WithAuthSettings:(NSArray *)authSettings; - -/** - * Perform request - * - * Request with non-empty response - * - * @param path Request url. - * @param method Request method. - * @param queryParams Request query parameters. - * @param body Request body. - * @param headerParams Request header parameters. - * @param authSettings Request authentication names. - * @param requestContentType Request content-type. - * @param responseContentType Response content-type. - * @param completionBlock The block will be executed when the request completed. - * - * @return The request id. - */ --(NSNumber*) dictionary:(NSString*) path - method:(NSString*) method - queryParams:(NSDictionary*) queryParams - body:(id) body - headerParams:(NSDictionary*) headerParams - authSettings: (NSArray *) authSettings - requestContentType:(NSString*) requestContentType - responseContentType:(NSString*) responseContentType - completionBlock:(void (^)(NSDictionary *, NSDictionary*, NSError *))completionBlock; - -/** - * Perform request - * - * Request with empty response - * - * @param path Request url. - * @param method Request method. - * @param queryParams Request query parameters. - * @param body Request body. - * @param headerParams Request header parameters. - * @param authSettings Request authentication names. - * @param requestContentType Request content-type. - * @param responseContentType Response content-type. - * @param completionBlock The block will be executed when the request completed. - * - * @return The request id. - */ --(NSNumber*) stringWithCompletionBlock:(NSString*) path - method:(NSString*) method - queryParams:(NSDictionary*) queryParams - body:(id) body - headerParams:(NSDictionary*) headerParams - authSettings: (NSArray *) authSettings - requestContentType:(NSString*) requestContentType - responseContentType:(NSString*) responseContentType - completionBlock:(void (^)(NSDictionary *, NSString*, NSError *))completionBlock; -@end - - diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/FotitionAPIClient.m b/modules/swagger-codegen/src/main/resources/fotition-objc/FotitionAPIClient.m deleted file mode 100644 index 704974a6444..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/FotitionAPIClient.m +++ /dev/null @@ -1,686 +0,0 @@ -#import "FotitionAPIClient.h" -#import "FTFile.h" -#import "FTQueryParamCollection.h" -#import "FTConfiguration.h" - -@implementation FotitionAPIClient - -NSString *const FotitionResponseObjectErrorKey = @"FotitionResponseObject"; - -static long requestId = 0; -static bool offlineState = false; -static NSMutableSet * queuedRequests = nil; -static bool cacheEnabled = false; -static AFNetworkReachabilityStatus reachabilityStatus = AFNetworkReachabilityStatusNotReachable; -static NSOperationQueue* sharedQueue; -static void (^reachabilityChangeBlock)(int); -static bool loggingEnabled = true; - -#pragma mark - Log Methods - -+(void)setLoggingEnabled:(bool) state { - loggingEnabled = state; -} - -- (void)logRequest:(NSURLRequest*)request { - NSLog(@"request: %@", [self descriptionForRequest:request]); -} - -- (void)logResponse:(id)data forRequest:(NSURLRequest*)request error:(NSError*)error { - NSLog(@"request: %@ response: %@ ", [self descriptionForRequest:request], data ); -} - -#pragma mark - - -+(void)clearCache { - [[NSURLCache sharedURLCache] removeAllCachedResponses]; -} - -+(void)setCacheEnabled:(BOOL)enabled { - cacheEnabled = enabled; -} - -+(void)configureCacheWithMemoryAndDiskCapacity: (unsigned long) memorySize - diskSize: (unsigned long) diskSize { - NSAssert(memorySize > 0, @"invalid in-memory cache size"); - NSAssert(diskSize >= 0, @"invalid disk cache size"); - - NSURLCache *cache = - [[NSURLCache alloc] - initWithMemoryCapacity:memorySize - diskCapacity:diskSize - diskPath:@"swagger_url_cache"]; - - [NSURLCache setSharedURLCache:cache]; -} - -+(NSOperationQueue*) sharedQueue { - return sharedQueue; -} - -+(FotitionAPIClient *)sharedClientFromPool:(NSString *)baseUrl { - static NSMutableDictionary *_pool = nil; - if (queuedRequests == nil) { - queuedRequests = [[NSMutableSet alloc]init]; - } - if(_pool == nil) { - // setup static vars - // create queue - sharedQueue = [[NSOperationQueue alloc] init]; - - // create pool - _pool = [[NSMutableDictionary alloc] init]; - - // initialize URL cache - [FotitionAPIClient configureCacheWithMemoryAndDiskCapacity:4*1024*1024 diskSize:32*1024*1024]; - - // configure reachability - [FotitionAPIClient configureCacheReachibilityForHost:baseUrl]; - } - - @synchronized(self) { - FotitionAPIClient * client = [_pool objectForKey:baseUrl]; - if (client == nil) { - client = [[FotitionAPIClient alloc] initWithBaseURL:[NSURL URLWithString:baseUrl]]; - [_pool setValue:client forKey:baseUrl ]; - if(loggingEnabled) - NSLog(@"new client for path %@", baseUrl); - } - if(loggingEnabled) - NSLog(@"returning client for path %@", baseUrl); - return client; - } -} - -/* - * Detect `Accept` from accepts - */ -+ (NSString *) selectHeaderAccept:(NSArray *)accepts -{ - if (accepts == nil || [accepts count] == 0) { - return @""; - } - - NSMutableArray *lowerAccepts = [[NSMutableArray alloc] initWithCapacity:[accepts count]]; - [accepts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - [lowerAccepts addObject:[obj lowercaseString]]; - }]; - - - if ([lowerAccepts containsObject:@"application/json"]) { - return @"application/json"; - } - else { - return [lowerAccepts componentsJoinedByString:@", "]; - } -} - -/* - * Detect `Content-Type` from contentTypes - */ -+ (NSString *) selectHeaderContentType:(NSArray *)contentTypes -{ - if (contentTypes == nil || [contentTypes count] == 0) { - return @"application/json"; - } - - NSMutableArray *lowerContentTypes = [[NSMutableArray alloc] initWithCapacity:[contentTypes count]]; - [contentTypes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - [lowerContentTypes addObject:[obj lowercaseString]]; - }]; - - if ([lowerContentTypes containsObject:@"application/json"]) { - return @"application/json"; - } - else { - return lowerContentTypes[0]; - } -} - --(void)setHeaderValue:(NSString*) value - forKey:(NSString*) forKey { - [self.requestSerializer setValue:value forHTTPHeaderField:forKey]; -} - -+(unsigned long)requestQueueSize { - return [queuedRequests count]; -} - -+(NSNumber*) nextRequestId { - @synchronized(self) { - long nextId = ++requestId; - if(loggingEnabled) - NSLog(@"got id %ld", nextId); - return [NSNumber numberWithLong:nextId]; - } -} - -+(NSNumber*) queueRequest { - NSNumber* requestId = [FotitionAPIClient nextRequestId]; - if(loggingEnabled) - NSLog(@"added %@ to request queue", requestId); - [queuedRequests addObject:requestId]; - return requestId; -} - -+(void) cancelRequest:(NSNumber*)requestId { - [queuedRequests removeObject:requestId]; -} - -+(NSString*) escape:(id)unescaped { - if([unescaped isKindOfClass:[NSString class]]){ - return (NSString *)CFBridgingRelease - (CFURLCreateStringByAddingPercentEscapes( - NULL, - (__bridge CFStringRef) unescaped, - NULL, - (CFStringRef)@"!*'();:@&=+$,/?%#[]", - kCFStringEncodingUTF8)); - } - else { - return [NSString stringWithFormat:@"%@", unescaped]; - } -} - --(Boolean) executeRequestWithId:(NSNumber*) requestId { - NSSet* matchingItems = [queuedRequests objectsPassingTest:^BOOL(id obj, BOOL *stop) { - if([obj intValue] == [requestId intValue]) - return TRUE; - else return FALSE; - }]; - - if(matchingItems.count == 1) { - if(loggingEnabled) - NSLog(@"removing request id %@", requestId); - [queuedRequests removeObject:requestId]; - return true; - } - else - return false; -} - --(id)initWithBaseURL:(NSURL *)url { - self = [super initWithBaseURL:url]; - self.requestSerializer = [AFJSONRequestSerializer serializer]; - self.responseSerializer = [AFJSONResponseSerializer serializer]; - if (!self) - return nil; - return self; -} - -+(AFNetworkReachabilityStatus) getReachabilityStatus { - return reachabilityStatus; -} - -+(void) setReachabilityChangeBlock:(void(^)(int))changeBlock { - reachabilityChangeBlock = changeBlock; -} - -+(void) setOfflineState:(BOOL) state { - offlineState = state; -} - -+(void) configureCacheReachibilityForHost:(NSString*)host { - [[FotitionAPIClient sharedClientFromPool:host].reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { - reachabilityStatus = status; - switch (status) { - case AFNetworkReachabilityStatusUnknown: - if(loggingEnabled) - NSLog(@"reachability changed to AFNetworkReachabilityStatusUnknown"); - [FotitionAPIClient setOfflineState:true]; - break; - - case AFNetworkReachabilityStatusNotReachable: - if(loggingEnabled) - NSLog(@"reachability changed to AFNetworkReachabilityStatusNotReachable"); - [FotitionAPIClient setOfflineState:true]; - break; - - case AFNetworkReachabilityStatusReachableViaWWAN: - if(loggingEnabled) - NSLog(@"reachability changed to AFNetworkReachabilityStatusReachableViaWWAN"); - [FotitionAPIClient setOfflineState:false]; - break; - - case AFNetworkReachabilityStatusReachableViaWiFi: - if(loggingEnabled) - NSLog(@"reachability changed to AFNetworkReachabilityStatusReachableViaWiFi"); - [FotitionAPIClient setOfflineState:false]; - break; - default: - break; - } - // call the reachability block, if configured - if(reachabilityChangeBlock != nil) { - reachabilityChangeBlock(status); - } - }]; - [[FotitionAPIClient sharedClientFromPool:host].reachabilityManager startMonitoring]; -} - --(NSString*) pathWithQueryParamsToString:(NSString*) path - queryParams:(NSDictionary*) queryParams { - NSString * separator = nil; - int counter = 0; - - NSMutableString * requestUrl = [NSMutableString stringWithFormat:@"%@", path]; - if(queryParams != nil){ - for(NSString * key in [queryParams keyEnumerator]){ - if(counter == 0) separator = @"?"; - else separator = @"&"; - id queryParam = [queryParams valueForKey:key]; - if([queryParam isKindOfClass:[NSString class]]){ - [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, - [FotitionAPIClient escape:key], [FotitionAPIClient escape:[queryParams valueForKey:key]]]]; - } - else if([queryParam isKindOfClass:[FTQueryParamCollection class]]){ - FTQueryParamCollection * coll = (FTQueryParamCollection*) queryParam; - NSArray* values = [coll values]; - NSString* format = [coll format]; - - if([format isEqualToString:@"csv"]) { - [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, - [FotitionAPIClient escape:key], [NSString stringWithFormat:@"%@", [values componentsJoinedByString:@","]]]]; - - } - else if([format isEqualToString:@"tsv"]) { - [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, - [FotitionAPIClient escape:key], [NSString stringWithFormat:@"%@", [values componentsJoinedByString:@"\t"]]]]; - - } - else if([format isEqualToString:@"pipes"]) { - [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, - [FotitionAPIClient escape:key], [NSString stringWithFormat:@"%@", [values componentsJoinedByString:@"|"]]]]; - - } - else if([format isEqualToString:@"multi"]) { - for(id obj in values) { - [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, - [FotitionAPIClient escape:key], [NSString stringWithFormat:@"%@", obj]]]; - counter += 1; - } - - } - } - else { - [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, - [FotitionAPIClient escape:key], [NSString stringWithFormat:@"%@", [queryParams valueForKey:key]]]]; - } - - counter += 1; - } - } - return requestUrl; -} - -- (NSString*)descriptionForRequest:(NSURLRequest*)request { - return [[request URL] absoluteString]; -} - - -/** - * Update header and query params based on authentication settings - */ -- (void) updateHeaderParams:(NSDictionary *__autoreleasing *)headers - queryParams:(NSDictionary *__autoreleasing *)querys - WithAuthSettings:(NSArray *)authSettings { - - if (!authSettings || [authSettings count] == 0) { - return; - } - - NSMutableDictionary *headersWithAuth = [NSMutableDictionary dictionaryWithDictionary:*headers]; - NSMutableDictionary *querysWithAuth = [NSMutableDictionary dictionaryWithDictionary:*querys]; - - FTConfiguration *config = [FTConfiguration sharedConfig]; - for (NSString *auth in authSettings) { - NSDictionary *authSetting = [[config authSettings] objectForKey:auth]; - - if (authSetting) { - if ([authSetting[@"in"] isEqualToString:@"header"]) { - [headersWithAuth setObject:authSetting[@"value"] forKey:authSetting[@"key"]]; - } - else if ([authSetting[@"in"] isEqualToString:@"query"]) { - [querysWithAuth setObject:authSetting[@"value"] forKey:authSetting[@"key"]]; - } - } - } - - *headers = [NSDictionary dictionaryWithDictionary:headersWithAuth]; - *querys = [NSDictionary dictionaryWithDictionary:querysWithAuth]; -} - -#pragma mark - Perform Request Methods - --(NSNumber*) dictionary: (NSString*) path - method: (NSString*) method - queryParams: (NSDictionary*) queryParams - body: (id) body - headerParams: (NSDictionary*) headerParams - authSettings: (NSArray *) authSettings - requestContentType: (NSString*) requestContentType - responseContentType: (NSString*) responseContentType - completionBlock: (void (^)(NSDictionary *, NSDictionary*, NSError *))completionBlock { - - // setting request serializer - if ([requestContentType isEqualToString:@"application/json"]) { - self.requestSerializer = [AFJSONRequestSerializer serializer]; - } - else if ([requestContentType isEqualToString:@"application/x-www-form-urlencoded"]) { - self.requestSerializer = [AFHTTPRequestSerializer serializer]; - } - else if ([requestContentType isEqualToString:@"multipart/form-data"]) { - self.requestSerializer = [AFHTTPRequestSerializer serializer]; - } - else { - NSAssert(false, @"unsupport request type %@", requestContentType); - } - - // setting response serializer - if ([responseContentType isEqualToString:@"application/json"]) { - self.responseSerializer = [AFJSONResponseSerializer serializer]; - } - else { - self.responseSerializer = [AFHTTPResponseSerializer serializer]; - } - - // auth setting - [self updateHeaderParams:&headerParams queryParams:&queryParams WithAuthSettings:authSettings]; - - NSMutableURLRequest * request = nil; - if (body != nil && [body isKindOfClass:[NSArray class]]){ - FTFile * file; - NSMutableDictionary * params = [[NSMutableDictionary alloc] init]; - for(id obj in body) { - if([obj isKindOfClass:[FTFile class]]) { - file = (FTFile*) obj; - requestContentType = @"multipart/form-data"; - } - else if([obj isKindOfClass:[NSDictionary class]]) { - for(NSString * key in obj) { - params[key] = obj[key]; - } - } - } - NSString * urlString = [[NSURL URLWithString:path relativeToURL:self.baseURL] absoluteString]; - - // request with multipart form - if([requestContentType isEqualToString:@"multipart/form-data"]) { - request = [self.requestSerializer multipartFormRequestWithMethod: @"POST" - URLString: urlString - parameters: nil - constructingBodyWithBlock: ^(id formData) { - - for(NSString * key in params) { - NSData* data = [params[key] dataUsingEncoding:NSUTF8StringEncoding]; - [formData appendPartWithFormData: data name: key]; - } - - if (file) { - [formData appendPartWithFileData: [file data] - name: [file paramName] - fileName: [file name] - mimeType: [file mimeType]]; - } - - } - error:nil]; - } - // request with form parameters or json - else { - NSString* pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams]; - NSString* urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString]; - - request = [self.requestSerializer requestWithMethod:method - URLString:urlString - parameters:params - error:nil]; - } - } - else { - NSString * pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams]; - NSString * urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString]; - - request = [self.requestSerializer requestWithMethod:method - URLString:urlString - parameters:body - error:nil]; - } - BOOL hasHeaderParams = false; - if(headerParams != nil && [headerParams count] > 0) - hasHeaderParams = true; - if(offlineState) { - NSLog(@"%@ cache forced", path); - [request setCachePolicy:NSURLRequestReturnCacheDataDontLoad]; - } - else if(!hasHeaderParams && [method isEqualToString:@"GET"] && cacheEnabled) { - NSLog(@"%@ cache enabled", path); - [request setCachePolicy:NSURLRequestUseProtocolCachePolicy]; - } - else { - NSLog(@"%@ cache disabled", path); - [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; - } - - if(body != nil) { - if([body isKindOfClass:[NSDictionary class]] || [body isKindOfClass:[NSArray class]]){ - [self setHeaderValue:requestContentType forKey:@"Content-Type"]; - } - else if ([body isKindOfClass:[FTFile class]]) {} - else { - NSAssert(false, @"unsupported post type!"); - } - } - if(headerParams != nil){ - for(NSString * key in [headerParams keyEnumerator]){ - [request setValue:[headerParams valueForKey:key] forHTTPHeaderField:key]; - } - } - [self setHeaderValue:responseContentType forKey:@"Accept"]; - - // Always disable cookies! - [request setHTTPShouldHandleCookies:NO]; - - - if (self.logRequests) { - [self logRequest:request]; - } - - NSNumber* requestId = [FotitionAPIClient queueRequest]; - AFHTTPRequestOperation *op = - [self HTTPRequestOperationWithRequest:request - success:^(AFHTTPRequestOperation *operation, id JSON) { - if([self executeRequestWithId:requestId]) { - if(self.logServerResponses) - [self logResponse:JSON forRequest:request error:nil]; - completionBlock([[operation response] allHeaderFields], JSON, nil); - } - } failure:^(AFHTTPRequestOperation *operation, NSError *error) { - if([self executeRequestWithId:requestId]) { - NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; - if(operation.responseObject) { - // Add in the (parsed) response body. - userInfo[FotitionResponseObjectErrorKey] = operation.responseObject; - } - NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo]; - - if(self.logServerResponses) - [self logResponse:nil forRequest:request error:augmentedError]; - completionBlock([[operation response] allHeaderFields], nil, augmentedError); - } - } - ]; - - [self.operationQueue addOperation:op]; - return requestId; -} - --(NSNumber*) stringWithCompletionBlock: (NSString*) path - method: (NSString*) method - queryParams: (NSDictionary*) queryParams - body: (id) body - headerParams: (NSDictionary*) headerParams - authSettings: (NSArray *) authSettings - requestContentType: (NSString*) requestContentType - responseContentType: (NSString*) responseContentType - completionBlock: (void (^)(NSDictionary *, NSString*, NSError *))completionBlock { - - // setting request serializer - if ([requestContentType isEqualToString:@"application/json"]) { - self.requestSerializer = [AFJSONRequestSerializer serializer]; - } - else if ([requestContentType isEqualToString:@"application/x-www-form-urlencoded"]) { - self.requestSerializer = [AFHTTPRequestSerializer serializer]; - } - else if ([requestContentType isEqualToString:@"multipart/form-data"]) { - self.requestSerializer = [AFHTTPRequestSerializer serializer]; - } - else { - NSAssert(false, @"unsupport request type %@", requestContentType); - } - - // setting response serializer - if ([responseContentType isEqualToString:@"application/json"]) { - self.responseSerializer = [AFJSONResponseSerializer serializer]; - } - else { - self.responseSerializer = [AFHTTPResponseSerializer serializer]; - } - - // auth setting - [self updateHeaderParams:&headerParams queryParams:&queryParams WithAuthSettings:authSettings]; - - NSMutableURLRequest * request = nil; - if (body != nil && [body isKindOfClass:[NSArray class]]){ - FTFile * file; - NSMutableDictionary * params = [[NSMutableDictionary alloc] init]; - for(id obj in body) { - if([obj isKindOfClass:[FTFile class]]) { - file = (FTFile*) obj; - requestContentType = @"multipart/form-data"; - } - else if([obj isKindOfClass:[NSDictionary class]]) { - for(NSString * key in obj) { - params[key] = obj[key]; - } - } - } - NSString * urlString = [[NSURL URLWithString:path relativeToURL:self.baseURL] absoluteString]; - - // request with multipart form - if([requestContentType isEqualToString:@"multipart/form-data"]) { - request = [self.requestSerializer multipartFormRequestWithMethod: @"POST" - URLString: urlString - parameters: nil - constructingBodyWithBlock: ^(id formData) { - - for(NSString * key in params) { - NSData* data = [params[key] dataUsingEncoding:NSUTF8StringEncoding]; - [formData appendPartWithFormData: data name: key]; - } - - if (file) { - [formData appendPartWithFileData: [file data] - name: [file paramName] - fileName: [file name] - mimeType: [file mimeType]]; - } - - } - error:nil]; - } - // request with form parameters or json - else { - NSString* pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams]; - NSString* urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString]; - - request = [self.requestSerializer requestWithMethod:method - URLString:urlString - parameters:params - error:nil]; - } - - } - else { - NSString * pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams]; - NSString * urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString]; - - request = [self.requestSerializer requestWithMethod: method - URLString: urlString - parameters: body - error: nil]; - } - BOOL hasHeaderParams = false; - if(headerParams != nil && [headerParams count] > 0) - hasHeaderParams = true; - if(offlineState) { - NSLog(@"%@ cache forced", path); - [request setCachePolicy:NSURLRequestReturnCacheDataDontLoad]; - } - else if(!hasHeaderParams && [method isEqualToString:@"GET"] && cacheEnabled) { - NSLog(@"%@ cache enabled", path); - [request setCachePolicy:NSURLRequestUseProtocolCachePolicy]; - } - else { - NSLog(@"%@ cache disabled", path); - [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; - } - - - if(body != nil) { - if([body isKindOfClass:[NSDictionary class]] || [body isKindOfClass:[NSArray class]]){ - [self.requestSerializer setValue:requestContentType forHTTPHeaderField:@"Content-Type"]; - } - else if ([body isKindOfClass:[FTFile class]]){} - else { - NSAssert(false, @"unsupported post type!"); - } - } - if(headerParams != nil){ - for(NSString * key in [headerParams keyEnumerator]){ - [request setValue:[headerParams valueForKey:key] forHTTPHeaderField:key]; - } - } - [self.requestSerializer setValue:responseContentType forHTTPHeaderField:@"Accept"]; - - - // Always disable cookies! - [request setHTTPShouldHandleCookies:NO]; - - NSNumber* requestId = [FotitionAPIClient queueRequest]; - AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request - success:^(AFHTTPRequestOperation *operation, id responseObject) { - NSString *response = [operation responseString]; - if([self executeRequestWithId:requestId]) { - if(self.logServerResponses) - [self logResponse:responseObject forRequest:request error:nil]; - completionBlock([[operation response] allHeaderFields], response, nil); - } - } failure:^(AFHTTPRequestOperation *operation, NSError *error) { - if([self executeRequestWithId:requestId]) { - NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; - if(operation.responseObject) { - // Add in the (parsed) response body. - userInfo[FotitionResponseObjectErrorKey] = operation.responseObject; - } - NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo]; - - if(self.logServerResponses) - [self logResponse:nil forRequest:request error:augmentedError]; - completionBlock([[operation response] allHeaderFields], nil, augmentedError); - } - }]; - - [self.operationQueue addOperation:op]; - return requestId; -} - -@end - - - - - - - - diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/JSONValueTransformer+ISO8601.h b/modules/swagger-codegen/src/main/resources/fotition-objc/JSONValueTransformer+ISO8601.h deleted file mode 100644 index 832f485f4f0..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/JSONValueTransformer+ISO8601.h +++ /dev/null @@ -1,6 +0,0 @@ -#import -#import -#import - -@interface JSONValueTransformer (ISO8601) -@end diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/JSONValueTransformer+ISO8601.m b/modules/swagger-codegen/src/main/resources/fotition-objc/JSONValueTransformer+ISO8601.m deleted file mode 100644 index cec8bdeea27..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/JSONValueTransformer+ISO8601.m +++ /dev/null @@ -1,10 +0,0 @@ -#import "JSONValueTransformer+ISO8601.h" - -@implementation JSONValueTransformer (ISO8601) - -- (NSDate *) NSDateFromNSString:(NSString *)string -{ - return [NSDate dateWithISO8601String:string]; -} - -@end diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/Podfile.mustache b/modules/swagger-codegen/src/main/resources/fotition-objc/Podfile.mustache deleted file mode 100644 index c61ab59dd8f..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/Podfile.mustache +++ /dev/null @@ -1,5 +0,0 @@ -platform :ios, '6.0' -xcodeproj '{{projectName}}/{{projectName}}.xcodeproj' -pod 'AFNetworking', '~> 2.1' -pod 'JSONModel', '~> 1.0' -pod 'ISO8601' diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/api-body.mustache b/modules/swagger-codegen/src/main/resources/fotition-objc/api-body.mustache deleted file mode 100644 index b5e14d8adf3..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/api-body.mustache +++ /dev/null @@ -1,235 +0,0 @@ -{{#operations}} -#import "{{classname}}.h" -#import "FTFile.h" -#import "FTQueryParamCollection.h" -{{#imports}}#import "{{import}}.h" -{{/imports}} -{{newline}} - -@interface {{classname}} () - @property (readwrite, nonatomic, strong) NSMutableDictionary *defaultHeaders; -@end - -@implementation {{classname}} - -static NSString * basePath = @"{{basePath}}"; - -#pragma mark - Initialize methods - -- (id) init { - self = [super init]; - if (self) { - self.apiClient = [FotitionAPIClient sharedClientFromPool:basePath]; - self.defaultHeaders = [NSMutableDictionary dictionary]; - } - return self; -} - -- (id) initWithApiClient:(FotitionAPIClient *)apiClient { - self = [super init]; - if (self) { - if (apiClient) { - self.apiClient = apiClient; - } - else { - self.apiClient = [FotitionAPIClient sharedClientFromPool:basePath]; - } - self.defaultHeaders = [NSMutableDictionary dictionary]; - } - return self; -} - -#pragma mark - - -+({{classname}}*) apiWithHeader:(NSString*)headerValue key:(NSString*)key { - static {{classname}}* singletonAPI = nil; - - if (singletonAPI == nil) { - singletonAPI = [[{{classname}} alloc] init]; - [singletonAPI addHeader:headerValue forKey:key]; - } - return singletonAPI; -} - -+(void) setBasePath:(NSString*)path { - basePath = path; -} - -+(NSString*) getBasePath { - return basePath; -} - --(void) addHeader:(NSString*)value forKey:(NSString*)key { - [self.defaultHeaders setValue:value forKey:key]; -} - --(void) setHeaderValue:(NSString*) value - forKey:(NSString*)key { - [self.defaultHeaders setValue:value forKey:key]; -} - --(unsigned long) requestQueueSize { - return [FotitionAPIClient requestQueueSize]; -} - - -{{#operation}} -/*! - * {{{summary}}} - * {{{notes}}} -{{#allParams}} * \param {{paramName}} {{{description}}} -{{/allParams}} * \returns {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} - */ --(NSNumber*) {{nickname}}WithCompletionBlock{{^allParams}}: {{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}} - {{/allParams}} - {{#returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)(NSDictionary *responseHeaders, {{{returnType}}} output, NSError* error))completionBlock{{/returnBaseType}} - {{^returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)(NSDictionary *responseHeaders, NSError* error))completionBlock{{/returnBaseType}} { - - {{#allParams}}{{#required}} - // verify the required parameter '{{paramName}}' is set - NSAssert({{paramName}} != nil, @"Missing the required parameter `{{paramName}}` when calling {{nickname}}"); - {{/required}}{{/allParams}} - - NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@{{path}}", basePath]; - - // remove format in URL if needed - if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) - [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; - - {{#pathParams}}[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"{{baseName}}", @"}"]] withString: [FotitionAPIClient escape:{{paramName}}]]; - {{/pathParams}} - - NSMutableDictionary* queryParams __attribute__((unused)) = [[NSMutableDictionary alloc] init]; - {{#queryParams}}if({{paramName}} != nil) { - {{#collectionFormat}} - queryParams[@"{{baseName}}"] = [[FTQueryParamCollection alloc] initWithValuesAndFormat: {{baseName}} format: @"{{collectionFormat}}"]; - {{/collectionFormat}} - {{^collectionFormat}}queryParams[@"{{baseName}}"] = {{paramName}};{{/collectionFormat}} - } - {{/queryParams}} - NSMutableDictionary* headerParams __attribute__((unused)) = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; - - {{#headerParams}}if({{paramName}} != nil) - headerParams[@"{{baseName}}"] = {{paramName}}; - {{/headerParams}} - - // HTTP header `Accept` - headerParams[@"Accept"] = [FotitionAPIClient selectHeaderAccept:@[{{#produces}}@"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}]]; - if ([headerParams[@"Accept"] length] == 0) { - [headerParams removeObjectForKey:@"Accept"]; - } - - // response content type - NSString *responseContentType; - if ([headerParams objectForKey:@"Accept"]) { - responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; - } - else { - responseContentType = @""; - } - - // request content type - NSString *requestContentType = [FotitionAPIClient selectHeaderContentType:@[{{#consumes}}@"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}]]; - - // Authentication setting - NSArray *authSettings = @[{{#authMethods}}@"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}}]; - - id bodyDictionary = nil; - {{#bodyParam}} - id __body = {{paramName}}; - - if(__body != nil && [__body isKindOfClass:[NSArray class]]){ - NSMutableArray * objs = [[NSMutableArray alloc] init]; - for (id dict in (NSArray*)__body) { - if([dict respondsToSelector:@selector(toDictionary)]) { - [objs addObject:[(FTObject*)dict toDictionary]]; - } - else{ - [objs addObject:dict]; - } - } - bodyDictionary = objs; - } - else if([__body respondsToSelector:@selector(toDictionary)]) { - bodyDictionary = [(FTObject*)__body toDictionary]; - } - else if([__body isKindOfClass:[NSString class]]) { - // convert it to a dictionary - NSError * error; - NSString * str = (NSString*)__body; - NSDictionary *JSON = - [NSJSONSerialization JSONObjectWithData: [str dataUsingEncoding: NSUTF8StringEncoding] - options: NSJSONReadingMutableContainers - error: &error]; - bodyDictionary = JSON; - } - {{/bodyParam}} - {{^bodyParam}} - - NSMutableDictionary * formParams __attribute__((unused)) = [[NSMutableDictionary alloc]init]; - - if(bodyDictionary == nil) { - bodyDictionary = [[NSMutableArray alloc] init]; - } - {{#formParams}} - {{#notFile}} - if ([{{paramName}} isKindOfClass:[NSNumber class]]){ - NSNumber *num = (NSNumber *){{paramName}}; - formParams[@"{{paramName}}"] = [num stringValue]; - }else{ - formParams[@"{{paramName}}"] = {{paramName}}; - } - - - {{/notFile}}{{#isFile}} - requestContentType = @"multipart/form-data"; - - if({{paramName}} != nil) { - [bodyDictionary addObject:{{paramName}}]; - {{paramName}}.paramName = @"{{baseName}}"; - } - {{/isFile}} - {{/formParams}} - - [bodyDictionary addObject:formParams]; - - {{/bodyParam}} - - {{#requiredParamCount}} - {{#requiredParams}} - if({{paramName}} == nil) { - // error - } - {{/requiredParams}} - {{/requiredParamCount}} - - {{#returnContainer}} - // response is in a container - {{>apiBodyResponseWithContainer}}{{/returnContainer}} - - {{#returnSimpleType}} - // non container response - - {{#returnTypeIsPrimitive}} - // primitive response - {{>apiPrimitiveResponse}}{{/returnTypeIsPrimitive}} - - {{#returnBaseType}} - // complex response - {{>apiNonPrimitiveResponse}}{{/returnBaseType}} - {{/returnSimpleType}} - - {{^returnSimpleType}}{{^returnContainer}} - // it's void - {{>voidResponse}} - {{/returnContainer}}{{/returnSimpleType}} -} - -{{/operation}} - -{{newline}} -{{/operations}} -@end - - - diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/api-header.mustache b/modules/swagger-codegen/src/main/resources/fotition-objc/api-header.mustache deleted file mode 100644 index 86ad2c60167..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/api-header.mustache +++ /dev/null @@ -1,41 +0,0 @@ -#import -{{#imports}}#import "{{import}}.h" -{{/imports}} -#import "FTObject.h" -#import "FotitionAPIClient.h" -{{newline}} - -{{#operations}} -@interface {{classname}}: NSObject - -@property(nonatomic, assign)FotitionAPIClient *apiClient; - --(instancetype) initWithApiClient:(FotitionAPIClient *)apiClient; --(void) addHeader:(NSString*)value forKey:(NSString*)key; --(unsigned long) requestQueueSize; -+({{classname}}*) apiWithHeader:(NSString*)headerValue key:(NSString*)key; -+(void) setBasePath:(NSString*)basePath; -+(NSString*) getBasePath; -{{#operation}} -/** - - {{{summary}}} - {{#notes}}{{{notes}}}{{/notes}} - - {{#allParams}}@param {{paramName}} {{description}} - {{/allParams}} - - return type: {{{returnType}}} - */ --(NSNumber*) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}} {{#hasMore}} -{{/hasMore}}{{/allParams}} - {{#returnBaseType}}{{#hasParams}} - completionHandler: {{/hasParams}}(void (^)(NSDictionary *responseHeaders, {{{returnType}}} output, NSError* error))completionBlock;{{/returnBaseType}} - {{^returnBaseType}}{{#hasParams}} - completionHandler: {{/hasParams}}(void (^)(NSDictionary *responseHeaders, NSError* error))completionBlock;{{/returnBaseType}} - -{{newline}} -{{/operation}} - -{{/operations}} -@end diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/apiBodyResponseWithContainer.mustache b/modules/swagger-codegen/src/main/resources/fotition-objc/apiBodyResponseWithContainer.mustache deleted file mode 100644 index 9deba39e35a..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/apiBodyResponseWithContainer.mustache +++ /dev/null @@ -1,38 +0,0 @@ - // {{returnContainer}} container response type - return [self.apiClient dictionary: requestUrl - method: @"{{httpMethod}}" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSDictionary *responseHeaders, NSDictionary *data, NSError *error) { - if (error) { - {{#returnBaseType}}completionBlock(responseHeaders, nil, error);{{/returnBaseType}}{{^returnBaseType}}completionBlock(responseHeaders, error);{{/returnBaseType}} - return; - } - {{#isMapContainer}} - NSDictionary *result = nil; - if (data) { - result = [[NSDictionary alloc]initWithDictionary: data]; - } - completionBlock(data, nil); - {{/isMapContainer}}{{#isListContainer}} - {{#returnBaseType}}if([data isKindOfClass:[NSArray class]]){ - NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]]; - for (NSDictionary* dict in (NSArray*)data) { - {{#returnTypeIsPrimitive}} - {{returnBaseType}}* d = [[{{{returnBaseType}}} alloc]initWithString: dict]; - {{/returnTypeIsPrimitive}} - {{^returnTypeIsPrimitive}} - {{{returnBaseType}}}* d = [[{{{returnBaseType}}} alloc] initWithDictionary:dict error:nil]; - {{/returnTypeIsPrimitive}} - [objs addObject:d]; - } - completionBlock(responseHeaders, ({{{returnType}}})objs, nil); - } - {{/returnBaseType}} - {{/isListContainer}} - }]; - diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/apiNonPrimitiveResponse.mustache b/modules/swagger-codegen/src/main/resources/fotition-objc/apiNonPrimitiveResponse.mustache deleted file mode 100644 index 47b6d614346..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/apiNonPrimitiveResponse.mustache +++ /dev/null @@ -1,24 +0,0 @@ - {{^returnTypeIsPrimitive}} - // comples response type - return [self.apiClient dictionary: requestUrl - method: @"{{httpMethod}}" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSDictionary *responseHeaders, NSDictionary *data, NSError *error) { - if (error) { - {{#returnBaseType}}completionBlock(responseHeaders, nil, error);{{/returnBaseType}} - {{^returnBaseType}}completionBlock(responseHeaders, error);{{/returnBaseType}} - return; - } - {{#returnType}}{{returnType}} result = nil; - if (data) { - result = [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc] {{#returnContainer}}{{#isMapContainer}}initWithDictionary{{/isMapContainer}}{{#isListContainer}} initWithDictionary{{/isListContainer}}{{/returnContainer}}{{^returnContainer}} initWithDictionary{{/returnContainer}}:data error:nil]; - } - {{#returnType}}completionBlock(responseHeaders, result , nil);{{/returnType}} - {{/returnType}} - }]; - {{/returnTypeIsPrimitive}} diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/apiPrimitiveResponse.mustache b/modules/swagger-codegen/src/main/resources/fotition-objc/apiPrimitiveResponse.mustache deleted file mode 100644 index a04f2a86656..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/apiPrimitiveResponse.mustache +++ /dev/null @@ -1,36 +0,0 @@ - // primitive response type - {{#returnBaseType}}return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"{{httpMethod}}" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSDictionary *responseHeaders, NSString *data, NSError *error) { - if (error) { - completionBlock(responseHeaders, nil, error); - return; - } - {{returnBaseType}} *result = data ? [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc]initWithString: data] : nil; - completionBlock(responseHeaders, result, nil); - }]; - {{/returnBaseType}} - {{^returnBaseType}} - // no return base type - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"{{httpMethod}}" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSDictionary *responseHeaders, NSString *data, NSError *error) { - if (error) { - completionBlock(responseHeaders, error); - return; - } - completionBlock(responseHeaders, nil); - }]; - {{/returnBaseType}} - diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/model-body.mustache b/modules/swagger-codegen/src/main/resources/fotition-objc/model-body.mustache deleted file mode 100644 index b728e6bb06c..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/model-body.mustache +++ /dev/null @@ -1,26 +0,0 @@ -{{#models}} -{{#model}} -#import "{{classname}}.h" - -@implementation {{classname}} - -+ (JSONKeyMapper *)keyMapper -{ - return [[JSONKeyMapper alloc] initWithDictionary:@{ {{#vars}}@"{{baseName}}": @"{{name}}"{{#hasMore}}, {{/hasMore}}{{/vars}} }]; -} - -+ (BOOL)propertyIsOptional:(NSString *)propertyName -{ - NSArray *optionalProperties = @[{{#vars}}{{^required}}@"{{name}}"{{#hasMore}}, {{/hasMore}}{{/required}}{{/vars}}]; - - if ([optionalProperties containsObject:propertyName]) { - return YES; - } - else { - return NO; - } -} - -{{/model}} -@end -{{/models}} diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/model-header.mustache b/modules/swagger-codegen/src/main/resources/fotition-objc/model-header.mustache deleted file mode 100644 index a899dcdd461..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/model-header.mustache +++ /dev/null @@ -1,22 +0,0 @@ -#import -#import "FTObject.h" -{{#imports}}#import "{{import}}.h" -{{/imports}} -{{newline}} -{{#models}} -{{#model}} - -@protocol {{classname}} -@end - -@interface {{classname}} : FTObject - -{{#vars}} -{{#description}}/* {{{description}}} {{^required}}[optional]{{/required}} - */{{/description}} -@property(nonatomic) {{{ datatype }}} {{name}}; -{{/vars}} - -@end -{{/model}} -{{/models}} diff --git a/modules/swagger-codegen/src/main/resources/fotition-objc/voidResponse.mustache b/modules/swagger-codegen/src/main/resources/fotition-objc/voidResponse.mustache deleted file mode 100644 index 4fdc7c190e8..00000000000 --- a/modules/swagger-codegen/src/main/resources/fotition-objc/voidResponse.mustache +++ /dev/null @@ -1,16 +0,0 @@ - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"{{httpMethod}}" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSDictionary *responseHeaders, NSString *data, NSError *error) { - if (error) { - // no data to return - completionBlock(responseHeaders, error); - return; - } - completionBlock(responseHeaders, nil); - }]; diff --git a/modules/swagger-codegen/src/main/resources/objc/ApiClient-body.mustache b/modules/swagger-codegen/src/main/resources/objc/ApiClient-body.mustache index b7643de6ddd..1dce31e43f1 100644 --- a/modules/swagger-codegen/src/main/resources/objc/ApiClient-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/ApiClient-body.mustache @@ -378,14 +378,17 @@ static void (^reachabilityChangeBlock)(int); - (void) operationWithCompletionBlock: (NSURLRequest *)request requestId: (NSNumber *) requestId - completionBlock: (void (^)(id, NSError *))completionBlock { + completionBlock: (void (^)(NSDictionary *, id, NSError *))completionBlock { AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id response) { if([self executeRequestWithId:requestId]) { if([[{{classPrefix}}Configuration sharedConfig] debug]) { [self logResponse:operation forRequest:request error:nil]; } - completionBlock(response, nil); + + NSDictionary *responseHeaders = [[operation response] allHeaderFields]; + + completionBlock(responseHeaders, response, nil); } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { if([self executeRequestWithId:requestId]) { @@ -398,7 +401,10 @@ static void (^reachabilityChangeBlock)(int); if([[{{classPrefix}}Configuration sharedConfig] debug]) [self logResponse:nil forRequest:request error:augmentedError]; - completionBlock(nil, augmentedError); + + NSDictionary *responseHeaders = [[operation response] allHeaderFields]; + + completionBlock(responseHeaders, nil, augmentedError); } }]; @@ -407,7 +413,7 @@ static void (^reachabilityChangeBlock)(int); - (void) downloadOperationWithCompletionBlock: (NSURLRequest *)request requestId: (NSNumber *) requestId - completionBlock: (void (^)(id, NSError *))completionBlock { + completionBlock: (void (^)(NSDictionary *, id, NSError *))completionBlock { AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) { {{classPrefix}}Configuration *config = [{{classPrefix}}Configuration sharedConfig]; @@ -441,7 +447,8 @@ static void (^reachabilityChangeBlock)(int); NSURL *file = [NSURL fileURLWithPath:filepath]; [operation.responseData writeToURL:file atomically:YES]; - completionBlock(file, nil); + NSDictionary *responseHeaders = [[operation response] allHeaderFields]; + completionBlock(responseHeaders, file, nil); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { if ([self executeRequestWithId:requestId]) { @@ -455,8 +462,8 @@ static void (^reachabilityChangeBlock)(int); if ([[{{classPrefix}}Configuration sharedConfig] debug]) { [self logResponse:nil forRequest:request error:augmentedError]; } - - completionBlock(nil, augmentedError); + NSDictionary *responseHeaders = [[operation response] allHeaderFields]; + completionBlock(responseHeaders, nil, augmentedError); } }]; @@ -477,7 +484,7 @@ static void (^reachabilityChangeBlock)(int); requestContentType: (NSString*) requestContentType responseContentType: (NSString*) responseContentType responseType: (NSString *) responseType - completionBlock: (void (^)(id, NSError *))completionBlock { + completionBlock: (void (^)(NSDictionary *, id, NSError *))completionBlock { // setting request serializer if ([requestContentType isEqualToString:@"application/json"]) { self.requestSerializer = [{{classPrefix}}JSONRequestSerializer serializer]; @@ -513,7 +520,7 @@ static void (^reachabilityChangeBlock)(int); NSMutableString *resourcePath = [NSMutableString stringWithString:path]; [pathParams enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { [resourcePath replaceCharactersInRange:[resourcePath rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", key, @"}"]] - withString:[SWGApiClient escape:obj]]; + withString:[{{classPrefix}}ApiClient escape:obj]]; }]; NSMutableURLRequest * request = nil; @@ -585,13 +592,13 @@ static void (^reachabilityChangeBlock)(int); NSNumber* requestId = [{{classPrefix}}ApiClient queueRequest]; if ([responseType isEqualToString:@"NSURL*"]) { - [self downloadOperationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) { - completionBlock(data, error); + [self downloadOperationWithCompletionBlock:request requestId:requestId completionBlock:^(NSDictionary *responseHeaders, id data, NSError *error) { + completionBlock(responseHeaders, data, error); }]; } else { - [self operationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) { - completionBlock([self deserialize:data class:responseType], error); + [self operationWithCompletionBlock:request requestId:requestId completionBlock:^(NSDictionary *responseHeaders, id data, NSError *error) { + completionBlock(responseHeaders, [self deserialize:data class:responseType], error); }]; } return requestId; @@ -690,7 +697,7 @@ static void (^reachabilityChangeBlock)(int); if (object == nil) { return nil; } - else if ([object isKindOfClass:[NSString class]] || [object isKindOfClass:[NSNumber class]] || [object isKindOfClass:[SWGQueryParamCollection class]]) { + else if ([object isKindOfClass:[NSString class]] || [object isKindOfClass:[NSNumber class]] || [object isKindOfClass:[{{classPrefix}}QueryParamCollection class]]) { return object; } else if ([object isKindOfClass:[NSDate class]]) { @@ -714,7 +721,7 @@ static void (^reachabilityChangeBlock)(int); }]; return sanitizedObjs; } - else if ([object isKindOfClass:[SWGObject class]]) { + else if ([object isKindOfClass:[{{classPrefix}}Object class]]) { return [object toDictionary]; } else { diff --git a/modules/swagger-codegen/src/main/resources/objc/ApiClient-header.mustache b/modules/swagger-codegen/src/main/resources/objc/ApiClient-header.mustache index eba62705879..24f280fa195 100644 --- a/modules/swagger-codegen/src/main/resources/objc/ApiClient-header.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/ApiClient-header.mustache @@ -191,7 +191,7 @@ extern NSString *const {{classPrefix}}ResponseObjectErrorKey; requestContentType:(NSString*) requestContentType responseContentType:(NSString*) responseContentType responseType:(NSString *) responseType - completionBlock:(void (^)(id, NSError *))completionBlock; + completionBlock:(void (^)(NSDictionary *, id, NSError *))completionBlock; /** * Sanitize object for request diff --git a/modules/swagger-codegen/src/main/resources/objc/Object-body.mustache b/modules/swagger-codegen/src/main/resources/objc/Object-body.mustache index 122484f1ad4..6944765b1ca 100644 --- a/modules/swagger-codegen/src/main/resources/objc/Object-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/Object-body.mustache @@ -1,4 +1,17 @@ #import "{{classPrefix}}Object.h" @implementation {{classPrefix}}Object + +-(BOOL)isEqual:(id)object +{ + if (![object isMemberOfClass:[self class]]){ + return NO; + } + if ([object respondsToSelector:@selector(toDictionary)]) { + return [[self toDictionary] isEqualToDictionary:[object toDictionary]]; + }else{ + return [super isEqual:object]; + } +} + @end diff --git a/modules/swagger-codegen/src/main/resources/objc/api-body.mustache b/modules/swagger-codegen/src/main/resources/objc/api-body.mustache index 534c887fe7b..e5d6e2cffb5 100644 --- a/modules/swagger-codegen/src/main/resources/objc/api-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/api-body.mustache @@ -11,6 +11,8 @@ @implementation {{classname}} +static {{classname}}* singletonAPI = nil; + #pragma mark - Initialize methods - (id) init { @@ -38,7 +40,6 @@ #pragma mark - +({{classname}}*) apiWithHeader:(NSString*)headerValue key:(NSString*)key { - static {{classname}}* singletonAPI = nil; if (singletonAPI == nil) { singletonAPI = [[{{classname}} alloc] init]; @@ -47,6 +48,15 @@ return singletonAPI; } ++({{classname}}*) sharedAPI { + + if (singletonAPI == nil) { + singletonAPI = [[{{classname}} alloc] init]; + } + return singletonAPI; +} + + -(void) addHeader:(NSString*)value forKey:(NSString*)key { [self.defaultHeaders setValue:value forKey:key]; } @@ -72,8 +82,8 @@ /// -(NSNumber*) {{nickname}}WithCompletionBlock{{^allParams}}: {{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}} {{/allParams}} - {{#returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{{returnType}}} output, NSError* error))completionBlock { {{/returnBaseType}} - {{^returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)(NSError* error))completionBlock { {{/returnBaseType}} + {{#returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)(NSDictionary *responseHeaders, {{{returnType}}} output, NSError* error))completionBlock { {{/returnBaseType}} + {{^returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)(NSDictionary *responseHeaders, NSError* error))completionBlock { {{/returnBaseType}} {{#allParams}}{{#required}} // verify the required parameter '{{paramName}}' is set @@ -139,7 +149,11 @@ {{#formParams}} {{#notFile}} if ({{paramName}}) { - formParams[@"{{baseName}}"] = {{paramName}}; + if ([{{paramName}} isKindOfClass:[NSNumber class]]){ + formParams[@"{{baseName}}"] = [((NSNumber *){{paramName}}) stringValue]; + }else{ + formParams[@"{{baseName}}"] = {{paramName}}; + } } {{/notFile}}{{#isFile}} files[@"{{paramName}}"] = {{paramName}}; @@ -166,9 +180,9 @@ requestContentType: requestContentType responseContentType: responseContentType responseType: {{^returnType}}nil{{/returnType}}{{#returnType}}@"{{{ returnType }}}"{{/returnType}} - completionBlock: ^(id data, NSError *error) { - {{^returnType}}completionBlock(error);{{/returnType}} - {{#returnType}}completionBlock(({{{ returnType }}})data, error);{{/returnType}} + completionBlock: ^(NSDictionary *responseHeaders, id data, NSError *error) { + {{^returnType}}completionBlock(responseHeaders, error);{{/returnType}} + {{#returnType}}completionBlock(responseHeaders, ({{{ returnType }}})data, error);{{/returnType}} } ]; } diff --git a/modules/swagger-codegen/src/main/resources/objc/api-header.mustache b/modules/swagger-codegen/src/main/resources/objc/api-header.mustache index d9f691f7227..d001495f507 100644 --- a/modules/swagger-codegen/src/main/resources/objc/api-header.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/api-header.mustache @@ -20,6 +20,7 @@ -(void) addHeader:(NSString*)value forKey:(NSString*)key; -(unsigned long) requestQueueSize; +({{classname}}*) apiWithHeader:(NSString*)headerValue key:(NSString*)key; ++({{classname}}*) sharedAPI; {{#operation}} /// /// @@ -33,9 +34,9 @@ -(NSNumber*) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}} {{#hasMore}} {{/hasMore}}{{/allParams}} {{#returnBaseType}}{{#hasParams}} - completionHandler: {{/hasParams}}(void (^)({{{returnType}}} output, NSError* error))completionBlock;{{/returnBaseType}} + completionHandler: {{/hasParams}}(void (^)(NSDictionary *responseHeaders, {{{returnType}}} output, NSError* error))completionBlock;{{/returnBaseType}} {{^returnBaseType}}{{#hasParams}} - completionHandler: {{/hasParams}}(void (^)(NSError* error))completionBlock;{{/returnBaseType}} + completionHandler: {{/hasParams}}(void (^)(NSDictionary *responseHeaders, NSError* error))completionBlock;{{/returnBaseType}} {{newline}} {{/operation}} diff --git a/modules/swagger-codegen/src/main/resources/objc/podspec.mustache b/modules/swagger-codegen/src/main/resources/objc/podspec.mustache index 9ce03695bcf..af6be552c6d 100644 --- a/modules/swagger-codegen/src/main/resources/objc/podspec.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/podspec.mustache @@ -20,6 +20,12 @@ Pod::Spec.new do |s| s.requires_arc = true s.framework = 'SystemConfiguration' + s.homepage = "{{gitRepoURL}}" + s.license = "{{license}}" + + s.source = { :git => "{{gitRepoURL}}.git", :tag => "#{s.version}" } + + s.author = { "{{authorName}}" => "{{authorEmail}}" } s.source_files = '{{podName}}/**/*' s.public_header_files = '{{podName}}/**/*.h'