Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding custom attribute to the openAPI endpoints possible? #647

Open
bzuidgeest opened this issue Feb 22, 2024 · 0 comments
Open

Adding custom attribute to the openAPI endpoints possible? #647

bzuidgeest opened this issue Feb 22, 2024 · 0 comments

Comments

@bzuidgeest
Copy link

Describe the issue
I am building a .NET 8 out-of-process azure function and I have added the openAPI extensions. Everything mostly works great.
My only issue is that I am using a custom authentication middleware (no choice, external factors). I need to add an extra attribute to the openAPI Endpoints so this middleware knows to ignore these endpoints. Basically an custom "Allow-anonymous".

But I cannot find the place to do this.
I found https://github.com/Azure/azure-functions-openapi-extension/blob/main/templates/OpenApiHttpTrigger.cs.
But when I put a variant of that in my project I get errors on startup that the openapi functionname have been declare twice. From the code repo I cannot figure out how, if at all, DefaultOpenApiHttpTrigger and derivatives are used.

Basically I would like to do somthing like this:

/// <summary>
/// Invokes the HTTP trigger endpoint to get OpenAPI document.
/// </summary>
/// <param name="req"><see cref="HttpRequestData"/> instance.</param>
/// <param name="version">OpenAPI document spec version. This MUST be either "v2" or "v3".</param>
/// <param name="extension">File extension representing the document format. This MUST be either "json" or "yaml".</param>
/// <param name="ctx"><see cref="FunctionContext"/> instance.</param>
/// <returns>OpenAPI document in a format of either JSON or YAML.</returns>
[Function(nameof(OpenApiHttpTrigger.RenderOpenApiDocument))]
[OpenApiIgnore]
----> [AllowAnonymous] <----
public new async Task<HttpResponseData> RenderOpenApiDocument(
    [HttpTrigger(AuthorizationLevel.Function, "GET", Route = "openapi/{version}.{extension}")] HttpRequestData req,
    string version,
    string extension,
    FunctionContext ctx)
{
    var response = await this.Function.RenderOpenApiDocument(req, version, extension, ctx).ConfigureAwait(false);

    return response;
}

Is this possible?

I can also check in the middleware for the swagger endpoints entrypoints and filter on that, but that feels a little more crude to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant