Skip to content

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

@jhartman-resurgent

Description

@jhartman-resurgent

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions