NSwag和OWIN启动类定义

时间:2018-11-27 15:27:51

标签: c# asp.net-web-api swagger swagger-ui nswag

根据NSWAG文档和OWIN(OWIN Middleware),我应该打以下电话:

public void Configuration(IAppBuilder app)
{
    var config = new HttpConfiguration();

    var apiExplorer = GlobalConfiguration.Configuration.
                      AddVersionedApiExplorer(
            options =>
            {
                options.GroupNameFormat = "'v'VVV";
            });

    app.UseSwaggerUi3(typeof(Startup).Assembly, settings =>
    {
        // configure settings here
        // settings.GeneratorSettings.*: Generator settings and 
        // extension points settings.*: Routing and UI settings
    });

    WebApiConfig.Register(config);

    config.MapHttpAttributeRoutes();
    config.EnsureInitialized();

}

但是每次调用config.MapHttpAttributeRoutes();时,都会出现以下错误:

System.ArgumentException: 'An item with the same key has already been added.'

StackTrace也无济于事,因为我得到的只是:

at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, 
Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at System.Web.Http.HttpRouteCollection.Add(String name, IHttpRoute route)
at System.Web.Http.Routing.AttributeRoutingMapper.MapAttributeRoutes
(HttpConfiguration configuration, IInlineConstraintResolver
constraintResolver, IDirectRouteProvider directRouteProvider)
at System.Web.Http.HttpConfigurationExtensions.MapHttpAttributeRoute
(HttpConfiguration configuration)
at Esb.MyTime.WebApi.Startup.Configuration(IAppBuilder app) in
D:\Source\MyProject\App_Start\Startup.cs:line 33

就目前而言,我们有一个可用的NSwag解决方案,但是没有触发owin启动类,但是如果我更改代码以触发启动,它将忽略NSwag,因此我认为我会按照确切的说明进行操作关于如何使用OWIN来获得NSwag的信息,但到目前为止还算不上成功!

有人可以帮忙吗?

谢谢。

0 个答案:

没有答案