2

I have a ASP.NET Web API implemented as OWIN middleware. I hosted it on azure and now I have a problem using swagger. It is perfectly working on localhost but when I try it on azure I get this:

enter image description here

The way I did my configuration for swagger on the API was to completely remove SwaggerConfig.cs file and add all the configuration into my Startup.cs class as shown here: How to generate documentation using swashbuckle for WebApi 2 with Owin . If it is going to help, I am trying to implement oAuth2 between my API, identity server and client application.

Can you help me find out what is the reason for not getting swagger functionality on Azure?

EDIT: I also tried the solution from here but without success. I went to my API->Properties->Buld tab->Changed to 'Release' configuration->In the output path added the same what was in the 'Debug' configuration and nothing.

My bin folder on Azure:

Here you can see that the xml resource file is there

Community
  • 1
  • 1
user2128702
  • 2,059
  • 2
  • 29
  • 74

3 Answers3

0

I had this problem myself when going though this tutorial.

In that tutorial on #3 under "Configure the middle tier to call the data tier" I named my key apiAppURL instead of toDoListDataAPIURL. This caused me to get 500 response codes and

{
  "Message": "An error has occurred."
}

in the response body.

I fixed it by updating the following line:

var client = new ApiApp(new Uri(ConfigurationManager.AppSettings["toDoListApiURL"]));

to

var client = new ApiApp(new Uri(ConfigurationManager.AppSettings["apiAppURL"]));

**The change made was to the string at the end of the line. That code can be found in ToDoListController.cs on line 42

Hope this helps someone!

Ethan Melamed
  • 367
  • 1
  • 11
0

Check your SwaggerConfig.cs file, if you are not included the xml file with your swagger, it works in your azure app services.

c.IncludeXmlComments($@"{System.AppDomain.CurrentDomain.BaseDirectory}\bin\WebApiSwagger.XML");
c.DescribeAllEnumsAsStrings();

I've included these 2 lines of code to show my xml in the swagger, the azure swagger will gone error.

jefferyleo
  • 630
  • 3
  • 17
  • 34
0

This is late reply but may help someone in future. I solved this issue this way:

  1. Set XML documentation file path in project settings to : wwwroot\api.xml
  2. Let Swagger know where the file is within ConfigureServices method in Startup.cs:

            services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
    
            // Set the comments path for the Swagger JSON and UI.
            var xmlFile = "api.xml";
            var xmlPath = Path.Combine(AppContext.BaseDirectory, "wwwroot", xmlFile);
            c.IncludeXmlComments(xmlPath);
        });
    

You can set different paths but you will get the idea of how to do it from this example.

Mariusz
  • 908
  • 1
  • 13
  • 28