-
Notifications
You must be signed in to change notification settings - Fork 198
Open
Labels
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.
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.
andrewreeman