Skip to content

Commit 32171a4

Browse files
committed
Deal with collisions generating the headers.
When generating a query header, we can add "object" and "uploadParams" as arguments, which could conflict with the service definition, change the variable name when collisions happen. Fixes #133
1 parent ec6bfd4 commit 32171a4

File tree

2 files changed

+52
-30
lines changed

2 files changed

+52
-30
lines changed

Source/GeneratedServices/Storage/GTLRStorageQuery.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,14 +1653,14 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
16531653
* @param object The @c GTLRStorage_ObjectAccessControl to include in the
16541654
* query.
16551655
* @param bucket Name of a bucket.
1656-
* @param object Name of the object. For information about how to URL encode
1657-
* object names to be path safe, see Encoding URI Path Parts.
1656+
* @param object_param Name of the object. For information about how to URL
1657+
* encode object names to be path safe, see Encoding URI Path Parts.
16581658
*
16591659
* @returns GTLRStorageQuery_ObjectAccessControlsInsert
16601660
*/
16611661
+ (instancetype)queryWithObject:(GTLRStorage_ObjectAccessControl *)object
16621662
bucket:(NSString *)bucket
1663-
object:(NSString *)object;
1663+
object:(NSString *)object_param;
16641664

16651665
@end
16661666

@@ -1764,8 +1764,8 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
17641764
* @param object The @c GTLRStorage_ObjectAccessControl to include in the
17651765
* query.
17661766
* @param bucket Name of a bucket.
1767-
* @param object Name of the object. For information about how to URL encode
1768-
* object names to be path safe, see Encoding URI Path Parts.
1767+
* @param object_param Name of the object. For information about how to URL
1768+
* encode object names to be path safe, see Encoding URI Path Parts.
17691769
* @param entity The entity holding the permission. Can be user-userId,
17701770
* user-emailAddress, group-groupId, group-emailAddress, allUsers, or
17711771
* allAuthenticatedUsers.
@@ -1774,7 +1774,7 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
17741774
*/
17751775
+ (instancetype)queryWithObject:(GTLRStorage_ObjectAccessControl *)object
17761776
bucket:(NSString *)bucket
1777-
object:(NSString *)object
1777+
object:(NSString *)object_param
17781778
entity:(NSString *)entity;
17791779

17801780
@end
@@ -1827,8 +1827,8 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
18271827
* @param object The @c GTLRStorage_ObjectAccessControl to include in the
18281828
* query.
18291829
* @param bucket Name of a bucket.
1830-
* @param object Name of the object. For information about how to URL encode
1831-
* object names to be path safe, see Encoding URI Path Parts.
1830+
* @param object_param Name of the object. For information about how to URL
1831+
* encode object names to be path safe, see Encoding URI Path Parts.
18321832
* @param entity The entity holding the permission. Can be user-userId,
18331833
* user-emailAddress, group-groupId, group-emailAddress, allUsers, or
18341834
* allAuthenticatedUsers.
@@ -1837,7 +1837,7 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
18371837
*/
18381838
+ (instancetype)queryWithObject:(GTLRStorage_ObjectAccessControl *)object
18391839
bucket:(NSString *)bucket
1840-
object:(NSString *)object
1840+
object:(NSString *)object_param
18411841
entity:(NSString *)entity;
18421842

18431843
@end
@@ -2682,14 +2682,14 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
26822682
*
26832683
* @param object The @c GTLRStorage_Object to include in the query.
26842684
* @param bucket Name of the bucket in which the object resides.
2685-
* @param object Name of the object. For information about how to URL encode
2686-
* object names to be path safe, see Encoding URI Path Parts.
2685+
* @param object_param Name of the object. For information about how to URL
2686+
* encode object names to be path safe, see Encoding URI Path Parts.
26872687
*
26882688
* @returns GTLRStorageQuery_ObjectsPatch
26892689
*/
26902690
+ (instancetype)queryWithObject:(GTLRStorage_Object *)object
26912691
bucket:(NSString *)bucket
2692-
object:(NSString *)object;
2692+
object:(NSString *)object_param;
26932693

26942694
@end
26952695

