0

I am using currently using AddEndpointFilter for my endpoint using MinimalAPI

app.MapGet("/{Id}", Method).AddEndpointFilter<HeaderFilter>()

Using NSwag's OperationProcessor, I want to be able to get every EndpointFilter that is used in an endpoint. Is there a path within the context I can use? I am currently struggling to find any way of doing this.

public class HeaderOperationProcessor : IOperationProcessor
{
    public bool Process(OperationProcessorContext context)
    {
        // filter need to go here
        var header = new OpenApiParameter()
        {
            Name = "CustomHeader",
            Kind = OpenApiParameterKind.Header,
            IsRequired = true,
            Type = JsonObjectType.String
        };

        context.OperationDescription.Operation.Parameters.Add(header);

        return true;
    }
}

I have tried adding to the metadata of the endpoint and filtering through that, that works to an extent but adds extra lines for an endpoint that may have multiple endpoint filters so it can be quite messy

1 Answer 1

0

So the context default type of OperationProcessorContext doesn't include an API description by default but you can declare it as an AspNetCoreOperationProcessorContext which does contain the metadata - E.g.

            var metadata = ((AspNetCoreOperationProcessorContext)context).ApiDescription.ActionDescriptor.EndpointMetadata.Select(m => m.ToString());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.