Repository navigation
fix: suppress obsolete warning when enumerating a deprecated resources field - #1017
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the API generator to mark a paginated method and its enumerators as deprecated if its underlying resources field is deprecated. It also updates the snippet generator to wrap page iterations in obsolete warning suppressions (#pragma warning disable CS0612) when the method is deprecated. Tests, fakes, and generated snippets have been added to verify this behavior. There are no review comments to address, so I have no feedback to provide.
231c3e1 to
cc0e95d
Compare
cc0e95d to
274b568
Compare
| SyncGrpcType = Typ.Generic(typeof(GrpcPagedEnumerable<,,>), RequestTyp, ResponseTyp, ResourceTyp); | ||
| AsyncGrpcType = Typ.Generic(typeof(GrpcPagedAsyncEnumerable<,,>), RequestTyp, ResponseTyp, ResourceTyp); | ||
| ResourcesFieldName = responseResourceField.CSharpPropertyName(); | ||
| IsResourcesFieldDeprecated = responseResourceField.GetOptions()?.Deprecated ?? false; |
There was a problem hiding this comment.
I see there's an extension method on the FieldDescriptor class similar to this except it's also checking if the containing type is deprecated:
public static bool IsDeprecated(this FieldDescriptor desc) =>
(desc?.GetOptions()?.Deprecated ?? false) || IsDeprecated(desc?.ContainingType);Is that something we'll need here?
There was a problem hiding this comment.
Good call out, but it's not required in this case. That would result in the following getting wrapped:
+#pragma warning disable CS0612
sc::IEnumerator sc::IEnumerable.GetEnumerator() => GetEnumerator())
+#pragma warning restore CS0612Although this method doesn't need to get wrapped as it doesn't reference the obsolete type.
There was a problem hiding this comment.
I see it's being used now, did you find something that caused a change of heart?
There was a problem hiding this comment.
Yes sorry forgot to update here. I was wrong totally wrong in my initial comment - I ran it and that doesn't actually get wrapped 🤦 . So I went ahead and used IsDeprecated. Thanks for pointing it out.
274b568 to
77bbaab
Compare
| /// <param name="request">The request object containing all of the parameters for the API call.</param> | ||
| /// <param name="callSettings">If not null, applies overrides to this RPC call.</param> | ||
| /// <returns>A pageable sequence of <see cref="Response"/> resources.</returns> | ||
| public virtual gax::PagedEnumerable<DeprecatedResourcesFieldPaginatedResponse, Response> DeprecatedResourcesFieldPaginatedMethod(PaginatedRequest request, gaxgrpc::CallSettings callSettings = null) => |
There was a problem hiding this comment.
Ideally API teams would mark this method as deprecated when they mark the list property deprecated. But I don't' think that's an easy thing for us to do, not sure if it's our decision to make. Just leaving this comment for posterity.
b/543020713
When a paginated method's resources field is marked deprecated, the generated code hits a deprecated warning. In this case the method should not be deprecated and we should disable the warning on the repeated field while we are using this implementation.
As a concrete example, for Apps.V1 chat the
Spacesfield forSearchSpacesResponseis deprecated and will be replaced with the newResultsfield. But whileSpacesexists it is the lowest numbered repeated field so it will be used for pagination. We do not mark the enumeration methods as obsolete as what is obsolete is our implementation (usingSpaces.GetEnumeratorinstead of the new repeatedResults.Enumeratorfield to get the enumerator - see below), onceSpacesfield is removed from the proto our implementation will become the following and not throw (validated):Validation