我写了一个asp web-api,我已经使用这个类为api添加了版本.
我的路线看起来像这样:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{namespace}/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Services.Replace(typeof(IHttpControllerSelector), new NamespaceHttpControllerSelector(config));
Run Code Online (Sandbox Code Playgroud)
所以我可以访问 https://localhost:44301/v1/test
我现在正在尝试添加Swagger来生成一些api文档(实际上我正在使用Swashbuckle Nuget包)
当我浏览到/swagger页面加载但出现所有控制器的错误时:
Unable to read api 'TestController' from path https://localhost:44301/swagger/api-docs/TestController (server returned undefined)
Run Code Online (Sandbox Code Playgroud)
如果我浏览到https://localhost:44301/swagger/api-docs/TestController它,则会出现NullReferenceException一个堆栈跟踪:
at Swashbuckle.Swagger.OperationGenerator.CreateParameter(ApiParameterDescription apiParamDesc, String apiPath)
at Swashbuckle.Swagger.OperationGenerator.<>c__DisplayClass2.<ApiDescriptionToOperation>b__1(ApiParameterDescription paramDesc)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Swashbuckle.Swagger.OperationGenerator.ApiDescriptionToOperation(ApiDescription apiDescription)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Swashbuckle.Swagger.ApiExplorerAdapter.CreateApi(IGrouping`2 …Run Code Online (Sandbox Code Playgroud)