@@ -2914,14 +2914,14 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
29142914
*
29152915
* @param object The @c GTLRStorage_Policy to include in the query.
29162916
* @param bucket Name of the bucket in which the object resides.
2917-
* @param object Name of the object. For information about how to URL encode
2918-
* object names to be path safe, see Encoding URI Path Parts.
2917+
* @param object_param Name of the object. For information about how to URL
2918+
* encode object names to be path safe, see Encoding URI Path Parts.
29192919
*
29202920
* @returns GTLRStorageQuery_ObjectsSetIamPolicy
29212921
*/
29222922
+ (instancetype)queryWithObject:(GTLRStorage_Policy *)object
29232923
bucket:(NSString *)bucket
2924-
object:(NSString *)object;
2924+
object:(NSString *)object_param;
29252925

29262926
@end
29272927

@@ -3083,14 +3083,14 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
30833083
*
30843084
* @param object The @c GTLRStorage_Object to include in the query.
30853085
* @param bucket Name of the bucket in which the object resides.
3086-
* @param object Name of the object. For information about how to URL encode
3087-
* object names to be path safe, see Encoding URI Path Parts.
3086+
* @param object_param Name of the object. For information about how to URL
3087+
* encode object names to be path safe, see Encoding URI Path Parts.
30883088
*
30893089
* @returns GTLRStorageQuery_ObjectsUpdate
30903090
*/
30913091
+ (instancetype)queryWithObject:(GTLRStorage_Object *)object
30923092
bucket:(NSString *)bucket
3093-
object:(NSString *)object;
3093+
object:(NSString *)object_param;
30943094

30953095
/**
30963096
* Fetches the requested resource data as a @c GTLRDataObject.
@@ -3099,14 +3099,14 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
30993099
*
31003100
* @param object The @c GTLRStorage_Object to include in the query.
31013101
* @param bucket Name of the bucket in which the object resides.
3102-
* @param object Name of the object. For information about how to URL encode
3103-
* object names to be path safe, see Encoding URI Path Parts.
3102+
* @param object_param Name of the object. For information about how to URL
3103+
* encode object names to be path safe, see Encoding URI Path Parts.
31043104
*
31053105
* @returns GTLRStorageQuery_ObjectsUpdate
31063106
*/
31073107
+ (instancetype)queryForMediaWithObject:(GTLRStorage_Object *)object
31083108
bucket:(NSString *)bucket
3109-
object:(NSString *)object;
3109+
object:(NSString *)object_param;
31103110

31113111
@end
31123112

