Azure / Azure/azure-functions-openapi-extension

Feature Request: Add Metadata to All/Multiple Functions At Once

Open
#360 1 comment 1 reaction 0 assignees View on GitHub
discussion enhancement
Dominant language
C#
Stars
388
Forks
202
PR merge metrics
No merged PRs in 30d

Description

I currently have to add an OpenApiSecurity attribute to every function, even though they are all the same. I would like to be able to add metadata to functions using code to fit my conventions.

**Pseudocode**
I'm just making up syntax here to convey the idea.

```csharp
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureOpenApi(ApplyOpenApiMetadata)
.Build();

public static void ApplyOpenApiMetadata(OpenApiContext context) {
context.Options.Title = "My Awesome API";

context.Functions
.Where(f => f.AuthorizationLevel == AuthorizationLevel.Function)
.AddAttribute(OpenApiSecurityAttrbute, "function_key", SecuritySchemeType.ApiKey, "x-functions-key", OpenApiSecurityLocationType.Header)
.AddAttribute(OpenApiResponseWithBody, HttpStatusCode.Unauthorized, "text/plain", "Unauthorized");

foreach(var endpoint in context.Functions) {
foreach(var param in endpoint.Parameters) {
endpoint.AddAttribute(OpenApiParameter, param.Name, param.Attributes.HasKey("FromRoute") ? ParameterLocation.Path : ParameterLocation.Query);
}
}
}
```

If we had to do our own reflection, that would be fine with me.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.