EnableSwagger 混乱

EnableSwagger confusion

我无法理解 visual studio 中的 Swagger & Owin 模板。

我基本上一开始就卡住了:

var httpConfiguration = new HttpConfiguration();
// Configure Swagger UI
httpConfiguration
    .EnableSwagger(c => c.SingleApiVersion("v1", "Test API"))
        .EnableSwaggerUi();

我感到困惑的是 SingleApiVersion 的 lambda 函数似乎不知从何而来。

这如何组合在一起?

我可以看到 EnableSwagger 扩展方法有两个重载:

(Action<SwaggerDocsConfig> configure = null) //(this is also confusing) and
(string routeTemplate, Action<SwaggerDocsConfig> configure = null)

所以我可以看到 SingleApiVersion 来自 SwaggerDocsConfig 但是如何!

谢谢,对于这个基本问题感到抱歉,我想我在试图理解这个问题时让自己很头疼。

通过使用 SwaggerDocsConfig 作为传递给 Action<T> 的委托作为 Action<SwaggerDocsConfig>,可以设置子成员 SingleApiVersion,因为它 returns 没有值。 SwaggerDocsConfig 的实例在 HttpConfigurationExtensions class.

上的 EnableSwagger 方法的构造函数中实例化