Enrico
Enrico

Reputation: 6202

Swashbuckle for Azure Functions: No API definition provided when it runs on Azure

I added Swashbuckle in my Azure Function v3 to generate Swagger documentation. I followed the instruction in this post and locally is working.

enter image description here

I published from my laptop this function to the Azure Portal in my function. The function is working but there is not Swagger documentation.

enter image description here

{
  "schemaValidationMessages": [
    {
      "level": "error",
      "message": "Can't read from file https://azuks-myfnz-q001.azurewebsites.net/api/swagger/json?code="
    }
  ]
}

I checked in the project to verify the generation of the XML. I can see the XML in the project. Also, I tried to change the file property "Copy to Output Directory" (apparently it is not required).

enter image description here

enter image description here

I published the Azure Function multiple times in Debug or Release and only once was working in Debug mode. I tried to Delete Existing Files with the same result.

enter image description here

Update

I updated AzureExtensions.Swashbuckle to the version 3.1.6 and now I have another error on Azure:

Failed to load API definition.

enter image description here

I checked in the project .csproj and I can see

<PropertyGroup>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

I created a test project on Github.

Update #2

For same reason, the code param can't be the same for json and UI. If you open your Swagger url with Get Function url and copy the url from UI function, it is working.

enter image description here

Upvotes: 0

Views: 3264

Answers (2)

Vitaly Bibikov
Vitaly Bibikov

Reputation: 56

1.4.4, that is referenced by your project is an older version of the same lib, which is forked and has version 3.1.6.

As original repo is no longer supported.

Now, only fork => https://github.com/vitalybibikov/azure-functions-extensions-swashbuckle supports your version of Azure Functions, (which is v3)

So, you need to use only AzureExtensions.Swashbuckle package,

   <PackageReference Include="AzureExtensions.Swashbuckle" Version="3.1.6" />

and configure it as described in repo.

Upvotes: 1

Jim Xu
Jim Xu

Reputation: 23111

According to my test, when we use sdk AzureFunctions.Extensions.Swashbuckle to integrate swagger fro Azure function, we can do the following steps to include xml

  1. Change your functions project's GenerateDocumentationFile option to enable. Please add the following element in .csproj file
 <PropertyGroup>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
  </PropertyGroup>
  1. Add configration setting this extensions on your functions project's hots.json
{
  "version": "2.0",
  "extensions": {
    "Swashbuckle": {
      "XmlPath":  "{your document xml file name}" 
    } 
  }
}

For more details, please refer to the document

enter image description here

Upvotes: 0

Related Questions