Skip to content

[Question]: WithOpenApi and ParameterFilters #3037

@jgarciadelanoceda

Description

@jgarciadelanoceda

What are you wanting to achieve?

I have just changed the SwaggerAnnotationsEndpoints of the WebApi project and realized that the ParameterFilters are not being called when you insert the WithOpenApi extension method.

I do not know if this is by design but the change of this is pretty simple.

Previously :

var apiParameter = apiDescription.ParameterDescriptions.SingleOrDefault(desc => desc.Name == parameter.Name && !desc.IsFromBody() && !desc.IsFromForm() && !desc.IsIllegalHeaderParameter());
if (apiParameter is not null)
{
parameter.Schema = GenerateSchema(
apiParameter.Type,
schemaRepository,
apiParameter.PropertyInfo(),
apiParameter.ParameterInfo(),
apiParameter.RouteInfo);
}

Now (If it's not by design), I have also to integrate ParameterAsyncFilters:

var apiParameter = apiDescription.ParameterDescriptions.SingleOrDefault(desc => desc.Name == parameter.Name && !desc.IsFromBody() && !desc.IsFromForm() && !desc.IsIllegalHeaderParameter());
if (apiParameter is not null)
{
    var (parameterAndContext, filterContext) = GenerateParameterAndContext(apiParameter, schemaRepository);
    parameter.Schema = parameterAndContext.Schema;
    foreach (var filter in _options.ParameterFilters)
    {
        filter.Apply(parameter, filterContext);
    }
}

I label this as Question because I am not sure if the WithOpenApi should apply the ParameterFilters

What code or approach do you have so far?

I want that the ParameterFilters run also when the WithOpenApi extension method is called

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions