4
votes

I have a problem to integrate swagger ui with my web api, and i don't have any idee what is the problem.

When i call in the browser the swagger, the page http://localhost:56381/swagger/ui/index is like in this screenshot

http://localhost:56381/swagger/ui/index

In the SwaggerConfig.cs file i have this code:

[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]

 namespace dummyNamespace
 {
    public class SwaggerConfig
    {
       public static void Register()
      {
        var thisAssembly = typeof(SwaggerConfig).Assembly;
        GlobalConfiguration.Configuration
            .EnableSwagger(c => c.SingleApiVersion("v1", "Test API"))
            .EnableSwaggerUi();

       }
    }
  }

I follow this tutorial: http://www.wmpratt.com/swagger-and-asp-net-web-api-part-1/ . But not working.

I don't now what is wrong with my configuratio.

I use .net framework 4.5.2, Web api 2.0 and Swashbuckle.5.5.3 version

Update: When I call this url

http://localhost:56381/swagger/docs/v1

Return this image: docs/v1

Update1:

After i put this code in my WebApiConfig.cs:

var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
        config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);

Now the http://localhost:56381/swagger/ui/index return this json:

  {
    "statusCode": 200
  }

Any idee how to make make http://localhost:56381/swagger/ui/index return this page: enter image description here

enter image description here

The page is from a test project.

1
Why do you belive that ? - MrBlue
Try to click link, it;s a png file. The link is the description of png - MrBlue
@MegaTron My Startup.cs is in the root of my project. and contain: code public partial class Startup { public void Configuration(IAppBuilder app) { ConfigureAuth(app); } } - MrBlue
@MegaTron Sorry. Bad link. This is the correct one: wmpratt.com/swagger-and-asp-net-web-api-part-1. Multiple tabs in chrome and bad copy paste. - MrBlue
Can you post your Controller? The response is not an error so it may be that there is nothing else to describe... - strickt01

1 Answers

1
votes

After reading the tutorial you posted, it looks like somehow your root URL may be different than what swagger expects. From the swagger config file:

// By default, the service root url is inferred from the request used to access the docs. // However, there may be situations (e.g. proxy and load-balanced environments) where this does not // resolve correctly. You can workaround this by providing your own code to determine the root URL. // //c.RootUrl(req => GetRootUrlFromAppConfig());

If that is not the case, it could be that the swashbuckle nuget install is somehow corrupted. Try removing the nuget package and reinstalling it.