From a6bdc35d59b0692352f6465a4f483c0f182cc0e8 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Sat, 13 Jun 2015 10:17:08 +0800 Subject: [PATCH] Support pure object response for objc client --- .../src/main/resources/objc/SWGApiClient-body.mustache | 5 +++++ .../objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m | 2 +- .../objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m | 5 +++++ samples/client/petstore/objc/client/SWGApiClient.m | 5 +++++ samples/client/petstore/objc/client/SWGStoreApi.m | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache index 45c6fc6d305..a0c9c63d27c 100644 --- a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache @@ -364,6 +364,11 @@ static bool loggingEnabled = true; class = [class substringToIndex:[class length] - 1]; } + // pure object + if ([class isEqualToString:@"NSObject"]) { + return [[NSObject alloc] init]; + } + // list of models NSString *arrayOfModelsPat = @"NSArray<(.+)>"; regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfModelsPat diff --git a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m index 5440935be1b..8ea2e7ee0fc 100644 --- a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m +++ b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m @@ -32,7 +32,7 @@ XCTFail(@"failed to fetch inventory"); } - NSSet *expectKeys = [NSSet setWithArray:@[@"confused", @"string", @"pending", @"available", @"sold"]]; + NSSet *expectKeys = [NSSet setWithArray:@[@"confused", @"string", @"available"]]; NSSet *keys = [NSSet setWithArray:[output allKeys]]; XCTAssertEqualObjects(expectKeys, keys); diff --git a/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m b/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m index 1bd0c0eb1c3..597cf2fb714 100644 --- a/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m +++ b/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m @@ -158,6 +158,11 @@ XCTAssertTrue([result isKindOfClass:[NSDictionary class]]); XCTAssertTrue([result[@"pet"] isKindOfClass:[SWGPet class]]); XCTAssertEqualObjects([result[@"pet"] _id], @119); + + // pure object + result = [self.apiClient deserialize:nil class:@"NSObject*"]; + + XCTAssertTrue([result isKindOfClass:[NSObject class]]); } @end diff --git a/samples/client/petstore/objc/client/SWGApiClient.m b/samples/client/petstore/objc/client/SWGApiClient.m index 45c6fc6d305..a0c9c63d27c 100644 --- a/samples/client/petstore/objc/client/SWGApiClient.m +++ b/samples/client/petstore/objc/client/SWGApiClient.m @@ -364,6 +364,11 @@ static bool loggingEnabled = true; class = [class substringToIndex:[class length] - 1]; } + // pure object + if ([class isEqualToString:@"NSObject"]) { + return [[NSObject alloc] init]; + } + // list of models NSString *arrayOfModelsPat = @"NSArray<(.+)>"; regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfModelsPat diff --git a/samples/client/petstore/objc/client/SWGStoreApi.m b/samples/client/petstore/objc/client/SWGStoreApi.m index ce3a63c9483..2613f8b6caf 100644 --- a/samples/client/petstore/objc/client/SWGStoreApi.m +++ b/samples/client/petstore/objc/client/SWGStoreApi.m @@ -81,6 +81,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; { + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store/inventory", basePath]; // remove format in URL if needed