简体   繁体   中英

Swagger / Swashbuckle not working on Visual Studio 2013 Web API 2 project

I'm trying to install Swagger via the Nuget package (Swashbuckle) however I can't get it to work.

It's a vanilla VS 2013 Web Api 2 project. There is a single error on the JS console: Uncaught TypeError: Cannot read property 'tags' of null.

A 404 is received on the request for /swagger/ui/lib/underscore-min.map

I found a link that recommended disabling BrowserLink using vs:EnableBrowserLink in webconfig, but it didn't seem to have any effect.

Any ideas?

I installed Swashbuckle.Core, ensured that XML outputs were being created and with a little config it worked right away.

    public static void Register(HttpConfiguration config)
    {
        ...
        config
            .EnableSwagger(c =>
            {
                c.SingleApiVersion("v1", "My API Title");
                c.IncludeXmlComments(GetXmlCommentsFileLocation());
            })
            .EnableSwaggerUi();
        ...
    }

    private static string GetXmlCommentsFileLocation()
    {
        var baseDirectory = AppDomain.CurrentDomain.BaseDirectory + "\\bin";
        var commentsFileName = Assembly.GetExecutingAssembly().GetName().Name + ".XML";
        var commentsFileLocation = Path.Combine(baseDirectory, commentsFileName);
        return commentsFileLocation;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM