azure-functions-openapi-extension
azure-functions-openapi-extension copied to clipboard
Microsoft.Azure.WebJobs.Extensions.OpenApi: OpenApiSecurityAttribute not generating bearer authentication in swagger.json
Describe the issue
I am using Microsoft.Azure.WebJobs.Extensions.OpenApi in my azure function to generate my OpenAPI spec. Unfortunately generating bearer token authentication in the swagger.json fails.
Azure function info:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="1.3.0" />
</ItemGroup>
To Reproduce Steps to reproduce the behavior:
- Add the
OpenApiSecurityAttributeto the function
[OpenApiSecurity("bearer_auth", SecuritySchemeType.Http, Scheme = OpenApiSecuritySchemeType.Bearer, BearerFormat = "JWT")]
- Start the function
- Open the swagger ui
- Click authenticate
Expected behavior
Authentication works in swagger ui, swagger.json securityDefinitions/bearer_auth is generated.
Actual behavior
Error is shown:

On investigation the swagger.json securityDefinitions/bearer_auth is empty:
{
"securityDefinitions": {
"bearer_auth": {}
}
}
I have the same problem
Try to set settings for your IOpenApiConfigurationOptions
OpenApiVersion = OpenApiVersionType.V3