question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ignore CancellationToken parameters by default

See original GitHub issue

I can’t find a way to flag a parameter on my method to exclude the CancellationToken parameter from generating in the documentation.

I propose a convention of ignoring this type of parameter during generation.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
dementeddevilcommented, Feb 14, 2016

Finally found out why my controller wasn’t working and this was it - just spent all weekend trying to get this going.

If you are using swashbuckle v6 and ASP.NET 5 then the code you need differs slightly from the above sample.

The code below was what I had to use to get things going…

    public class SwaggerRemoveCancellationTokenParameterFilter : IOperationFilter
    {
        public void Apply(Operation operation, OperationFilterContext context)
        {
            context.ApiDescription.ParameterDescriptions
                .Where(pd =>
                    pd.ModelMetadata.ContainerType == typeof(CancellationToken) ||
                    pd.ModelMetadata.ContainerType == typeof(WaitHandle) ||
                    pd.ModelMetadata.ContainerType == typeof(SafeWaitHandle))
                .ToList()
                .ForEach(
                    pd =>
                    {
                        if (operation.Parameters != null)
                        {
                            var cancellationTokenParameter = operation.Parameters.Single(p => p.Name == pd.Name);
                            operation.Parameters.Remove(cancellationTokenParameter);
                        }
                    });
        }
    }
2reactions
domaindrivendevcommented, Sep 14, 2017

Fixed by 7ab9b842c5ad068dd7115a102bed45559133e0a6. Will automatically ignore parameters of type CancellationToken without the need for custom filters.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignore CancellationToken parameters by default · Issue #627
I can't find a way to flag a parameter on my method to exclude the CancellationToken parameter from generating in the documentation.
Read more >
c# - Default parameter - CancellationToken
It's a good idea to only make your CancellationToken parameters optional in your public API (if you have one) and leave them as...
Read more >
CA1068: CancellationToken parameters must come last
A method has a CancellationToken parameter that is not the last parameter. By default, this rule analyzes the entire codebase, ...
Read more >
Set default parameter value for cancellationToken
This parameter allows you to check if a cancellation is requested and to handle this properly. Tip: If you want to learn everything...
Read more >
A Deep Dive into C#'s CancellationToken | by Mitesh Shah
Here we start cancellable tasks and pass the cancellation token to the delegate that's running. Passing to the task here is optional.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found