I have made a WebAPI in .NET CORE 6.
I have a controller class like this:
[ApiController]
[Route("{culture:culture}/[controller]")]
[SwaggerDefaultValue("culture", "en-US")]
[Produces("application/json")]
public class AccountsController : BaseController
{
...
}
As you can see I defined a parameter in the route like this {culture:culture}.
I would like to have a default value for this parameter in my Swagger.
I defined an attribute class like this:
[AttributeUsage(AttributeTargets.Class )]
public class SwaggerDefaultValueAttribute:Attribute
{
public string Name { get; set; }
public string Value { get; set; }
public SwaggerDefaultValueAttribute(string name, string value)
{
Name = name;
Value = value;
}
}
And a filter class like this:
public class SwaggerDefaultValueFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
// needs some code
}
}
And added the filter to my Swagger service too.
options.OperationFilter<SwaggerDefaultValueFilter>();
However, the problem is most of the code samples that I found are related to the old versions of Swagger and most of their methods are deprecated (like this one).
The question is, how can I modify this SwaggerDefaultValueFilter class to show a default value in my path parameter:
FYI: I am using <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.3" />.
I found this sample too, however, it does not set the default values of the path parameters, it seems it works for model attributes.

