4

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?

4

1 回答 1

4

我安装了 Swashbuckle.Core,确保正在创建 XML 输出,并通过一些配置立即工作。

    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;
    }
于 2015-11-05T16:27:06.043 回答