Skip to content

Commit

Permalink
Deal with collisions generating the headers.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thomasvl committed May 24, 2017
1 parent ec6bfd4 commit 32171a4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 30 deletions.
42 changes: 21 additions & 21 deletions Source/GeneratedServices/Storage/GTLRStorageQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -1653,14 +1653,14 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
* @param object The @c GTLRStorage_ObjectAccessControl to include in the
* query.
* @param bucket Name of a bucket.
* @param object Name of the object. For information about how to URL encode
* object names to be path safe, see Encoding URI Path Parts.
* @param object_param Name of the object. For information about how to URL
* encode object names to be path safe, see Encoding URI Path Parts.
*
* @returns GTLRStorageQuery_ObjectAccessControlsInsert
*/
+ (instancetype)queryWithObject:(GTLRStorage_ObjectAccessControl *)object
bucket:(NSString *)bucket
object:(NSString *)object;
object:(NSString *)object_param;

@end

Expand Down Expand Up @@ -1764,8 +1764,8 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
* @param object The @c GTLRStorage_ObjectAccessControl to include in the
* query.
* @param bucket Name of a bucket.
* @param object Name of the object. For information about how to URL encode
* object names to be path safe, see Encoding URI Path Parts.
* @param object_param Name of the object. For information about how to URL
* encode object names to be path safe, see Encoding URI Path Parts.
* @param entity The entity holding the permission. Can be user-userId,
* user-emailAddress, group-groupId, group-emailAddress, allUsers, or
* allAuthenticatedUsers.
Expand All @@ -1774,7 +1774,7 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
*/
+ (instancetype)queryWithObject:(GTLRStorage_ObjectAccessControl *)object
bucket:(NSString *)bucket
object:(NSString *)object
object:(NSString *)object_param
entity:(NSString *)entity;

@end
Expand Down Expand Up @@ -1827,8 +1827,8 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
* @param object The @c GTLRStorage_ObjectAccessControl to include in the
* query.
* @param bucket Name of a bucket.
* @param object Name of the object. For information about how to URL encode
* object names to be path safe, see Encoding URI Path Parts.
* @param object_param Name of the object. For information about how to URL
* encode object names to be path safe, see Encoding URI Path Parts.
* @param entity The entity holding the permission. Can be user-userId,
* user-emailAddress, group-groupId, group-emailAddress, allUsers, or
* allAuthenticatedUsers.
Expand All @@ -1837,7 +1837,7 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
*/
+ (instancetype)queryWithObject:(GTLRStorage_ObjectAccessControl *)object
bucket:(NSString *)bucket
object:(NSString *)object
object:(NSString *)object_param
entity:(NSString *)entity;

@end
Expand Down Expand Up @@ -2682,14 +2682,14 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
*
* @param object The @c GTLRStorage_Object to include in the query.
* @param bucket Name of the bucket in which the object resides.
* @param object Name of the object. For information about how to URL encode
* object names to be path safe, see Encoding URI Path Parts.
* @param object_param Name of the object. For information about how to URL
* encode object names to be path safe, see Encoding URI Path Parts.
*
* @returns GTLRStorageQuery_ObjectsPatch
*/
+ (instancetype)queryWithObject:(GTLRStorage_Object *)object
bucket:(NSString *)bucket
object:(NSString *)object;
object:(NSString *)object_param;

@end

Expand Down Expand Up @@ -2914,14 +2914,14 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
*
* @param object The @c GTLRStorage_Policy to include in the query.
* @param bucket Name of the bucket in which the object resides.
* @param object Name of the object. For information about how to URL encode
* object names to be path safe, see Encoding URI Path Parts.
* @param object_param Name of the object. For information about how to URL
* encode object names to be path safe, see Encoding URI Path Parts.
*
* @returns GTLRStorageQuery_ObjectsSetIamPolicy
*/
+ (instancetype)queryWithObject:(GTLRStorage_Policy *)object
bucket:(NSString *)bucket
object:(NSString *)object;
object:(NSString *)object_param;

@end

Expand Down Expand Up @@ -3083,14 +3083,14 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
*
* @param object The @c GTLRStorage_Object to include in the query.
* @param bucket Name of the bucket in which the object resides.
* @param object Name of the object. For information about how to URL encode
* object names to be path safe, see Encoding URI Path Parts.
* @param object_param Name of the object. For information about how to URL
* encode object names to be path safe, see Encoding URI Path Parts.
*
* @returns GTLRStorageQuery_ObjectsUpdate
*/
+ (instancetype)queryWithObject:(GTLRStorage_Object *)object
bucket:(NSString *)bucket
object:(NSString *)object;
object:(NSString *)object_param;

/**
* Fetches the requested resource data as a @c GTLRDataObject.
Expand All @@ -3099,14 +3099,14 @@ GTLR_EXTERN NSString * const kGTLRStorageProjectionNoAcl;
*
* @param object The @c GTLRStorage_Object to include in the query.
* @param bucket Name of the bucket in which the object resides.
* @param object Name of the object. For information about how to URL encode
* object names to be path safe, see Encoding URI Path Parts.
* @param object_param Name of the object. For information about how to URL
* encode object names to be path safe, see Encoding URI Path Parts.
*
* @returns GTLRStorageQuery_ObjectsUpdate
*/
+ (instancetype)queryForMediaWithObject:(GTLRStorage_Object *)object
bucket:(NSString *)bucket
object:(NSString *)object;
object:(NSString *)object_param;

