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 0ecdfb667c9..2029394bdbd 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 @@ -39,6 +39,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { protected String[] specialWords = {"new", "copy"}; protected String apiDocPath = "docs/"; protected String modelDocPath = "docs/"; + + protected Set advancedMapingTypes = new HashSet(); public ObjcClientCodegen() { super(); @@ -65,6 +67,16 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { defaultIncludes.add("NSDictionary"); defaultIncludes.add("NSMutableArray"); defaultIncludes.add("NSMutableDictionary"); + + advancedMapingTypes.add("NSDictionary"); + advancedMapingTypes.add("NSArray"); + advancedMapingTypes.add("NSMutableArray"); + advancedMapingTypes.add("NSMutableDictionary"); + advancedMapingTypes.add("NSObject"); + advancedMapingTypes.add("NSNumber"); + advancedMapingTypes.add("NSURL"); + advancedMapingTypes.add("NSString"); + advancedMapingTypes.add("NSDate"); languageSpecificPrimitives.clear(); languageSpecificPrimitives.add("NSNumber"); @@ -284,15 +296,20 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { if (innerTypeDeclaration.endsWith("*")) { innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1); } - + // In this codition, type of property p is array of primitive, - // return container type with pointer, e.g. `NSArray* /* NSString */' - if (languageSpecificPrimitives.contains(innerType)) { - return getSwaggerType(p) + "*" + " /* " + innerTypeDeclaration + " */"; + // return container type with pointer, e.g. `NSArray**' + if (languageSpecificPrimitives.contains(innerTypeDeclaration)) { + return getSwaggerType(p) + "<" + innerTypeDeclaration + "*>*"; } // In this codition, type of property p is array of model, // return container type combine inner type with pointer, e.g. `NSArray*' else { + for (String sd : advancedMapingTypes) { + if(innerTypeDeclaration.startsWith(sd)) { + return getSwaggerType(p) + "<" + innerTypeDeclaration + "*>*"; + } + } return getSwaggerType(p) + "<" + innerTypeDeclaration + ">*"; } } else if (p instanceof MapProperty) { @@ -300,11 +317,20 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { Property inner = mp.getAdditionalProperties(); String innerTypeDeclaration = getTypeDeclaration(inner); - + if (innerTypeDeclaration.endsWith("*")) { innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1); } - return getSwaggerType(p) + "* /* NSString, " + innerTypeDeclaration + " */"; + if (languageSpecificPrimitives.contains(innerTypeDeclaration)) { + return getSwaggerType(p) + "*"; + } else { + for (String s : advancedMapingTypes) { + if(innerTypeDeclaration.startsWith(s)) { + return getSwaggerType(p) + "*"; + } + } + return getSwaggerType(p) + "*"; + } } else { String swaggerType = getSwaggerType(p); 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 c7caa7ab11e..a9f20828acb 100644 --- a/modules/swagger-codegen/src/main/resources/objc/ApiClient-header.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/ApiClient-header.mustache @@ -28,7 +28,9 @@ extern NSString *const {{classPrefix}}ResponseObjectErrorKey; /** * Log debug message macro */ -#define {{classPrefix}}DebugLog(format, ...) [{{classPrefix}}ApiClient debugLog:[NSString stringWithFormat:@"%s", __PRETTY_FUNCTION__] message: format, ##__VA_ARGS__]; +#ifndef {{classPrefix}}DebugLog + #define {{classPrefix}}DebugLog(format, ...) [{{classPrefix}}ApiClient debugLog:[NSString stringWithFormat:@"%s", __PRETTY_FUNCTION__] message: format, ##__VA_ARGS__]; +#endif @interface {{classPrefix}}ApiClient : AFHTTPRequestOperationManager diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/objc/ObjcModelTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/objc/ObjcModelTest.java index fed94aa04f6..84fb38d1dd3 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/objc/ObjcModelTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/objc/ObjcModelTest.java @@ -27,6 +27,31 @@ import java.util.Map; @SuppressWarnings("static-method") public class ObjcModelTest { + @Test(description = "convert a model with a advanced map property") + public void advancedMapPropertyTest() { + final Model model = new ModelImpl() + .description("a sample model") + .property("translations", new MapProperty() + .additionalProperties(new MapProperty().additionalProperties(new StringProperty()))) + .required("id"); + final DefaultCodegen codegen = new ObjcClientCodegen(); + final CodegenModel cm = codegen.fromModel("sample", model); + + Assert.assertEquals(cm.name, "sample"); + Assert.assertEquals(cm.classname, "SWGSample"); + Assert.assertEquals(cm.description, "a sample model"); + Assert.assertEquals(cm.vars.size(), 1); + + final CodegenProperty property1 = cm.vars.get(0); + Assert.assertEquals(property1.baseName, "translations"); + Assert.assertEquals(property1.datatype, "NSDictionary*>*"); + Assert.assertEquals(property1.name, "translations"); + Assert.assertEquals(property1.baseType, "NSDictionary"); + Assert.assertEquals(property1.containerType, "map"); + Assert.assertNull(property1.required); + Assert.assertTrue(property1.isContainer); + } + @Test(description = "convert a simple java model") public void simpleModelTest() { final Model model = new ModelImpl() @@ -108,7 +133,7 @@ public class ObjcModelTest { final CodegenProperty property2 = cm.vars.get(1); Assert.assertEquals(property2.baseName, "urls"); - Assert.assertEquals(property2.datatype, "NSArray* /* NSString */"); + Assert.assertEquals(property2.datatype, "NSArray*"); Assert.assertEquals(property2.name, "urls"); Assert.assertNull(property2.defaultValue); Assert.assertEquals(property2.baseType, "NSArray"); @@ -136,7 +161,7 @@ public class ObjcModelTest { final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "translations"); - Assert.assertEquals(property1.datatype, "NSDictionary* /* NSString, NSString */"); + Assert.assertEquals(property1.datatype, "NSDictionary*"); Assert.assertEquals(property1.name, "translations"); Assert.assertEquals(property1.baseType, "NSDictionary"); Assert.assertEquals(property1.containerType, "map"); @@ -145,6 +170,7 @@ public class ObjcModelTest { Assert.assertTrue(property1.isPrimitiveType); } + @Test(description = "convert a model with complex property") public void complexPropertyTest() { final Model model = new ModelImpl() @@ -210,7 +236,7 @@ public class ObjcModelTest { final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "children"); Assert.assertEquals(property1.complexType, "SWGChildren"); - Assert.assertEquals(property1.datatype, "NSDictionary* /* NSString, SWGChildren */"); + Assert.assertEquals(property1.datatype, "NSDictionary*"); Assert.assertEquals(property1.name, "children"); Assert.assertEquals(property1.baseType, "NSDictionary"); Assert.assertEquals(property1.containerType, "map"); diff --git a/samples/client/petstore/objc/README.md b/samples/client/petstore/objc/README.md index a3550545c24..289ffd121c7 100644 --- a/samples/client/petstore/objc/README.md +++ b/samples/client/petstore/objc/README.md @@ -6,7 +6,7 @@ This ObjC package is automatically generated by the [Swagger Codegen](https://gi - API version: 1.0.0 - Package version: -- Build date: 2016-05-06T12:20:47.112+02:00 +- Build date: 2016-05-06T14:56:38.502+02:00 - Build package: class io.swagger.codegen.languages.ObjcClientCodegen ## Requirements diff --git a/samples/client/petstore/objc/SwaggerClient/SWGApiClient.h b/samples/client/petstore/objc/SwaggerClient/SWGApiClient.h index 7dea87a3327..5024566c3f7 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGApiClient.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGApiClient.h @@ -32,7 +32,9 @@ extern NSString *const SWGResponseObjectErrorKey; /** * Log debug message macro */ -#define SWGDebugLog(format, ...) [SWGApiClient debugLog:[NSString stringWithFormat:@"%s", __PRETTY_FUNCTION__] message: format, ##__VA_ARGS__]; +#ifndef SWGDebugLog + #define SWGDebugLog(format, ...) [SWGApiClient debugLog:[NSString stringWithFormat:@"%s", __PRETTY_FUNCTION__] message: format, ##__VA_ARGS__]; +#endif @interface SWGApiClient : AFHTTPRequestOperationManager diff --git a/samples/client/petstore/objc/SwaggerClient/SWGPet.h b/samples/client/petstore/objc/SwaggerClient/SWGPet.h index 84f10969e5b..2f83af6c4e1 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGPet.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGPet.h @@ -23,7 +23,7 @@ @property(nonatomic) NSString* name; -@property(nonatomic) NSArray* /* NSString */ photoUrls; +@property(nonatomic) NSArray* photoUrls; @property(nonatomic) NSArray* tags; /* pet status in the store [optional] diff --git a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.h b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.h index ef66979613f..908771588e0 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.h @@ -56,7 +56,7 @@ /// /// /// @return NSArray* --(NSNumber*) findPetsByStatusWithStatus: (NSArray* /* NSString */) status +-(NSNumber*) findPetsByStatusWithStatus: (NSArray*) status completionHandler: (void (^)(NSArray* output, NSError* error)) handler; @@ -69,7 +69,7 @@ /// /// /// @return NSArray* --(NSNumber*) findPetsByTagsWithTags: (NSArray* /* NSString */) tags +-(NSNumber*) findPetsByTagsWithTags: (NSArray*) tags completionHandler: (void (^)(NSArray* output, NSError* error)) handler; diff --git a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m index 87201064542..b3ebc31bf68 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m @@ -217,7 +217,7 @@ static SWGPetApi* singletonAPI = nil; /// /// @returns NSArray* /// --(NSNumber*) findPetsByStatusWithStatus: (NSArray* /* NSString */) status +-(NSNumber*) findPetsByStatusWithStatus: (NSArray*) status completionHandler: (void (^)(NSArray* output, NSError* error)) handler { NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet/findByStatus"]; @@ -284,7 +284,7 @@ static SWGPetApi* singletonAPI = nil; /// /// @returns NSArray* /// --(NSNumber*) findPetsByTagsWithTags: (NSArray* /* NSString */) tags +-(NSNumber*) findPetsByTagsWithTags: (NSArray*) tags completionHandler: (void (^)(NSArray* output, NSError* error)) handler { NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet/findByTags"]; diff --git a/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.h b/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.h index 0a7bc70864a..d86eb23a046 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.h @@ -39,9 +39,9 @@ /// /// /// -/// @return NSDictionary* /* NSString, NSNumber */ +/// @return NSDictionary* -(NSNumber*) getInventoryWithCompletionHandler: - (void (^)(NSDictionary* /* NSString, NSNumber */ output, NSError* error)) handler; + (void (^)(NSDictionary* output, NSError* error)) handler; /// diff --git a/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m b/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m index 84cd3a699d0..336258c3c5b 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m @@ -141,10 +141,10 @@ static SWGStoreApi* singletonAPI = nil; /// /// Returns pet inventories by status /// Returns a map of status codes to quantities -/// @returns NSDictionary* /* NSString, NSNumber */ +/// @returns NSDictionary* /// -(NSNumber*) getInventoryWithCompletionHandler: - (void (^)(NSDictionary* /* NSString, NSNumber */ output, NSError* error)) handler { + (void (^)(NSDictionary* output, NSError* error)) handler { NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/store/inventory"]; // remove format in URL if needed @@ -192,9 +192,9 @@ static SWGStoreApi* singletonAPI = nil; authSettings: authSettings requestContentType: requestContentType responseContentType: responseContentType - responseType: @"NSDictionary* /* NSString, NSNumber */" + responseType: @"NSDictionary*" completionBlock: ^(id data, NSError *error) { - handler((NSDictionary* /* NSString, NSNumber */)data, error); + handler((NSDictionary*)data, error); } ]; } diff --git a/samples/client/petstore/objc/SwaggerClientTests/SwaggerClient/SWGViewController.m b/samples/client/petstore/objc/SwaggerClientTests/SwaggerClient/SWGViewController.m index 57fd9828e03..4405438e7ee 100644 --- a/samples/client/petstore/objc/SwaggerClientTests/SwaggerClient/SWGViewController.m +++ b/samples/client/petstore/objc/SwaggerClientTests/SwaggerClient/SWGViewController.m @@ -27,16 +27,11 @@ SWGPetApi *api = [[SWGPetApi alloc] init]; NSURL *file = [NSURL fileURLWithPath:@"/Users/geekerzp/tmp/test.jpg"]; - [api uploadFileWithPetId:@2 additionalMetadata:@2 file:file completionHandler:^(NSError *error) { + [api uploadFileWithPetId:@2 additionalMetadata:@"2" file:file completionHandler:^(NSError *error) { NSLog(@"*** error: %@", error); }]; } -- (void)didReceiveMemoryWarning -{ - [super didReceiveMemoryWarning]; -} - - (SWGPet*) createPet { SWGPet * pet = [[SWGPet alloc] init]; pet._id = [[NSNumber alloc] initWithLong:[[NSDate date] timeIntervalSince1970]]; diff --git a/samples/client/petstore/objc/SwaggerClientTests/Tests/DeserializationTest.m b/samples/client/petstore/objc/SwaggerClientTests/Tests/DeserializationTest.m index 3284336a64b..6077ab42981 100644 --- a/samples/client/petstore/objc/SwaggerClientTests/Tests/DeserializationTest.m +++ b/samples/client/petstore/objc/SwaggerClientTests/Tests/DeserializationTest.m @@ -138,7 +138,13 @@ XCTAssertTrue([result isKindOfClass:[NSArray class]]); XCTAssertTrue([[result firstObject] isKindOfClass:[SWGPet class]]); - XCTAssertEqualObjects([[result firstObject] _id], @119); + SWGPet*pet = [result firstObject]; + XCTAssertEqualObjects([pet.photoUrls firstObject],@"string"); + XCTAssertTrue([[pet.tags firstObject] isKindOfClass:[SWGTag class]]); + SWGTag* tag = [pet.tags firstObject]; + XCTAssertEqualObjects(tag._id, @0); + XCTAssertEqualObjects(tag.name, @"string"); + XCTAssertEqualObjects(pet._id, @119); } - (void)testDeserializeMapOfModels { diff --git a/samples/client/petstore/objc/docs/SWGPet.md b/samples/client/petstore/objc/docs/SWGPet.md index 6c7286531f9..c8298c66bf1 100644 --- a/samples/client/petstore/objc/docs/SWGPet.md +++ b/samples/client/petstore/objc/docs/SWGPet.md @@ -6,7 +6,7 @@ Name | Type | Description | Notes **_id** | **NSNumber*** | | [optional] **category** | [**SWGCategory***](SWGCategory.md) | | [optional] **name** | **NSString*** | | -**photoUrls** | **NSArray* /* NSString */** | | +**photoUrls** | **NSArray<NSString*>*** | | **tags** | [**NSArray<SWGTag>***](SWGTag.md) | | [optional] **status** | **NSString*** | pet status in the store | [optional] diff --git a/samples/client/petstore/objc/docs/SWGPetApi.md b/samples/client/petstore/objc/docs/SWGPetApi.md index c69e6ce02c8..a07f0cf067c 100644 --- a/samples/client/petstore/objc/docs/SWGPetApi.md +++ b/samples/client/petstore/objc/docs/SWGPetApi.md @@ -140,7 +140,7 @@ void (empty response body) # **findPetsByStatus** ```objc --(NSNumber*) findPetsByStatusWithStatus: (NSArray* /* NSString */) status +-(NSNumber*) findPetsByStatusWithStatus: (NSArray*) status completionHandler: (void (^)(NSArray* output, NSError* error)) handler; ``` @@ -156,7 +156,7 @@ SWGConfiguration *apiConfig = [SWGConfiguration sharedConfig]; [apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"]; -NSArray* /* NSString */ status = @[@"available"]; // Status values that need to be considered for filter (optional) (default to available) +NSArray* status = @[@"available"]; // Status values that need to be considered for filter (optional) (default to available) @try { @@ -184,7 +184,7 @@ NSArray* /* NSString */ status = @[@"available"]; // Status values that need to Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **status** | [**NSArray* /* NSString */**](NSString*.md)| Status values that need to be considered for filter | [optional] [default to available] + **status** | [**NSArray<NSString*>***](NSString*.md)| Status values that need to be considered for filter | [optional] [default to available] ### Return type @@ -203,7 +203,7 @@ Name | Type | Description | Notes # **findPetsByTags** ```objc --(NSNumber*) findPetsByTagsWithTags: (NSArray* /* NSString */) tags +-(NSNumber*) findPetsByTagsWithTags: (NSArray*) tags completionHandler: (void (^)(NSArray* output, NSError* error)) handler; ``` @@ -219,7 +219,7 @@ SWGConfiguration *apiConfig = [SWGConfiguration sharedConfig]; [apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"]; -NSArray* /* NSString */ tags = @[@"tags_example"]; // Tags to filter by (optional) +NSArray* tags = @[@"tags_example"]; // Tags to filter by (optional) @try { @@ -247,7 +247,7 @@ NSArray* /* NSString */ tags = @[@"tags_example"]; // Tags to filter by (optiona Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **tags** | [**NSArray* /* NSString */**](NSString*.md)| Tags to filter by | [optional] + **tags** | [**NSArray<NSString*>***](NSString*.md)| Tags to filter by | [optional] ### Return type diff --git a/samples/client/petstore/objc/docs/SWGStoreApi.md b/samples/client/petstore/objc/docs/SWGStoreApi.md index 7c9b20696d0..29dfde60aa7 100644 --- a/samples/client/petstore/objc/docs/SWGStoreApi.md +++ b/samples/client/petstore/objc/docs/SWGStoreApi.md @@ -68,7 +68,7 @@ No authorization required # **getInventory** ```objc -(NSNumber*) getInventoryWithCompletionHandler: - (void (^)(NSDictionary* /* NSString, NSNumber */ output, NSError* error)) handler; + (void (^)(NSDictionary* output, NSError* error)) handler; ``` Returns pet inventories by status @@ -92,7 +92,7 @@ SWGConfiguration *apiConfig = [SWGConfiguration sharedConfig]; // Returns pet inventories by status [apiInstance getInventoryWithCompletionHandler: - ^(NSDictionary* /* NSString, NSNumber */ output, NSError* error) { + ^(NSDictionary* output, NSError* error) { if (output) { NSLog(@"%@", output); } @@ -113,7 +113,7 @@ This endpoint does not need any parameter. ### Return type -[**NSDictionary* /* NSString, NSNumber */**](NSDictionary.md) +[**NSDictionary***](NSDictionary.md) ### Authorization