Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to remove servers list from OpenAPI specification #242

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions samples/TinyHelpers.AspNetCore.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@

// Enable OpenAPI integration for custom parameters.
options.AddOperationParameters();

// Remove Servers list in OpenAPI
options.RemoveServersList();
});

// Add default problem details and exception handler.
Expand Down
3 changes: 3 additions & 0 deletions src/TinyHelpers.AspNetCore/OpenApi/OpenApiExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public static IServiceCollection AddOpenApiOperationParameters(this IServiceColl

public static void AddOperationParameters(this OpenApiOptions options)
=> options.AddOperationTransformer<OpenApiParametersOperationFilter>();

public static void RemoveServersList(this OpenApiOptions options)
=> options.AddDocumentTransformer<RemoveServersListDocumentTransformer>();
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#if NET9_0_OR_GREATER

using Microsoft.AspNetCore.OpenApi;
using Microsoft.OpenApi.Models;

namespace TinyHelpers.AspNetCore.OpenApi;

internal class RemoveServersListDocumentTransformer : IOpenApiDocumentTransformer
{
public Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransformerContext context, CancellationToken cancellationToken)
{
document.Servers.Clear();
return Task.CompletedTask;
}
}

#endif
Loading