From a4eaeb5d83095595cd6bf31aaf77852c72204e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20N=C3=A4geli?= Date: Thu, 17 Oct 2024 18:22:01 +0200 Subject: [PATCH] Add convenience extensions for OpenAPI --- Modules/OpenApi/Extensions.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Modules/OpenApi/Extensions.cs diff --git a/Modules/OpenApi/Extensions.cs b/Modules/OpenApi/Extensions.cs new file mode 100644 index 00000000..a6adbbdb --- /dev/null +++ b/Modules/OpenApi/Extensions.cs @@ -0,0 +1,30 @@ +using GenHTTP.Api.Content; +using GenHTTP.Modules.OpenApi.Discovery; + +namespace GenHTTP.Modules.OpenApi; + +public static class Extensions +{ + + /// + /// Adds a pre-configured concern to the given builder. + /// + /// + /// The generated concern will crawl through the inner handler chain and analyze the following + /// types of content: Layouts, Concerns, Functional Handlers, Webservices, Controllers. + /// + public static T AddOpenApi(this T builder) where T : IHandlerBuilder + => builder.AddOpenApi(ApiDiscovery.Default()); + + /// + /// Creates a concern that will use the given discovery configuration to search for API endpoints + /// to be added to the generated OpenAPI specification. + /// + /// The explorer registry to be used to analyze the handler chain + public static T AddOpenApi(this T builder, ApiDiscoveryRegistryBuilder registry) where T : IHandlerBuilder + { + builder.Add(ApiDescription.With(registry)); + return builder; + } + +}