某些方法的所有格式都没有显示net web api swagger respnse
我想以这种格式显示 . application/json, test/json, application/xml and text/xml
但它在某些api中仅显示 application/json and test/json . 我该如何解决这个问题?
如果api返回List和IEnumerable,那么它工作正常 . 但如果只处理某个类对象,那么它不会显示所有格式 .
听起来你只是在一些apis中遇到这个问题 .您应该比较您的api项目,特别是我们可以删除的 WebApiConfig 类,并添加如下格式:
WebApiConfig
public static void Register(HttpConfiguration config) { config.Formatters.Clear(); config.Formatters.Add(new BrowserJsonFormatter()); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); }
你可以在这里看到我的完整例子:https://github.com/heldersepu/SwashbuckleTest/blob/master/Swagger_Test/App_Start/WebApiConfig.cs#L33
1 回答
听起来你只是在一些apis中遇到这个问题 .
您应该比较您的api项目,特别是我们可以删除的
WebApiConfig
类,并添加如下格式:你可以在这里看到我的完整例子:https://github.com/heldersepu/SwashbuckleTest/blob/master/Swagger_Test/App_Start/WebApiConfig.cs#L33