Source/Tools/ServiceGenerator/SGGenerator.m

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ - (NSString *)generateQueryMethodParametersBlockForMode:(GeneratorMode)mode {
14321432

14331433
// Append "_param" to any name used as a local variable when generating the
14341434
// query method implementation to avoid duplication variables.
1435-
static NSString *MappedParamName(NSString *name) {
1435+
static NSString *MappedParamImplName(NSString *name) {
14361436
NSString *result = name;
14371437

14381438
if ([name isEqual:@"object"] ||
@@ -1446,6 +1446,19 @@ - (NSString *)generateQueryMethodParametersBlockForMode:(GeneratorMode)mode {
14461446
return result;
14471447
}
14481448

1449+
// Append "_param" to any name used as a parameter when generating the
1450+
// query method interface to avoid duplication variables.
1451+
static NSString *MappedParamInterfaceName(NSString *name, BOOL takesObject, BOOL takesUploadParams) {
1452+
NSString *result = name;
1453+
1454+
if ((takesObject && [name isEqual:@"object"]) ||
1455+
(takesUploadParams && [name isEqual:@"uploadParameters"])) {
1456+
result = [name stringByAppendingString:@"_param"];
1457+
}
1458+
1459+
return result;
1460+
}
1461+
14491462
- (NSString *)generateQueryPropertyBlock:(NSArray *)paramSchema
14501463
mode:(GeneratorMode)mode {
14511464
NSMutableArray *parts = [NSMutableArray array];
@@ -1935,10 +1948,14 @@ - (NSString *)generateQueryClassesForMode:(GeneratorMode)mode {
19351948
NSString *capitalizeObjCName = param.sg_capObjCName;
19361949
[methodStr appendFormat:@"With%@:(%@%@)%@",
19371950
capitalizeObjCName, objcType, (asPtr ? @" *" : @""),
1938-
(mode == kGenerateInterface ? name : MappedParamName(name))];
1951+
(mode == kGenerateInterface
1952+
? MappedParamInterfaceName(name, doesQueryTakeObject, supportsMediaUpload)
1953+
: MappedParamImplName(name))];
19391954
[downloadMethodStr appendFormat:@"With%@:(%@%@)%@",
19401955
capitalizeObjCName, objcType, (asPtr ? @" *" : @""),
1941-
(mode == kGenerateInterface ? name : MappedParamName(name))];
1956+
(mode == kGenerateInterface
1957+
? MappedParamInterfaceName(name, doesQueryTakeObject, supportsMediaUpload)
1958+
: MappedParamImplName(name))];
19421959
nameWidth += 4 + capitalizeObjCName.length; // 'With%@'
19431960
downloadNameWidth += 4 + capitalizeObjCName.length;
19441961
needsWith = NO;
@@ -1949,11 +1966,15 @@ - (NSString *)generateQueryClassesForMode:(GeneratorMode)mode {
19491966
[methodStr appendFormat:@"\n%*s:(%@%@)%@",
19501967
(int)nameWidth, name.UTF8String, objcType,
19511968
(asPtr ? @" *" : @""),
1952-
(mode == kGenerateInterface ? name : MappedParamName(name))];
1969+
(mode == kGenerateInterface
1970+
? MappedParamInterfaceName(name, doesQueryTakeObject, supportsMediaUpload)
1971+
: MappedParamImplName(name))];
19531972
[downloadMethodStr appendFormat:@"\n%*s:(%@%@)%@",
19541973
(int)downloadNameWidth, name.UTF8String, objcType,
19551974
(asPtr ? @" *" : @""),
1956-
(mode == kGenerateInterface ? name : MappedParamName(name))];
1975+
(mode == kGenerateInterface
1976+
? MappedParamInterfaceName(name, doesQueryTakeObject, supportsMediaUpload)
1977+
: MappedParamImplName(name))];
19571978
}
19581979

19591980
NSString *paramDesc = param.descriptionProperty;
@@ -1970,7 +1991,8 @@ - (NSString *)generateQueryClassesForMode:(GeneratorMode)mode {
19701991
if (paramDesc.length == 0) {
19711992
paramDesc = objcType;
19721993
}
1973-
[methodHDoc appendParam:name string:paramDesc];
1994+
[methodHDoc appendParam:MappedParamInterfaceName(name, doesQueryTakeObject, supportsMediaUpload)
1995+
string:paramDesc];
19741996

19751997
} // for (param in method.sg_sortedParameters)
19761998

@@ -2188,7 +2210,7 @@ - (NSString *)generateQueryClassesForMode:(GeneratorMode)mode {
21882210
for (GTLRDiscovery_JsonSchema *param in method.sg_sortedParameters) {
21892211
if (param.required.boolValue) {
21902212
NSString *name = param.sg_objcName;
2191-
NSString *nameAsValue = MappedParamName(name);
2213+
NSString *nameAsValue = MappedParamImplName(name);
21922214
[methodStr appendFormat:@" query.%@ = %@;\n", name, nameAsValue];
21932215
}
21942216
}
@@ -2242,13 +2264,13 @@ - (NSString *)generateQueryClassesForMode:(GeneratorMode)mode {
22422264
if (needsWith) {
22432265
NSString *capitalizeObjCName = param.sg_capObjCName;
22442266
[downloadMethodStr appendFormat:@"With%@:%@",
2245-
capitalizeObjCName, MappedParamName(param.sg_objcName)];
2267+
capitalizeObjCName, MappedParamImplName(param.sg_objcName)];
22462268
nameWidth += 4 + capitalizeObjCName.length; // 'With%@'
22472269
needsWith = NO;
22482270
} else {
22492271
NSString *name = param.sg_objcName;
22502272
[downloadMethodStr appendFormat:@"\n%*s:%@",
2251-
(int)nameWidth, name.UTF8String, MappedParamName(name)];
2273+
(int)nameWidth, name.UTF8String, MappedParamImplName(name)];
22522274
}
22532275
}
22542276
}

0 commit comments

Comments
 (0)