azure-functions-openapi-extension icon indicating copy to clipboard operation
azure-functions-openapi-extension copied to clipboard

Error Generating swagger.json running functions locally. Missing Microsoft.Azure.WebJobs

Open Pmeholm opened this issue 4 years ago • 2 comments

Hi,

using package Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="0.8.1-preview" I tried to create a basebones setup defining openapi config (to force v3) and one operation.

No errors are thrown when building and starting the local function, however when i try to load the swagger.json i get a message Could not load file or assembly 'Microsoft.Azure.WebJobs, Version=3.0.23.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified. I checked the folder containing the dlls (bin\Debug\netcoreapp3.1) and this file is present.

setup.cs

using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
using Microsoft.OpenApi.Models;
...
public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
{
    public OpenApiVersionType OpenApiVersion { get; set; } = OpenApiVersionType.V3;
    public OpenApiInfo Info { get; set; } = new OpenApiInfo()
    {
        Version = "1.0.0",
        Title = "My API",
        Description = "API for getting, setting and invoking actions",
        Contact = new OpenApiContact()
        {
            Name = "me",
            Email = "[email protected]"
            // Url = new Uri("https://github.com/Azure/azure-functions-openapi-extension/issues"),
        },
    };
    public bool IncludeRequestingHostName { get;set;}
    public List<OpenApiServer> Servers { get;set;} = new List<OpenApiServer>();
}

some.api.cs

using Microsoft.Azure.WebJobs.Extensions.OpenApi;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
...
[FunctionName(nameof(invokeApi.invoke_getById))]
[OpenApiOperation(
    operationId: "getById",
    tags: new[] { "name" },
    Summary = "Gets action by id",
    Description = "This gets the name.",
    Visibility = OpenApiVisibilityType.Important
    )]
.... function code...

local.settings.json

{
  "OpenApi__HideSwaggerUI": false,
  "OpenApi__ApiKey": "",
  "OpenApi__AuthLevel__Document": "Anonymous",
  "OpenApi__AuthLevel__UI": "Anonymous"
}

LOG:

Executing HTTP request: {
  requestId: "4ecf1571-9796-4b28-9eb2-c0c9e871b207",
  method: "GET",
  userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36",
  uri: "/api/swagger.json"
}
Request successfully matched the route with name 'RenderSwaggerDocument' and template 'api/swagger.{extension}'
Executing 'Functions.RenderSwaggerDocument' (Reason='This function was programmatically called via the host APIs.', Id=e8de6a65-512d-47b1-bd1d-675c7ebeeacf)
swagger.json was requested.
Could not load file or assembly 'Microsoft.Azure.WebJobs, Version=3.0.23.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
Executed 'Functions.RenderSwaggerDocument' (Succeeded, Id=e8de6a65-512d-47b1-bd1d-675c7ebeeacf, Duration=754ms)
Executed HTTP request: {
  requestId: "4ecf1571-9796-4b28-9eb2-c0c9e871b207",
  identities: "",
  status: "500",
  duration: "864"
}

Pmeholm avatar Aug 27 '21 12:08 Pmeholm

@Pmeholm Thanks for the issue! Could you double check whether your file exists in the bin\Debug\netcoreapp3.1/bin directory or not? If it doesn't exist, this workaround in your .csproj might help:

  <PropertyGroup>
    ...
    <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
  </PropertyGroup>

Reference: https://github.com/Azure/azure-functions-host/issues/5894

justinyoo avatar Sep 07 '21 16:09 justinyoo

Clean and rebuild also helps!

es-alt avatar Oct 19 '21 15:10 es-alt