-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated packages. Added Swagger OperationId filter. (#71)
- Loading branch information
Showing
3 changed files
with
37 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/SimpleServicesDashboard.Api/Infrastructure/Swagger/SwaggerOperationIdFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Microsoft.OpenApi.Models; | ||
using Swashbuckle.AspNetCore.SwaggerGen; | ||
|
||
namespace SimpleServicesDashboard.Api.Infrastructure.Swagger; | ||
|
||
/// <summary> | ||
/// Represents the Swagger/Swashbuckle operation filter used to document the implicit API operationId to be generated. | ||
/// </summary> | ||
public sealed class SwaggerOperationIdFilter : IOperationFilter | ||
{ | ||
/// <summary> | ||
/// Applies the filter to the specified operation using the given context. | ||
/// </summary> | ||
/// <param name="operation">The operation to apply the filter to.</param> | ||
/// <param name="context">The current operation filter context.</param> | ||
public void Apply(OpenApiOperation operation, OperationFilterContext context) | ||
{ | ||
var controllerName = context.ApiDescription.ActionDescriptor.RouteValues["controller"]; | ||
var actionName = context.ApiDescription.ActionDescriptor.RouteValues["action"]; | ||
operation.OperationId = $"{controllerName}_{actionName}"; | ||
} | ||
} |