Description
I have an interface like this:
public interface IOperationFilter
{
void Apply(OpenApiOperation operation, OperationFilterContext context);
}
I've implemented a filter class with this operation, but because the implementation doesn't touch any instance fields, SonarCloud is telling me that this method needs to be static, which cannot be done since it's an interface implementation.
Reproducer
public class AddHeaderOperationFilter : IOperationFilter
{
/// <inheritdoc />
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
if (context.ApiDescription.ActionDescriptor is ControllerActionDescriptor cad
&& (cad.MethodInfo.IsDefined(typeof(SkipHttpHeaderRequirementsAttribute), inherit: true)
|| cad.ControllerTypeInfo.IsDefined(typeof(SkipHttpHeaderRequirementsAttribute), inherit: true)))
{
return;
}
operation.Parameters ??= new List<IOpenApiParameter>();
operation.Parameters.Add(new OpenApiParameter
{
Name = "OrganisationId",
In = ParameterLocation.Header,
Required = true,
Schema = new OpenApiSchema
{
Type = JsonSchemaType.String
},
Description = "Organisation identifier"
});
operation.Parameters.Add(new OpenApiParameter
{
Name = "CallingSystem",
In = ParameterLocation.Header,
Required = true,
Schema = new OpenApiSchema
{
Type = JsonSchemaType.String
},
Description = "Identifier of system which calls the endpoint"
});
}
}
Apply gets flagged to be made static.
Product and Version
SonarCube Cloud
Description
I have an interface like this:
I've implemented a filter class with this operation, but because the implementation doesn't touch any instance fields, SonarCloud is telling me that this method needs to be static, which cannot be done since it's an interface implementation.
Reproducer
Apply gets flagged to be made static.
Product and Version
SonarCube Cloud