@end

Expand Down
40 changes: 31 additions & 9 deletions Source/Tools/ServiceGenerator/SGGenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ - (NSString *)generateQueryMethodParametersBlockForMode:(GeneratorMode)mode {

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

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

// Append "_param" to any name used as a parameter when generating the
// query method interface to avoid duplication variables.
static NSString *MappedParamInterfaceName(NSString *name, BOOL takesObject, BOOL takesUploadParams) {
NSString *result = name;

if ((takesObject && [name isEqual:@"object"]) ||
(takesUploadParams && [name isEqual:@"uploadParameters"])) {
result = [name stringByAppendingString:@"_param"];
}

return result;
}

- (NSString *)generateQueryPropertyBlock:(NSArray *)paramSchema
mode:(GeneratorMode)mode {
NSMutableArray *parts = [NSMutableArray array];
Expand Down Expand Up @@ -1935,10 +1948,14 @@ - (NSString *)generateQueryClassesForMode:(GeneratorMode)mode {
NSString *capitalizeObjCName = param.sg_capObjCName;
[methodStr appendFormat:@"With%@:(%@%@)%@",
capitalizeObjCName, objcType, (asPtr ? @" *" : @""),
(mode == kGenerateInterface ? name : MappedParamName(name))];
(mode == kGenerateInterface
? MappedParamInterfaceName(name, doesQueryTakeObject, supportsMediaUpload)
: MappedParamImplName(name))];
[downloadMethodStr appendFormat:@"With%@:(%@%@)%@",
capitalizeObjCName, objcType, (asPtr ? @" *" : @""),
(mode == kGenerateInterface ? name : MappedParamName(name))];
(mode == kGenerateInterface
? MappedParamInterfaceName(name, doesQueryTakeObject, supportsMediaUpload)
: MappedParamImplName(name))];
nameWidth += 4 + capitalizeObjCName.length; // 'With%@'
downloadNameWidth += 4 + capitalizeObjCName.length;
needsWith = NO;
Expand All @@ -1949,11 +1966,15 @@ - (NSString *)generateQueryClassesForMode:(GeneratorMode)mode {
[methodStr appendFormat:@"\n%*s:(%@%@)%@",
(int)nameWidth, name.UTF8String, objcType,
(asPtr ? @" *" : @""),
(mode == kGenerateInterface ? name : MappedParamName(name))];
(mode == kGenerateInterface
? MappedParamInterfaceName(name, doesQueryTakeObject, supportsMediaUpload)
: MappedParamImplName(name))];
[downloadMethodStr appendFormat:@"\n%*s:(%@%@)%@",
(int)downloadNameWidth, name.UTF8String, objcType,
(asPtr ? @" *" : @""),
(mode == kGenerateInterface ? name : MappedParamName(name))];
(mode == kGenerateInterface
? MappedParamInterfaceName(name, doesQueryTakeObject, supportsMediaUpload)
: MappedParamImplName(name))];
}

NSString *paramDesc = param.descriptionProperty;
Expand All @@ -1970,7 +1991,8 @@ - (NSString *)generateQueryClassesForMode:(GeneratorMode)mode {
if (paramDesc.length == 0) {
paramDesc = objcType;
}
[methodHDoc appendParam:name string:paramDesc];
[methodHDoc appendParam:MappedParamInterfaceName(name, doesQueryTakeObject, supportsMediaUpload)
string:paramDesc];

} // for (param in method.sg_sortedParameters)

Expand Down Expand Up @@ -2188,7 +2210,7 @@ - (NSString *)generateQueryClassesForMode:(GeneratorMode)mode {
for (GTLRDiscovery_JsonSchema *param in method.sg_sortedParameters) {
if (param.required.boolValue) {
NSString *name = param.sg_objcName;
NSString *nameAsValue = MappedParamName(name);
NSString *nameAsValue = MappedParamImplName(name);
[methodStr appendFormat:@" query.%@ = %@;\n", name, nameAsValue];
}
}
Expand Down Expand Up @@ -2242,13 +2264,13 @@ - (NSString *)generateQueryClassesForMode:(GeneratorMode)mode {
if (needsWith) {
NSString *capitalizeObjCName = param.sg_capObjCName;
[downloadMethodStr appendFormat:@"With%@:%@",
capitalizeObjCName, MappedParamName(param.sg_objcName)];
capitalizeObjCName, MappedParamImplName(param.sg_objcName)];
nameWidth += 4 + capitalizeObjCName.length; // 'With%@'
needsWith = NO;
} else {
NSString *name = param.sg_objcName;
[downloadMethodStr appendFormat:@"\n%*s:%@",
(int)nameWidth, name.UTF8String, MappedParamName(name)];
(int)nameWidth, name.UTF8String, MappedParamImplName(name)];
}
}
}
Expand Down

0 comments on commit 32171a4

Please sign in to comment.