5252static NSString *kReturnsSchemaParameterKey = @" returnsSchema" ;
5353static NSString *kAllMethodObjectParametersKey = @" allMethodObjectParameters" ;
5454static NSString *kAllMethodObjectParameterRefsKey = @" allMethodObjectParameterRefs" ;
55+ static NSString *kHasDeprecatedSchemaKey = @" hasDeprecatedSchemaKey" ;
5556static NSString *kCleanedRootURLStringKey = @" cleanedRootURLString" ;
5657static NSString *kResumableUploadPathKey = @" resumableUploadPath" ;
5758static NSString *kSimpleUploadPathKey = @" simpleUploadPath" ;
@@ -96,6 +97,7 @@ @interface GTLRDiscovery_RestDescription (SGGeneratorAdditions)
9697@property (readonly ) NSDictionary *sg_objectEnumsMap;
9798@property (readonly ) NSArray *sg_allSchemas;
9899@property (readonly ) NSArray *sg_topLevelObjectSchemas;
100+ @property (readonly ) BOOL sg_hasDeprecatedSchema;
99101@property (readonly ) NSArray *sg_allMethodObjectParameterReferences;
100102@property (readonly ) NSString *sg_resumableUploadPath;
101103@property (readonly ) NSString *sg_simpleUploadPath;
@@ -1287,6 +1289,7 @@ - (NSString *)objectsHeader {
12871289 }
12881290
12891291 SGClangDirectives *clangDirectives = [SGClangDirectives disabledDocumentation ];
1292+ clangDirectives.disableDeprecatedDeclarations = self.api .sg_hasDeprecatedSchema ;
12901293 [parts addObject: clangDirectives.start];
12911294
12921295 [parts addObject: @" NS_ASSUME_NONNULL_BEGIN\n " ];
@@ -1339,6 +1342,14 @@ - (NSString *)objectsSource {
13391342 [parts addObjectsFromArray: blocks];
13401343 }
13411344
1345+ SGClangDirectives *clangDirectives = [[SGClangDirectives alloc ] init ];
1346+ BOOL hasDeprecatedSchema = self.api .sg_hasDeprecatedSchema ;
1347+ clangDirectives.disableDeprecatedImplementations = hasDeprecatedSchema;
1348+ clangDirectives.disableDeprecatedDeclarations = hasDeprecatedSchema;
1349+ if (clangDirectives.hasDirectives ) {
1350+ [parts addObject: clangDirectives.start];
1351+ }
1352+
13421353 NSMutableArray *classParts = [NSMutableArray array ];
13431354 for (GTLRDiscovery_JsonSchema *schema in self.api .sg_topLevelObjectSchemas ) {
13441355 NSString *objectClassStr = [self generateObjectClassForSchema: schema
@@ -1354,6 +1365,10 @@ - (NSString *)objectsSource {
13541365 // Two blank lines between classes.
13551366 [parts addObject: [classParts componentsJoinedByString: @" \n\n " ]];
13561367
1368+ if (clangDirectives.hasDirectives ) {
1369+ [parts addObject: clangDirectives.end];
1370+ }
1371+
13571372 return [parts componentsJoinedByString: @" \n " ];
13581373}
13591374
@@ -2403,8 +2418,9 @@ - (NSString *)generateObjectClassForSchema:(GTLRDiscovery_JsonSchema *)schema
24032418 } else if (isTopLevelArrayResult) {
24042419 baseClass = kResultArrayClass ;
24052420 }
2406- atBlock = [NSString stringWithFormat: @" @interface %@ : %@ \n " ,
2407- schemaClassName, baseClass];
2421+ NSString *maybeDeprecated = schema.deprecated .boolValue ? kDeprecatedWithNewline : @" " ;
2422+ atBlock = [NSString stringWithFormat: @" %@ @interface %@ : %@ \n " ,
2423+ maybeDeprecated, schemaClassName, baseClass];
24082424 } else {
24092425 atBlock = [NSString stringWithFormat: @" @implementation %@ \n " ,
24102426 schemaClassName];
@@ -3313,6 +3329,37 @@ - (NSArray *)sg_topLevelObjectSchemas {
33133329 return result;
33143330}
33153331
3332+ - (BOOL )sg_hasDeprecatedSchema {
3333+ // This could be expanded to deal with if there are referenced as types
3334+ // on other schema vs. queries to only add the guards when needed, but
3335+ // for now just generally insert them when any schema was deprecated.
3336+ NSNumber *result = [self sg_propertyForKey: kHasDeprecatedSchemaKey ];
3337+ if (result == nil ) {
3338+ BOOL hasDeprecated = NO ;
3339+
3340+ for (GTLRDiscovery_JsonSchema *schema in self.sg_topLevelObjectSchemas ) {
3341+ if (schema.deprecated .boolValue ) {
3342+ hasDeprecated = YES ;
3343+ break ;
3344+ }
3345+
3346+ for (GTLRDiscovery_JsonSchema *subSchema in schema.sg_childObjectSchemas ) {
3347+ if (subSchema.deprecated .boolValue ) {
3348+ hasDeprecated = YES ;
3349+ break ;
3350+ }
3351+ }
3352+ if (hasDeprecated) {
3353+ break ;
3354+ }
3355+ }
3356+
3357+ result = [NSNumber numberWithBool: hasDeprecated];
3358+ [self sg_setProperty: result forKey: kHasDeprecatedSchemaKey ];
3359+ }
3360+ return [result boolValue ];
3361+ }
3362+
33163363// These are resolved schema references in the method parameters (refs or
33173364// inline).
33183365- (NSArray *)sg_allMethodObjectParameterReferences {
0 commit comments