mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 19:08:52 +00:00
Update objc client.
* Fix issue that list of primitive types deserialization. * Add test cases for list of primitive types deserialization and nested list deserialization.
This commit is contained in:
parent
cc45ff17cb
commit
b2e0d83f2e
@ -213,21 +213,22 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
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<SWGTag>*'
|
||||
String innerTypeDeclaration = getTypeDeclaration(inner);
|
||||
|
||||
if (innerTypeDeclaration.endsWith("*")) {
|
||||
innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1);
|
||||
}
|
||||
|
||||
return getSwaggerType(p) + "<" + innerTypeDeclaration + ">*";
|
||||
// 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 + " */";
|
||||
}
|
||||
// In this codition, type of property p is array of model,
|
||||
// return container type combine inner type with pointer, e.g. `NSArray<SWGTag>*'
|
||||
else {
|
||||
return getSwaggerType(p) + "<" + innerTypeDeclaration + ">*";
|
||||
}
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
@ -356,13 +356,14 @@ static void (^reachabilityChangeBlock)(int);
|
||||
NSTextCheckingResult *match = nil;
|
||||
NSMutableArray *resultArray = nil;
|
||||
NSMutableDictionary *resultDict = nil;
|
||||
NSString *innerType = nil;
|
||||
|
||||
// return nil if data is nil or class is nil
|
||||
if (!data || !class) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
// remove "*" from class, if ends with "*"
|
||||
// remove "*" from class, if ends with "*"
|
||||
if ([class hasSuffix:@"*"]) {
|
||||
class = [class substringToIndex:[class length] - 1];
|
||||
}
|
||||
@ -383,7 +384,7 @@ static void (^reachabilityChangeBlock)(int);
|
||||
range:NSMakeRange(0, [class length])];
|
||||
|
||||
if (match) {
|
||||
NSString *innerType = [class substringWithRange:[match rangeAtIndex:1]];
|
||||
innerType = [class substringWithRange:[match rangeAtIndex:1]];
|
||||
|
||||
resultArray = [NSMutableArray arrayWithCapacity:[data count]];
|
||||
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
@ -395,8 +396,8 @@ static void (^reachabilityChangeBlock)(int);
|
||||
}
|
||||
|
||||
// list of primitives
|
||||
NSString *arrayOfPrimitivesPet = @"NSArray";
|
||||
regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfPrimitivesPet
|
||||
NSString *arrayOfPrimitivesPat = @"NSArray\\* /\\* (.+) \\*/";
|
||||
regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfPrimitivesPat
|
||||
options:NSRegularExpressionCaseInsensitive
|
||||
error:nil];
|
||||
match = [regexp firstMatchInString:class
|
||||
@ -404,9 +405,11 @@ static void (^reachabilityChangeBlock)(int);
|
||||
range:NSMakeRange(0, [class length])];
|
||||
|
||||
if (match) {
|
||||
innerType = [class substringWithRange:[match rangeAtIndex:1]];
|
||||
|
||||
resultArray = [NSMutableArray arrayWithCapacity:[data count]];
|
||||
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
[resultArray addObject:[self deserialize:obj class:NSStringFromClass([obj class])]];
|
||||
[resultArray addObject:[self deserialize:obj class:innerType]];
|
||||
}];
|
||||
|
||||
return resultArray;
|
||||
|
@ -90,7 +90,7 @@ class ObjcModelTest extends FlatSpec with Matchers {
|
||||
vars.get(0).isNotContainer should equal(true)
|
||||
|
||||
vars.get(1).baseName should be("urls")
|
||||
vars.get(1).datatype should be("NSArray*")
|
||||
vars.get(1).datatype should be("NSArray* /* NSString */")
|
||||
vars.get(1).name should be("urls")
|
||||
// vars.get(1).defaultValue should be ("null")
|
||||
vars.get(1).baseType should be("NSArray")
|
||||
|
@ -356,13 +356,14 @@ static void (^reachabilityChangeBlock)(int);
|
||||
NSTextCheckingResult *match = nil;
|
||||
NSMutableArray *resultArray = nil;
|
||||
NSMutableDictionary *resultDict = nil;
|
||||
NSString *innerType = nil;
|
||||
|
||||
// return nil if data is nil or class is nil
|
||||
if (!data || !class) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
// remove "*" from class, if ends with "*"
|
||||
// remove "*" from class, if ends with "*"
|
||||
if ([class hasSuffix:@"*"]) {
|
||||
class = [class substringToIndex:[class length] - 1];
|
||||
}
|
||||
@ -383,7 +384,7 @@ static void (^reachabilityChangeBlock)(int);
|
||||
range:NSMakeRange(0, [class length])];
|
||||
|
||||
if (match) {
|
||||
NSString *innerType = [class substringWithRange:[match rangeAtIndex:1]];
|
||||
innerType = [class substringWithRange:[match rangeAtIndex:1]];
|
||||
|
||||
resultArray = [NSMutableArray arrayWithCapacity:[data count]];
|
||||
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
@ -395,8 +396,8 @@ static void (^reachabilityChangeBlock)(int);
|
||||
}
|
||||
|
||||
// list of primitives
|
||||
NSString *arrayOfPrimitivesPet = @"NSArray";
|
||||
regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfPrimitivesPet
|
||||
NSString *arrayOfPrimitivesPat = @"NSArray\\* /\\* (.+) \\*/";
|
||||
regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfPrimitivesPat
|
||||
options:NSRegularExpressionCaseInsensitive
|
||||
error:nil];
|
||||
match = [regexp firstMatchInString:class
|
||||
@ -404,9 +405,11 @@ static void (^reachabilityChangeBlock)(int);
|
||||
range:NSMakeRange(0, [class length])];
|
||||
|
||||
if (match) {
|
||||
innerType = [class substringWithRange:[match rangeAtIndex:1]];
|
||||
|
||||
resultArray = [NSMutableArray arrayWithCapacity:[data count]];
|
||||
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
[resultArray addObject:[self deserialize:obj class:NSStringFromClass([obj class])]];
|
||||
[resultArray addObject:[self deserialize:obj class:innerType]];
|
||||
}];
|
||||
|
||||
return resultArray;
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
@property(nonatomic) NSString* name;
|
||||
|
||||
@property(nonatomic) NSArray* photoUrls;
|
||||
@property(nonatomic) NSArray* /* NSString */ photoUrls;
|
||||
|
||||
@property(nonatomic) NSArray<SWGTag>* tags;
|
||||
/* pet status in the store [optional]
|
||||
|
@ -59,7 +59,7 @@
|
||||
///
|
||||
///
|
||||
/// @return NSArray<SWGPet>*
|
||||
-(NSNumber*) findPetsByStatusWithCompletionBlock :(NSArray*) status
|
||||
-(NSNumber*) findPetsByStatusWithCompletionBlock :(NSArray* /* NSString */) status
|
||||
|
||||
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error))completionBlock;
|
||||
|
||||
@ -74,7 +74,7 @@
|
||||
///
|
||||
///
|
||||
/// @return NSArray<SWGPet>*
|
||||
-(NSNumber*) findPetsByTagsWithCompletionBlock :(NSArray*) tags
|
||||
-(NSNumber*) findPetsByTagsWithCompletionBlock :(NSArray* /* NSString */) tags
|
||||
|
||||
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error))completionBlock;
|
||||
|
||||
|
@ -260,7 +260,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
||||
///
|
||||
/// @returns NSArray<SWGPet>*
|
||||
///
|
||||
-(NSNumber*) findPetsByStatusWithCompletionBlock: (NSArray*) status
|
||||
-(NSNumber*) findPetsByStatusWithCompletionBlock: (NSArray* /* NSString */) status
|
||||
|
||||
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error))completionBlock {
|
||||
|
||||
@ -341,7 +341,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
||||
///
|
||||
/// @returns NSArray<SWGPet>*
|
||||
///
|
||||
-(NSNumber*) findPetsByTagsWithCompletionBlock: (NSArray*) tags
|
||||
-(NSNumber*) findPetsByTagsWithCompletionBlock: (NSArray* /* NSString */) tags
|
||||
|
||||
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error))completionBlock {
|
||||
|
||||
|
@ -55,6 +55,14 @@
|
||||
XCTAssertTrue([result isEqualToString:data]);
|
||||
}
|
||||
|
||||
- (void)testDeserializeListOfString {
|
||||
NSArray *data = @[@"test string"];
|
||||
NSArray *result = [apiClient deserialize:data class:@"NSArray* /* NSString */"];
|
||||
|
||||
XCTAssertTrue([result isKindOfClass:[NSArray class]]);
|
||||
XCTAssertTrue([result[0] isKindOfClass:[NSString class]]);
|
||||
}
|
||||
|
||||
- (void)testDeserializeListOfModels {
|
||||
NSArray *data =
|
||||
@[
|
||||
@ -131,4 +139,14 @@
|
||||
XCTAssertTrue([result[@"foo"][@"bar"] isKindOfClass:[NSNumber class]]);
|
||||
}
|
||||
|
||||
- (void)testDeserializeNestedList {
|
||||
NSArray *data = @[@[@"foo"]];
|
||||
|
||||
NSArray *result = [apiClient deserialize:data class:@"NSArray* /* NSArray* /* NSString */ */"];
|
||||
|
||||
XCTAssertTrue([result isKindOfClass:[NSArray class]]);
|
||||
XCTAssertTrue([result[0] isKindOfClass:[NSArray class]]);
|
||||
XCTAssertTrue([result[0][0] isKindOfClass:[NSString class]]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in New Issue
Block a user