-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
I've been playing around with using minimal actions to build a sample app that's a mix of API, Identity and Razor Pages, but exclusively using minimal actions to implement any endpoints in the app, not just the API. I'm currently using this with a daily build of the preview 7 SDK (6.0.100-preview.7.21330.1
).
When plugging-in Swagger with the minimal configuration, all the minimal actions endpoints are returned in the Swagger documentation.
I've manually hidden things with the following code:
builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Todo API", Version = "v1" });
options.DocInclusionPredicate(
(_, description) => description.RelativePath?.StartsWith("api/", StringComparison.Ordinal) == true);
});
However what I would have liked to have done instead is to explicitly hide the actions using the ApiExplorerSettings
attribute using the new support for attributes on lambdas, that doesn't seem to be working.
This is what I tried:
builder.MapPost("/signin", [ApiExplorerSettings(IgnoreApi = true)] () =>
Results.Challenge(
new AuthenticationProperties { RedirectUri = "/" },
GitHubAuthenticationDefaults.AuthenticationScheme));
Another approach I've used in the past is the IActionModelConvention
support, but that's part of MVC so doesn't appear to be valid either.
While the DocInclusionPredicate()
approach works with a simple app, it doesn't feel like it would scale well from a maintenance point of view, particularly if the naming/paths weren't following a specific convention. It also doesn't seem possible to query for any decorated attributes (i.e. the ApiExplorerSettingsAttribute
) from the ApiDescription
passed to the method.
What is/will be the intended mechanism developers using minimal actions would use to hide specific actions from the API Explorer for use cases like Swagger?