How to omit methods from Swagger documentation on WebAPI using Swashbuckle

前端 未结 10 909
不思量自难忘°
不思量自难忘° 2020-11-30 19:38

I have a C# ASP.NET WebAPI application with API documentation being automatically generated using Swashbuckle. I want to be able to omit certain methods fr

10条回答
  •  爱一瞬间的悲伤
    2020-11-30 20:34

    I would prefer to remove the dictionary entries for path items completely:

    var pathsToRemove = swaggerDoc.Paths
                    .Where(pathItem => !pathItem.Key.Contains("api/"))
                    .ToList();
    
    foreach (var item in pathsToRemove)
    {
        swaggerDoc.Paths.Remove(item.Key);
    }
    

    With this approach, you would not get "empty" items in the generated swagger.json definition.

提交回复
热议问题