Skip to content

Commit

Permalink
Add convenience extensions for OpenAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat committed Oct 17, 2024
1 parent 099d732 commit a4eaeb5
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Modules/OpenApi/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using GenHTTP.Api.Content;
using GenHTTP.Modules.OpenApi.Discovery;

namespace GenHTTP.Modules.OpenApi;

public static class Extensions
{

/// <summary>
/// Adds a pre-configured concern to the given builder.
/// </summary>
/// <remarks>
/// The generated concern will crawl through the inner handler chain and analyze the following
/// types of content: Layouts, Concerns, Functional Handlers, Webservices, Controllers.
/// </remarks>
public static T AddOpenApi<T>(this T builder) where T : IHandlerBuilder<T>
=> builder.AddOpenApi(ApiDiscovery.Default());

/// <summary>
/// Creates a concern that will use the given discovery configuration to search for API endpoints
/// to be added to the generated OpenAPI specification.
/// </summary>
/// <param name="registry">The explorer registry to be used to analyze the handler chain</param>
public static T AddOpenApi<T>(this T builder, ApiDiscoveryRegistryBuilder registry) where T : IHandlerBuilder<T>
{
builder.Add(ApiDescription.With(registry));
return builder;
}

}

0 comments on commit a4eaeb5

Please sign in to comment.