如何添加Swashbuckle AspNetCore XmlCommentsDocumentFilter

时间:2018-06-09 17:23:17

标签: asp.net-core swagger swagger-ui swashbuckle

使用此错误添加c.DocumentFilter<XmlCommentsDocumentFilter>();会破坏API服务

System.ObjectDisposedException: Cannot write to the response body, the 
response has completed.
Object name: 'HttpResponseStream'.

我正在使用https://github.com/Microsoft/aspnet-api-versioning

services.AddSwaggerGen(c =>
{
    var provider = services.BuildServiceProvider().GetRequiredService<IApiVersionDescriptionProvider>();
    // This is the offending line of code
    c.DocumentFilter<XmlCommentsDocumentFilter>();

    foreach (var description in provider.ApiVersionDescriptions)
    {
        c.SwaggerDoc(
            description.GroupName,
            new Info()
            {
                Title = $"API {description.ApiVersion}",
                Version = description.ApiVersion.ToString(),
                Description = "Services for handling resource requests",
                }
            });

    }

    var filePath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "API.xml");
    c.IncludeXmlComments(filePath);
});

0 个答案:

没有答案