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 76739f5ab3..3351007386 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 @@ -84,6 +84,9 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { typeMapping.put("List", "NSArray"); typeMapping.put("object", "NSObject"); typeMapping.put("file", "NSURL"); + //TODO binary should be mapped to byte array + // mapped to String as a workaround + typeMapping.put("binary", "NSString"); // ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm diff --git a/pom.xml b/pom.xml index 17ad062e4f..3519ce9f0c 100644 --- a/pom.xml +++ b/pom.xml @@ -399,7 +399,19 @@ - samples/client/petstore/objc + samples/client/petstore/objc/SwaggerClientTests + + + + swift-client + + + env + swift + + + + samples/client/petstore/swift/SwaggerClientTests @@ -459,9 +471,10 @@ samples/client/petstore/javascript samples/client/petstore/scala samples/server/petstore/spring-mvc - samples/client/petstore/ruby samples/server/petstore/jaxrs + + diff --git a/samples/client/petstore/csharp/SwaggerClientTest/mono-nunit.sh b/samples/client/petstore/csharp/SwaggerClientTest/mono-nunit.sh new file mode 100755 index 0000000000..c14e76dad0 --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientTest/mono-nunit.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +wget -nc https://nuget.org/nuget.exe; +mozroots --import --sync + +# remove bin/Debug/SwaggerClientTest.dll +rm bin/Debug/SwaggerClientTest.dll 2> /dev/null + +# install NUnit runners via NuGet +mono nuget.exe install NUnit.Runners -Version 2.6.4 -OutputDirectory testrunner + +# build the solution and run the unit test +xbuild SwaggerClientTest.sln && \ +mono ./testrunner/NUnit.Runners.2.6.4/tools/nunit-console.exe bin/Debug/SwaggerClientTest.dll + diff --git a/samples/client/petstore/csharp/SwaggerClientTest/pom.xml b/samples/client/petstore/csharp/SwaggerClientTest/pom.xml new file mode 100644 index 0000000000..46304c2162 --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientTest/pom.xml @@ -0,0 +1,56 @@ + + 4.0.0 + com.wordnik + CsharpPetstoreClientTests + pom + 1.0-SNAPSHOT + C# Swagger Petstore Client + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory} + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + + mono-test + integration-test + + exec + + + mono-nunit.sh + + + + + + + diff --git a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.h b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.h index 7ea1821e57..8450740ce3 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.h @@ -149,5 +149,35 @@ completionHandler: (void (^)(NSError* error))completionBlock; +/// +/// +/// Fake endpoint to test byte array return by 'Find pet by ID' +/// Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions +/// +/// @param petId ID of pet that needs to be fetched +/// +/// +/// @return NSString* +-(NSNumber*) getPetByIdWithByteArrayWithCompletionBlock :(NSNumber*) petId + + completionHandler: (void (^)(NSString* output, NSError* error))completionBlock; + + + +/// +/// +/// Fake endpoint to test byte array in body parameter for adding a new pet to the store +/// +/// +/// @param body Pet object in the form of byte array +/// +/// +/// @return +-(NSNumber*) addPetUsingByteArrayWithCompletionBlock :(NSString*) body + + + completionHandler: (void (^)(NSError* error))completionBlock; + + @end diff --git a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m index c7c2ed175c..d3b76c0a4f 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m @@ -758,6 +758,170 @@ static SWGPetApi* singletonAPI = nil; + return [self.apiClient requestWithCompletionBlock: resourcePath + method: @"POST" + pathParams: pathParams + queryParams: queryParams + formParams: formParams + files: files + body: bodyParam + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + responseType: nil + completionBlock: ^(id data, NSError *error) { + completionBlock(error); + + } + ]; +} + +/// +/// Fake endpoint to test byte array return by 'Find pet by ID' +/// Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions +/// @param petId ID of pet that needs to be fetched +/// +/// @returns NSString* +/// +-(NSNumber*) getPetByIdWithByteArrayWithCompletionBlock: (NSNumber*) petId + + completionHandler: (void (^)(NSString* output, NSError* error))completionBlock { + + + + // verify the required parameter 'petId' is set + if (petId == nil) { + [NSException raise:@"Invalid parameter" format:@"Missing the required parameter `petId` when calling `getPetByIdWithByteArray`"]; + } + + + NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet/{petId}?testing_byte_array=true"]; + + // remove format in URL if needed + if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) { + [resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"]; + } + + NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init]; + if (petId != nil) { + pathParams[@"petId"] = petId; + } + + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + + NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + + + // HTTP header `Accept` + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + 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 = [SWGApiClient selectHeaderContentType:@[]]; + + // Authentication setting + NSArray *authSettings = @[@"api_key"]; + + id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; + + + + + + return [self.apiClient requestWithCompletionBlock: resourcePath + method: @"GET" + pathParams: pathParams + queryParams: queryParams + formParams: formParams + files: files + body: bodyParam + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + responseType: @"NSString*" + completionBlock: ^(id data, NSError *error) { + + completionBlock((NSString*)data, error); + } + ]; +} + +/// +/// Fake endpoint to test byte array in body parameter for adding a new pet to the store +/// +/// @param body Pet object in the form of byte array +/// +/// @returns void +/// +-(NSNumber*) addPetUsingByteArrayWithCompletionBlock: (NSString*) body + + + completionHandler: (void (^)(NSError* error))completionBlock { + + + + NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet?testing_byte_array=true"]; + + // remove format in URL if needed + if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) { + [resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"]; + } + + NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init]; + + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + + NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + + + // HTTP header `Accept` + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + 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 = [SWGApiClient selectHeaderContentType:@[@"application/json", @"application/xml"]]; + + // Authentication setting + NSArray *authSettings = @[@"petstore_auth"]; + + id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; + + bodyParam = body; + + + return [self.apiClient requestWithCompletionBlock: resourcePath method: @"POST" pathParams: pathParams diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift index ea6c50e254..d0ea91c2dc 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift @@ -71,20 +71,20 @@ extension PetstoreClientAPI { - OAuth: - type: oauth2 - name: petstore_auth - - examples: [{contentType=application/json, example=[ { - "photoUrls" : [ "aeiou" ], - "name" : "doggie", + - examples: [{example=[ { + "tags" : [ { + "id" : 123456789, + "name" : "aeiou" + } ], "id" : 123456789, "category" : { - "name" : "aeiou", - "id" : 123456789 + "id" : 123456789, + "name" : "aeiou" }, - "tags" : [ { - "name" : "aeiou", - "id" : 123456789 - } ], - "status" : "aeiou" -} ]}, {contentType=application/xml, example= + "status" : "aeiou", + "name" : "doggie", + "photoUrls" : [ "aeiou" ] +} ], contentType=application/json}, {example= 123456 doggie @@ -93,21 +93,21 @@ extension PetstoreClientAPI { string -}] - - examples: [{contentType=application/json, example=[ { - "photoUrls" : [ "aeiou" ], - "name" : "doggie", +, contentType=application/xml}] + - examples: [{example=[ { + "tags" : [ { + "id" : 123456789, + "name" : "aeiou" + } ], "id" : 123456789, "category" : { - "name" : "aeiou", - "id" : 123456789 + "id" : 123456789, + "name" : "aeiou" }, - "tags" : [ { - "name" : "aeiou", - "id" : 123456789 - } ], - "status" : "aeiou" -} ]}, {contentType=application/xml, example= + "status" : "aeiou", + "name" : "doggie", + "photoUrls" : [ "aeiou" ] +} ], contentType=application/json}, {example= 123456 doggie @@ -116,7 +116,7 @@ extension PetstoreClientAPI { string -}] +, contentType=application/xml}] - parameter status: (query) Status values that need to be considered for filter @@ -145,20 +145,20 @@ extension PetstoreClientAPI { - OAuth: - type: oauth2 - name: petstore_auth - - examples: [{contentType=application/json, example=[ { - "photoUrls" : [ "aeiou" ], - "name" : "doggie", + - examples: [{example=[ { + "tags" : [ { + "id" : 123456789, + "name" : "aeiou" + } ], "id" : 123456789, "category" : { - "name" : "aeiou", - "id" : 123456789 + "id" : 123456789, + "name" : "aeiou" }, - "tags" : [ { - "name" : "aeiou", - "id" : 123456789 - } ], - "status" : "aeiou" -} ]}, {contentType=application/xml, example= + "status" : "aeiou", + "name" : "doggie", + "photoUrls" : [ "aeiou" ] +} ], contentType=application/json}, {example= 123456 doggie @@ -167,21 +167,21 @@ extension PetstoreClientAPI { string -}] - - examples: [{contentType=application/json, example=[ { - "photoUrls" : [ "aeiou" ], - "name" : "doggie", +, contentType=application/xml}] + - examples: [{example=[ { + "tags" : [ { + "id" : 123456789, + "name" : "aeiou" + } ], "id" : 123456789, "category" : { - "name" : "aeiou", - "id" : 123456789 + "id" : 123456789, + "name" : "aeiou" }, - "tags" : [ { - "name" : "aeiou", - "id" : 123456789 - } ], - "status" : "aeiou" -} ]}, {contentType=application/xml, example= + "status" : "aeiou", + "name" : "doggie", + "photoUrls" : [ "aeiou" ] +} ], contentType=application/json}, {example= 123456 doggie @@ -190,7 +190,7 @@ extension PetstoreClientAPI { string -}] +, contentType=application/xml}] - parameter tags: (query) Tags to filter by @@ -219,20 +219,20 @@ extension PetstoreClientAPI { - API Key: - type: apiKey api_key - name: api_key - - examples: [{contentType=application/json, example={ - "photoUrls" : [ "aeiou" ], - "name" : "doggie", + - examples: [{example={ + "tags" : [ { + "id" : 123456789, + "name" : "aeiou" + } ], "id" : 123456789, "category" : { - "name" : "aeiou", - "id" : 123456789 + "id" : 123456789, + "name" : "aeiou" }, - "tags" : [ { - "name" : "aeiou", - "id" : 123456789 - } ], - "status" : "aeiou" -}}, {contentType=application/xml, example= + "status" : "aeiou", + "name" : "doggie", + "photoUrls" : [ "aeiou" ] +}, contentType=application/json}, {example= 123456 doggie @@ -241,21 +241,21 @@ extension PetstoreClientAPI { string -}] - - examples: [{contentType=application/json, example={ - "photoUrls" : [ "aeiou" ], - "name" : "doggie", +, contentType=application/xml}] + - examples: [{example={ + "tags" : [ { + "id" : 123456789, + "name" : "aeiou" + } ], "id" : 123456789, "category" : { - "name" : "aeiou", - "id" : 123456789 + "id" : 123456789, + "name" : "aeiou" }, - "tags" : [ { - "name" : "aeiou", - "id" : 123456789 - } ], - "status" : "aeiou" -}}, {contentType=application/xml, example= + "status" : "aeiou", + "name" : "doggie", + "photoUrls" : [ "aeiou" ] +}, contentType=application/json}, {example= 123456 doggie @@ -264,7 +264,7 @@ extension PetstoreClientAPI { string -}] +, contentType=application/xml}] - parameter petId: (path) ID of pet that needs to be fetched @@ -374,5 +374,59 @@ extension PetstoreClientAPI { return requestBuilder.init(method: "POST", URLString: URLString, parameters: parameters, isBody: false) } + /** + + Fake endpoint to test byte array return by 'Find pet by ID' + + - GET /pet/{petId}?testing_byte_array=true + - Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + - API Key: + - type: apiKey api_key + - name: api_key + - examples: [{example="", contentType=application/json}, {example=not implemented io.swagger.models.properties.BinaryProperty@55e6ae9e, contentType=application/xml}] + - examples: [{example="", contentType=application/json}, {example=not implemented io.swagger.models.properties.BinaryProperty@55e6ae9e, contentType=application/xml}] + + - parameter petId: (path) ID of pet that needs to be fetched + + - returns: RequestBuilder + */ + public class func getPetByIdWithByteArray(petId petId: Int) -> RequestBuilder { + var path = "/pet/{petId}?testing_byte_array=true" + path = path.stringByReplacingOccurrencesOfString("{petId}", withString: "\(petId)", options: .LiteralSearch, range: nil) + let URLString = PetstoreClientAPI.basePath + path + + let nillableParameters: [String:AnyObject?] = [:] + let parameters = APIHelper.rejectNil(nillableParameters) + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "GET", URLString: URLString, parameters: parameters, isBody: true) + } + + /** + + Fake endpoint to test byte array in body parameter for adding a new pet to the store + + - POST /pet?testing_byte_array=true + - + - OAuth: + - type: oauth2 + - name: petstore_auth + + - parameter body: (body) Pet object in the form of byte array + + - returns: RequestBuilder + */ + public class func addPetUsingByteArray(body body: String?) -> RequestBuilder { + let path = "/pet?testing_byte_array=true" + let URLString = PetstoreClientAPI.basePath + path + + let parameters = body?.encodeToJSON() as? [String:AnyObject] + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "POST", URLString: URLString, parameters: parameters, isBody: true) + } + } } diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift index 0b81fea66d..23a33a0f28 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift @@ -21,12 +21,12 @@ extension PetstoreClientAPI { - API Key: - type: apiKey api_key - name: api_key - - examples: [{contentType=application/json, example={ + - examples: [{example={ "key" : 123 -}}, {contentType=application/xml, example=not implemented io.swagger.models.properties.MapProperty@d1e580af}] - - examples: [{contentType=application/json, example={ +}, contentType=application/json}, {example=not implemented io.swagger.models.properties.MapProperty@d1e580af, contentType=application/xml}] + - examples: [{example={ "key" : 123 -}}, {contentType=application/xml, example=not implemented io.swagger.models.properties.MapProperty@d1e580af}] +}, contentType=application/json}, {example=not implemented io.swagger.models.properties.MapProperty@d1e580af, contentType=application/xml}] - returns: RequestBuilder<[String:Int]> */ @@ -48,36 +48,36 @@ extension PetstoreClientAPI { - POST /store/order - - - examples: [{contentType=application/json, example={ - "petId" : 123456789, - "quantity" : 123, + - examples: [{example={ "id" : 123456789, - "shipDate" : "2016-02-07T13:55:23.709+0000", + "petId" : 123456789, "complete" : true, - "status" : "aeiou" -}}, {contentType=application/xml, example= + "status" : "aeiou", + "quantity" : 123, + "shipDate" : "2016-02-13T08:19:01.757+0000" +}, contentType=application/json}, {example= 123456 123456 0 - 2016-02-07T05:55:23.712Z + 2016-02-13T16:19:01.763Z string true -}] - - examples: [{contentType=application/json, example={ - "petId" : 123456789, - "quantity" : 123, +, contentType=application/xml}] + - examples: [{example={ "id" : 123456789, - "shipDate" : "2016-02-07T13:55:23.709+0000", + "petId" : 123456789, "complete" : true, - "status" : "aeiou" -}}, {contentType=application/xml, example= + "status" : "aeiou", + "quantity" : 123, + "shipDate" : "2016-02-13T08:19:01.757+0000" +}, contentType=application/json}, {example= 123456 123456 0 - 2016-02-07T05:55:23.712Z + 2016-02-13T16:19:01.763Z string true -}] +, contentType=application/xml}] - parameter body: (body) order placed for purchasing the pet @@ -100,36 +100,36 @@ extension PetstoreClientAPI { - GET /store/order/{orderId} - For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - - examples: [{contentType=application/json, example={ - "petId" : 123456789, - "quantity" : 123, + - examples: [{example={ "id" : 123456789, - "shipDate" : "2016-02-07T13:55:23.713+0000", + "petId" : 123456789, "complete" : true, - "status" : "aeiou" -}}, {contentType=application/xml, example= + "status" : "aeiou", + "quantity" : 123, + "shipDate" : "2016-02-13T08:19:01.765+0000" +}, contentType=application/json}, {example= 123456 123456 0 - 2016-02-07T05:55:23.713Z + 2016-02-13T16:19:01.766Z string true -}] - - examples: [{contentType=application/json, example={ - "petId" : 123456789, - "quantity" : 123, +, contentType=application/xml}] + - examples: [{example={ "id" : 123456789, - "shipDate" : "2016-02-07T13:55:23.713+0000", + "petId" : 123456789, "complete" : true, - "status" : "aeiou" -}}, {contentType=application/xml, example= + "status" : "aeiou", + "quantity" : 123, + "shipDate" : "2016-02-13T08:19:01.765+0000" +}, contentType=application/json}, {example= 123456 123456 0 - 2016-02-07T05:55:23.713Z + 2016-02-13T16:19:01.766Z string true -}] +, contentType=application/xml}] - parameter orderId: (path) ID of pet that needs to be fetched diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift index 231e7f5922..19cf534cea 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift @@ -84,8 +84,8 @@ extension PetstoreClientAPI { - GET /user/login - - - examples: [{contentType=application/json, example="aeiou"}, {contentType=application/xml, example=string}] - - examples: [{contentType=application/json, example="aeiou"}, {contentType=application/xml, example=string}] + - examples: [{example="aeiou", contentType=application/json}, {example=string, contentType=application/xml}] + - examples: [{example="aeiou", contentType=application/json}, {example=string, contentType=application/xml}] - parameter username: (query) The user name for login - parameter password: (query) The password for login in clear text @@ -134,7 +134,7 @@ extension PetstoreClientAPI { - GET /user/{username} - - - examples: [{contentType=application/json, example={ + - examples: [{example={ "id" : 1, "username" : "johnp", "firstName" : "John", @@ -143,7 +143,7 @@ extension PetstoreClientAPI { "password" : "-secret-", "phone" : "0123456789", "userStatus" : 0 -}}] +}, contentType=application/json}] - parameter username: (path) The name that needs to be fetched. Use user1 for testing. diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models.swift index fd79652c61..04c07fa97f 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models.swift @@ -109,13 +109,19 @@ class Decoders { } // Decoder for NSDate Decoders.addDecoder(clazz: NSDate.self) { (source: AnyObject) -> NSDate in - let sourceString = source as! String - for formatter in formatters { - if let date = formatter.dateFromString(sourceString) { - return date + if let sourceString = source as? String { + for formatter in formatters { + if let date = formatter.dateFromString(sourceString) { + return date + } } + } - fatalError("formatter failed to parse \(sourceString)") + if let sourceInt = source as? Int { + // treat as a java date + return NSDate(timeIntervalSince1970: Double(sourceInt / 1000) ) + } + fatalError("formatter failed to parse \(source)") } // Decoder for [User]