3
現在、私のASP.NET MVC Web APIアプリケーション内でSwashbuckle 5.4.0を使用しようとしています。私がswaggerによって生成されたページ(rooturl/swagger経由)に行くと、ページは正しくロードされますが、メソッドは表示されません。私のプロジェクトを正しく動作する別のプロジェクトと比較すると、コードの違いを見つけることができます。私は何が欠けていますか? Swashbuckle 5.4.0 with ASP.NET MVC WebApi - スワッガーWebページ内にドキュメントがありません
Global.asaxの
namespace WebApiExperiment
{
public class SwaggerConfig
{
public static void Register()
{
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "Swagger Demo Api");
c.IncludeXmlComments(string.Format(@"{0}\bin\WebApiExperiment.XML",
System.AppDomain.CurrentDomain.BaseDirectory));
})
.EnableSwaggerUi();
}
}
}
Startup.cs
[assembly: OwinStartupAttribute(typeof(WebApiExperiment.Startup))]
namespace WebApiExperiment
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
}
:
SwaggerConfig.cs:ここ
あなたが問題に関連した.csファイルです
任意のファイルについてはnamespace WebApiExperiment
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
GlobalConfiguration.Configure(WebApiConfig.Register);
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
}
HomeController.cs(私のプロジェクト内の最も簡単かつ非常識なコントローラ)
namespace WebApiExperiment.Controllers
{
public class HomeController : ApiController
{
public IHttpActionResult Index(SendCodeViewModel sendView)
{
return Ok();
}
public IHttpActionResult About(SendCodeViewModel sendView)
{
return Ok("Your application description page.");
}
public IHttpActionResult Contact(SendCodeViewModel sendView)
{
return Ok("Your contact page.");
}
}
}
、ちょうど私が知っていると私はあなたを提供します。
いや、それは働きます!ありがとうございました!私が忘れてしまったのは、どの部分ですか? – Gab
@Gabは言うのは難しいですが、それはあなたのAPIのほうがAPIではないようです。ルーティングはWebApiの基本的な実装の一部です。私はあなたがApiControllersの前にコントローラを使用したと思います。これが理由です。ですから、WebApiについてのチュートリアルを読むと、すべてが明確になります。 SwashbucleはすべてのパブリックAPIメソッドを取得します。 –