Better CancellationToken support for ApiExplorer
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Is your feature request related to a problem? Please describe.
I want to use `Microsoft.AspNetCore.Mvc.Api.Analyzers` and its `DefaultApiConventions` to analyze my apis. However, I use CancellationTokens in the controller actions. This means that the `DefaultApiConventions` won't match to my controller actions and I get an "API1000 Action method returns undeclared status code [...]" warning. Since CancellationTokens are not part the api contract per se, I don't think we should need to create duplicate conventions for controller actions with CancellationTokens and controller actions without CancellationTokens.
### Describe the solution you'd like
CancellationToken parameters are ignored by the `ApiConventionMatcher`.
### Describe alternatives you've considered
Creating duplicate conventions for controller actions with CancellationTokens and those without. eg:
```
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesDefaultResponseType]
[ApiConventionNameMatch(ApiConventionNameMatchBehavior.Prefix)]
public static void Get(
[ApiConventionNameMatch(ApiConventionNameMatchBehavior.Suffix)]
[ApiConventionTypeMatch(ApiConventionTypeMatchBehavior.Any)]
object id)
{ }
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesDefaultResponseType]
[ApiConventionNameMatch(ApiConventionNameMatchBehavior.Prefix)]
public static void Get(
[ApiConventionNameMatch(ApiConventionNameMatchBehavior.Suffix)]
[ApiConventionTypeMatch(ApiConventionTypeMatchBehavior.Any)]
object id,
[ApiConventionNameMatch(ApiConventionNameMatchBehavior.Any)]
CancellationToken cancellationToken)
{ }
```
Contributor guide
Assessment
This issue has not been assessed yet.