Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AZC00002 to match method pair with required requestcontext and optional convenience method #6156

Merged
merged 8 commits into from
Jun 13, 2023

Conversation

pshao25
Copy link
Member

@pshao25 pshao25 commented May 12, 2023

Fix #6145

@pshao25 pshao25 requested a review from a team as a code owner May 12, 2023 09:16
@weshaggard
Copy link
Member

@JoshLove-msft would you be the right person to review this?

@pshao25 pshao25 requested a review from m-nash May 15, 2023 05:23
@pshao25
Copy link
Member Author

pshao25 commented May 18, 2023

@m-nash could you review? BTW, since it changes the existing behavior, do you know whether we could run analyzer beforehand against azure-sdk-for-net?

@@ -10,7 +10,7 @@ namespace Azure.ClientSdk.Analyzers.Tests
public class AZC0002Tests
{
[Fact]
public async Task AZC0002ProducedForMethodsWithoutCancellationToken()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we have success cases for both cancellation token and request context being last where request context can be both required and optional but cancellation token cannot?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, AZC0002NotProducedForMethodsWithCancellationToken and AZC0002NotProducedForMethodsWithRequestContext

public class AZC0017Tests
{
[Fact]
public async Task AZC0017ProducedForMethodsWithNonOptionalCancellationToken()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this case be caught by AZC0002?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

AZC0002: your operations should have last parameter CancellationToken or RequestContext.
AZC0017: fine-grained rule for CancellationToken, your CancellationToken should optional, and your operation should not have RequestContent as parameter
AZC0018: fine-grained rule for RequestContext, your return type should not be a Response<T>.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original intent of AZC0002 was to validate that the last param was CancellationToken AND that it was optional which is why this test existed.

I think we should keep that definition only adding the allowance for RequestContext as well.

AZC0017 should only validate that if the last param is a CancellationToken, then the method MUST NOT contain a parameter of type RequestContent

Copy link
Member

@m-nash m-nash May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public Response Method(string name, CancellationToken cancellationToken = default) //PASS
public Response Method(string name, CancellationToken myToken = default) //AZC0002
public Response Method(string name, CancellationToken cancellationToken) //AZC0002
public Response Method(string name, RequestContent content, CancellationToken cancellationToken = default) //AZC0017
public Response Method(string name) //AZC0002
public Response Method(string name) //AZC0002
public Response Method(string name, RequestContext context = default) //AZC0002
public Response Method(string name, RequestContext myContext = default) //AZC0002
public Response Method(string name, RequestContext context) //PASS

//the below two cases require to look in the body for the following line
Argument.AssertNotNull(content, nameof(content));
//If it exists then the context param should be optional else it should be required
public Response Method(string name, RequestContent content, RequestContext context) //variable based on body assert
public Response Method(string name, RequestContent content, RequestContext context = default) //variable based on body assert

public Response Method(string name, RequestContent content, RequestContext context = default) //AZC0018

//future issue
public Response Method(string name, Foo content, RequestContext context = default) //AZC0018 or AZC0019

{
public class SomeClient
{
public virtual Task<Response> GetAsync(string s, RequestContext context = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add a test case which has a model as the body param to ensure it throws.

I think you will need to allow any framework types and extensible enum custom types otherwise it should fail?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A protocol method should return Response, so something like Response<string> should fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For return type yes, I was referring to the body param.

Copy link
Member

@m-nash m-nash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved with one name typo

[Fact]
public async Task AZC0002ProducedWhenCancellationTokenOverloadsDontMatch()
public async Task AZC0002NotProducedForMethodsWithRequestContentAndCancellationToken()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method named incorrectly shouldn't it be `AZC0002NotProducedForMethodsWithRequestContextAndCancellationToken

@pshao25 pshao25 merged commit 59b104e into main Jun 13, 2023
@pshao25 pshao25 deleted the AZC0002issue6145 branch June 13, 2023 10:10
annelo-msft added a commit to annelo-msft/azure-sdk-tools that referenced this pull request Aug 9, 2023
annelo-msft added a commit that referenced this pull request Aug 9, 2023
…text and optional convenience method (#6156)"

This reverts commit 59b104e.
annelo-msft added a commit that referenced this pull request Aug 10, 2023
…text and optional convenience method (#6156)" (#6742)

This reverts commit 59b104e.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update AZC0002 to match latest protocol method signature
3 participants