{"id":284565,"date":"2017-04-06T19:00:03","date_gmt":"2017-04-06T15:00:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=284565"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=284565","title":{"rendered":"ASP.NET Core: \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u044b\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0432\u0435\u0431-API ASP.NET \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Swagger"},"content":{"rendered":"<p>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0431\u044b\u0432\u0430\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 API. \u0421\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0438 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u044b\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0432\u0435\u0431-API \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c Swagger \u0441 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0435\u0439 Swashbuckle .NET Core \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u043a\u0430\u043a \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u0440\u0443 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 NuGet \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c Startup.cs.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/b78\/039\/55c\/b7803955cc0e4e25981739bf67023d5c.jpg\"\/><br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u0412\u0442\u043e\u0440\u043e\u0439 \u0446\u0438\u043a\u043b \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e ASP.NET Core<\/h2>\n<p>  1.<a href=\"https:\/\/habrahabr.ru\/company\/microsoft\/blog\/319482\/\"> \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0445 \u0441\u043b\u0443\u0436\u0431 \u0434\u043b\u044f \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439<\/a>.<br \/>  2. <a href=\"https:\/\/habrahabr.ru\/company\/microsoft\/blog\/324312\/\">\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 ASP.NET Core \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e dotnet watch<\/a>.<br \/>  3. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u044b\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0432\u0435\u0431-API ASP.NET \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Swagger.<br \/>  4. \u041e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0432\u0435\u0431-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f .NET (OWIN).<br \/>  5. \u0412\u044b\u0431\u043e\u0440 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 .NET \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435.<\/p>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u0438:  <\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/domaindrivendev\/Ahoy\">Swashbuckle<\/a> \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 Swagger \u0434\u043b\u044f \u0432\u0435\u0431-API, \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e ASP.NET Core MVC.<\/li>\n<li><a href=\"http:\/\/swagger.io\/\">Swagger<\/a> \u2014 \u044d\u0442\u043e \u043c\u0430\u0448\u0438\u043d\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 RESTful API, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0445 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 SDK \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f.<\/li>\n<\/ul>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u0443\u0447\u0435\u0431\u043d\u044b\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043f\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430 <a href=\"https:\/\/docs.microsoft.com\/en-us\/aspnet\/core\/tutorials\/first-web-api\">\u00ab\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432\u0435\u0431-API \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e ASP.NET Core MVC \u0438 Visual Studio\u00bb<\/a>. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0441 <a href=\"https:\/\/github.com\/aspnet\/Docs\/tree\/master\/aspnetcore\/tutorials\/first-web-api\/sample\">GitHub<\/a>.<\/p>\n<h2>\u041d\u0430\u0447\u0430\u043b\u043e \u0440\u0430\u0431\u043e\u0442\u044b<\/h2>\n<p>  Swashbuckle \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432:  <\/p>\n<ul>\n<li><i>Swashbuckle.SwaggerGen<\/i>: \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 JSON Swagger, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043c\u0435\u0442\u043e\u0434\u044b, \u0442\u0438\u043f\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/li>\n<li><i>Swashbuckle.SwaggerUI<\/i>: \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 Swagger, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u0435\u0431-API \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u043e\u0431\u0449\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/li>\n<\/ul>\n<p>  <\/p>\n<h2>\u041f\u0430\u043a\u0435\u0442\u044b NuGet<\/h2>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c Swashbuckle, \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432:  <\/p>\n<ul>\n<li>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430 \u043f\u0430\u043a\u0435\u0442\u043e\u0432:<br \/> \n<pre><code class=\"bash\">Install-Package Swashbuckle -Pre<\/code><\/pre>\n<\/li>\n<li>\u0412 Visual Studio:<br \/>   o \u041f\u0440\u0430\u0432\u043e\u0439 \u043a\u043d\u043e\u043f\u043a\u043e\u0439 \u043c\u044b\u0448\u0438 \u0449\u0435\u043b\u043a\u043d\u0438\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 \u041e\u0431\u043e\u0437\u0440\u0435\u0432\u0430\u0442\u0435\u043b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 &gt; \u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043a\u0435\u0442\u0430\u043c\u0438 NuGet.<br \/>   o \u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0432 \u043f\u043e\u043b\u0435 \u043f\u043e\u0438\u0441\u043a\u0430 \u0442\u0435\u043a\u0441\u0442 Swashbuckle.<br \/>   o \u041f\u043e\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0444\u043b\u0430\u0436\u043e\u043a Include prerelease (\u0412\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u043f\u0443\u0441\u043a).<br \/>   o \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0443\u043a\u0430\u0436\u0438\u0442\u0435 nuget.org.<br \/>   o \u041a\u043e\u0441\u043d\u0438\u0442\u0435\u0441\u044c Swashbuckle package (\u043f\u0430\u043a\u0435\u0442 Swashbuckle), \u0430 \u0437\u0430\u0442\u0435\u043c \u2014 Install (\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c).<\/li>\n<\/ul>\n<p>  <\/p>\n<h2>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 Swagger \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435 \u0435\u0433\u043e \u0432 \u0441\u0432\u044f\u0437\u0443\u044e\u0449\u0435\u0435 \u041f\u041e<\/h2>\n<p>  \u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 SwaggerGen \u0432 \u043d\u0430\u0431\u043e\u0440 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 Configure \u0438 ConfigureServices, \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0439\u0442\u0435 \u0441\u0432\u044f\u0437\u0443\u044e\u0449\u0435\u0435 \u041f\u041e \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 JSON \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 Swagger.<\/p>\n<pre><code class=\"cs\">public void ConfigureServices(IServiceCollection services) {     \/\/ Add framework services.     services.AddMvc();      services.AddLogging();      \/\/ Add our repository type     services.AddSingleton&lt;ITodoRepository, TodoRepository&gt;();      \/\/ Inject an implementation of ISwaggerProvider with defaulted settings applied     services.AddSwaggerGen(); }  \/\/ This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {     app.UseMvcWithDefaultRoute();      \/\/ Enable middleware to serve generated Swagger as a JSON endpoint     app.UseSwagger();      \/\/ Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)     app.UseSwaggerUi();  }<\/code><\/pre>\n<p>  \u0412 Visual Studio \u043d\u0430\u0436\u043c\u0438\u0442\u0435 F5 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u043f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043a<code> http:\/\/localhost:&lt;random_port&gt;\/swagger\/v1\/swagger.json<\/code>. \u0417\u0434\u0435\u0441\u044c \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438.<\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/b> \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u044b Microsoft Edge, Google Chrome \u0438 Firefox \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b JSON \u0431\u0435\u0437 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a. \u0414\u043b\u044f Chrome \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0447\u0442\u0435\u043d\u0438\u044f. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 JavaScript.<\/p>\n<pre><code class=\"javascript\">{    &quot;swagger&quot;: &quot;2.0&quot;,    &quot;info&quot;: {        &quot;version&quot;: &quot;v1&quot;,        &quot;title&quot;: &quot;API V1&quot;    },    &quot;basePath&quot;: &quot;\/&quot;,    &quot;paths&quot;: {        &quot;\/api\/Todo&quot;: {        &quot;get&quot;: {            &quot;tags&quot;: [            &quot;Todo&quot;            ],            &quot;operationId&quot;: &quot;ApiTodoGet&quot;,            &quot;consumes&quot;: [],            &quot;produces&quot;: [            &quot;text\/plain&quot;,            &quot;application\/json&quot;,            &quot;text\/json&quot;            ],            &quot;responses&quot;: {            &quot;200&quot;: {                &quot;description&quot;: &quot;OK&quot;,                &quot;schema&quot;: {                &quot;type&quot;: &quot;array&quot;,                &quot;items&quot;: {                    &quot;$ref&quot;: &quot;#\/definitions\/TodoItem&quot;                }                }            }            },            &quot;deprecated&quot;: false        },        &quot;post&quot;: {            ...        }        },        &quot;\/api\/Todo\/{id}&quot;: {        &quot;get&quot;: {            ...        },        &quot;put&quot;: {            ...        },        &quot;delete&quot;: {            ...    },    &quot;definitions&quot;: {        &quot;TodoItem&quot;: {        &quot;type&quot;: &quot;object&quot;,        &quot;properties&quot;: {            &quot;key&quot;: {            &quot;type&quot;: &quot;string&quot;            },            &quot;name&quot;: {            &quot;type&quot;: &quot;string&quot;            },            &quot;isComplete&quot;: {            &quot;type&quot;: &quot;boolean&quot;            }        }        }    },    &quot;securityDefinitions&quot;: {}    }<\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 Swagger, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0433\u043e \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443:<code> http:\/\/localhost:&lt;random_port&gt;\/swagger\/ui<\/code>.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/256\/a27\/714\/256a27714b044acc96d34738a4ff8ef9.png\"\/><br \/>  \u041a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 ToDo \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u041a\u043e\u0441\u043d\u0438\u0442\u0435\u0441\u044c \u043c\u0435\u0442\u043e\u0434\u0430, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0440\u0430\u0437\u0434\u0435\u043b, \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438 \u043d\u0430\u0436\u043c\u0438\u0442\u0435 \u00abTry it out!\u00bb (\u041f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c).<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/572\/e85\/13a\/572e8513a6444f4dbc9b6443cd994998.png\"\/><\/p>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u043e\u0441\u0442\u044c<\/h2>\n<p>  Swagger \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u0435\u0437 \u0442\u0440\u0443\u0434\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c API, \u043d\u043e \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0432\u0438\u0434\u0430 \u0438 \u044f\u0437\u044b\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430.<\/p>\n<h4>\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 API<\/h4>\n<p>  \u041c\u0435\u0442\u043e\u0434 <code>ConfigureSwaggerGen<\/code> \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u0439 \u043e\u0431 \u0430\u0432\u0442\u043e\u0440\u0435 \u0438 \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f.<\/p>\n<pre><code class=\"cs\">services.ConfigureSwaggerGen(options =&gt;    {        options.SingleApiVersion(new Info        {            Version = &quot;v1&quot;,            Title = &quot;ToDo API&quot;,            Description = &quot;A simple example ASP.NET Core Web API&quot;,            TermsOfService = &quot;None&quot;,            Contact = new Contact { Name = &quot;Shayne Boyer&quot;, Email = &quot;&quot;, Url = &quot;http:\/\/twitter.com\/spboyer&quot;},            License = new License { Name = &quot;Use under LICX&quot;, Url = &quot;http:\/\/url.com&quot; }        });    });<\/code><\/pre>\n<p>  \u041d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 Swagger \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/fd6\/29c\/6b1\/fd629c6b12d14311b37d0b2dfa6da59e.png\"\/><\/p>\n<h4>\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 XML<\/h4>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 XML, \u043f\u0440\u0430\u0432\u043e\u0439 \u043a\u043d\u043e\u043f\u043a\u043e\u0439 \u043c\u044b\u0448\u0438 \u0449\u0435\u043b\u043a\u043d\u0438\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 Visual Studio \u0438 \u0432\u044b\u0431\u0435\u0440\u0438\u0442\u0435 <b>Properties<\/b> (\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430). \u0417\u0430\u0442\u0435\u043c \u043f\u043e\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0444\u043b\u0430\u0436\u043e\u043a<b> XML Documentation file<\/b> (\u0424\u0430\u0439\u043b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 XML) \u043f\u043e\u0434 \u0440\u0430\u0437\u0434\u0435\u043b\u043e\u043c <b>Output Settings<\/b> (\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0432\u044b\u0445\u043e\u0434\u0430).<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/fee\/83d\/697\/fee83d6970984ab2ad62cb5e647a0ba0.png\"\/><\/p>\n<p>  \u0421\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u0439\u0442\u0435 Swagger \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 XML.<\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/b> \u0434\u043b\u044f Linux \u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c, \u043d\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0445 \u043a \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u0443 Windows, \u0438\u043c\u0435\u043d\u0430 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b \u043a \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0438\u0441\u043a \u0444\u0430\u0439\u043b\u0430 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>ToDoApi.XML<\/code> \u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d \u0432 Windows, \u043d\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d \u0432 CentOS.<\/p>\n<pre><code class=\"cs\">\/\/ This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) {     \/\/ Add framework services.     services.AddMvc();      services.AddLogging();      \/\/ Add our repository type.     services.AddSingleton&lt;ITodoRepository, TodoRepository&gt;();      \/\/ Inject an implementation of ISwaggerProvider with defaulted settings applied.     services.AddSwaggerGen();      \/\/ Add the detail information for the API.     services.ConfigureSwaggerGen(options =&gt;     {         options.SingleApiVersion(new Info         {             Version = &quot;v1&quot;,             Title = &quot;ToDo API&quot;,             Description = &quot;A simple example ASP.NET Core Web API&quot;,             TermsOfService = &quot;None&quot;,             Contact = new Contact { Name = &quot;Shayne Boyer&quot;, Email = &quot;&quot;, Url = &quot;http:\/\/twitter.com\/spboyer&quot;},             License = new License { Name = &quot;Use under LICX&quot;, Url = &quot;http:\/\/url.com&quot; }         });          \/\/Determine base path for the application.         var basePath = PlatformServices.Default.Application.ApplicationBasePath;          \/\/Set the comments path for the swagger json and ui.         var xmlPath = Path.Combine(basePath, &quot;TodoApi.xml&quot;);          options.IncludeXmlComments(xmlPath);     }); }  \/\/ This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {     app.UseStaticFiles();      app.UseMvcWithDefaultRoute();      \/\/ Enable middleware to serve generated Swagger as a JSON endpoint.     app.UseSwagger();      \/\/ Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)     app.UseSwaggerUi();      } <\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435 ApplicationBasePath \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043f\u0443\u0442\u044c \u043a \u0431\u0430\u0437\u043e\u0432\u043e\u043c\u0443 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043a \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c XML. <code>TodoApi.xml<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0438\u043c\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 XML \u0441 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438 \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0438\u043c\u0435\u043d\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0441 \u0442\u0440\u0435\u043c\u044f \u043a\u043e\u0441\u044b\u043c\u0438 \u0447\u0435\u0440\u0442\u0430\u043c\u0438, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 Swagger: \u043a \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0443 \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435.<\/p>\n<pre><code class=\"cs\">\/\/\/ &lt;summary&gt; \/\/\/ Deletes a specific TodoItem. \/\/\/ &lt;\/summary&gt; \/\/\/ &lt;param name=&quot;id&quot;&gt;&lt;\/param&gt; [HttpDelete(&quot;{id}&quot;)] public void Delete(string id) {     TodoItems.Remove(id); }<\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/780\/f08\/4be\/780f084be66a4e97a714a60c3b0d9afc.png\"\/><\/p>\n<p>  \u041f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b JSON, \u0438 \u0432 \u043d\u0435\u043c \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u044d\u0442\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438.<\/p>\n<pre><code class=\"javascript\">&quot;delete&quot;: {   &quot;tags&quot;: [     &quot;Todo&quot;   ],   &quot;summary&quot;: &quot;Deletes a specific TodoItem&quot;,   &quot;operationId&quot;: &quot;ApiTodoByIdDelete&quot;,   &quot;consumes&quot;: [],   &quot;produces&quot;: [],   &quot;parameters&quot;: [     {       &quot;name&quot;: &quot;id&quot;,       &quot;in&quot;: &quot;path&quot;,       &quot;description&quot;: &quot;&quot;,       &quot;required&quot;: true,       &quot;type&quot;: &quot;string&quot;     }   ],   &quot;responses&quot;: {     &quot;204&quot;: {       &quot;description&quot;: &quot;No Content&quot;     }   },   &quot;deprecated&quot;: false }<\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c <code>&lt;remarks \/&gt;<\/code>, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0431\u043e\u0439 \u0442\u0435\u043a\u0441\u0442, \u043e\u0431\u044a\u0435\u043a\u0442 JSON \u0438\u043b\u0438 XML \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<pre><code class=\"cs\">\/\/\/ &lt;summary&gt; \/\/\/ Creates a TodoItem. \/\/\/ &lt;\/summary&gt; \/\/\/ &lt;remarks&gt; \/\/\/ Note that the key is a GUID and not an integer. \/\/\/   \/\/\/     POST \/Todo \/\/\/     { \/\/\/        &quot;key&quot;: &quot;0e7ad584-7788-4ab1-95a6-ca0a5b444cbb&quot;, \/\/\/        &quot;name&quot;: &quot;Item1&quot;, \/\/\/        &quot;isComplete&quot;: true \/\/\/     } \/\/\/  \/\/\/ &lt;\/remarks&gt; \/\/\/ &lt;param name=&quot;item&quot;&gt;&lt;\/param&gt; \/\/\/ &lt;returns&gt;New Created Todo Item&lt;\/returns&gt; \/\/\/ &lt;response code=&quot;201&quot;&gt;Returns the newly created item&lt;\/response&gt; \/\/\/ &lt;response code=&quot;400&quot;&gt;If the item is null&lt;\/response&gt; [HttpPost] [ProducesResponseType(typeof(TodoItem), 201)] [ProducesResponseType(typeof(TodoItem), 400)] public IActionResult Create([FromBody, Required] TodoItem item) {     if (item == null)     {         return BadRequest();     }     TodoItems.Add(item);     return CreatedAtRoute(&quot;GetTodo&quot;, new { id = item.Key }, item); }<\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043a\u0430\u043a \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c \u0443\u043b\u0443\u0447\u0448\u0438\u043b\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/9e6\/1d4\/e6c\/9e61d4e6cb524066b0a00599eb1bbbaa.png\"\/><\/p>\n<h4>DataAnnotations<\/h4>\n<p>  \u0412 API \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 <code>System.ComponentModel.DataAnnotations<\/code>, \u0447\u0442\u043e\u0431\u044b \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 Swagger.<\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>[Required]<\/code> \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443 <code>Name<\/code> \u043a\u043b\u0430\u0441\u0441\u0430 <code>TodoItem<\/code> \u043c\u0435\u043d\u044f\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e ModelSchema \u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435. \u0410\u0433\u0435\u043d\u0442\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 <code>[Produces(&quot;application\/json&quot;)]<\/code>, <code>RegularExpression<\/code> \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043b\u0443\u0436\u0430\u0442 \u0434\u043b\u044f \u0443\u0442\u043e\u0447\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u043e\u0439 \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435. \u0427\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u0434\u0435, \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0438\u043b\u0438 API.<\/p>\n<pre><code class=\"cs\">using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations;  namespace TodoApi.Models {     public class TodoItem     {         public string Key { get; set; }         [Required]         public string Name { get; set; }         [DefaultValue(false)]         public bool IsComplete { get; set; }     } }<\/code><\/pre>\n<h4>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u043e\u0442\u0432\u0435\u0442\u043e\u0432<\/h4>\n<p>  \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u0441\u043e\u0437\u0434\u0430\u044e\u0449\u0438\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0443\u0434\u0435\u043b\u044f\u044e\u0442 \u043e\u0441\u043e\u0431\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0432\u044b\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0442\u0438\u043f\u0430\u043c \u043e\u0442\u0432\u0435\u0442\u043e\u0432, \u043a\u043e\u0434\u0430\u043c \u043e\u0448\u0438\u0431\u043e\u043a (\u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u043d\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435). \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 XML \u0438 DataAnnotations.<\/p>\n<p>  \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>Create()<\/code>. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043d \u0432\u044b\u0434\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442 \u00ab201 Created\u00bb (\u0435\u0441\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u043d) \u0438\u043b\u0438 \u00ab204 No Content\u00bb (\u0435\u0441\u043b\u0438 \u0432 \u0442\u0435\u043b\u043e POST \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u044b \u0434\u0430\u043d\u043d\u044b\u0435). \u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0434\u0441\u043a\u0430\u0436\u0435\u0442, \u043a\u0430\u043a\u0438\u043c \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u0442 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u043e\u0442\u0432\u0435\u0442. \u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430.<\/p>\n<pre><code class=\"cs\">\/\/\/ &lt;summary&gt; \/\/\/ Creates a TodoItem. \/\/\/ &lt;\/summary&gt; \/\/\/ &lt;remarks&gt; \/\/\/ Note that the key is a GUID and not an integer. \/\/\/   \/\/\/     POST \/Todo \/\/\/     { \/\/\/        &quot;key&quot;: &quot;0e7ad584-7788-4ab1-95a6-ca0a5b444cbb&quot;, \/\/\/        &quot;name&quot;: &quot;Item1&quot;, \/\/\/        &quot;isComplete&quot;: true \/\/\/     } \/\/\/  \/\/\/ &lt;\/remarks&gt; \/\/\/ &lt;param name=&quot;item&quot;&gt;&lt;\/param&gt; \/\/\/ &lt;returns&gt;New Created Todo Item&lt;\/returns&gt; \/\/\/ &lt;response code=&quot;201&quot;&gt;Returns the newly created item&lt;\/response&gt; \/\/\/ &lt;response code=&quot;400&quot;&gt;If the item is null&lt;\/response&gt; [HttpPost] [ProducesResponseType(typeof(TodoItem), 201)] [ProducesResponseType(typeof(TodoItem), 400)] public IActionResult Create([FromBody, Required] TodoItem item) {     if (item == null)     {         return BadRequest();     }     TodoItems.Add(item);     return CreatedAtRoute(&quot;GetTodo&quot;, new { id = item.Key }, item); } <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/a8f\/861\/ff0\/a8f861ff05c74f26990f3720d48b4423.png\"\/><\/p>\n<h4>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430<\/h4>\n<p>  \u0413\u043e\u0442\u043e\u0432\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0438 \u0443\u0434\u043e\u0431\u043d\u044b\u0439, \u043d\u043e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0434\u043b\u044f API \u0432\u044b \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0431\u0440\u0435\u043d\u0434 \u0438\u043b\u0438 \u0444\u0438\u0440\u043c\u0435\u043d\u043d\u044b\u0439 \u0441\u0442\u0438\u043b\u044c.<\/p>\n<p>  \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 Swashbuckle. \u0412\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0434\u043b\u044f \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 \u0432\u0435\u0431-API, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0430\u043f\u043e\u043a \u0434\u043b\u044f \u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0443 \u043f\u0430\u043a\u0435\u0442 NuGet <code>\u00abMicrosoft.AspNetCore.StaticFiles\u00bb: \u00ab1.0.0-*\u00bb<\/code>.<\/p>\n<p>  \u0412\u043a\u043b\u044e\u0447\u0438\u0442\u0435 \u0441\u0432\u044f\u0437\u0443\u044e\u0449\u0435\u0435 \u041f\u041e \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432.<\/p>\n<pre><code class=\"cs\">\/\/ This method gets called by the runtime. Use this method to configure the HTTP request pipeline.    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)    {        \/\/ Enable static files middleware.        app.UseStaticFiles();         app.UseMvcWithDefaultRoute();         \/\/ Enable middleware to serve generated Swagger as a JSON endpoint        app.UseSwagger();         \/\/ Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)        app.UseSwaggerUi();    } <\/code><\/pre>\n<p>  \u0412\u043e\u0437\u044c\u043c\u0438\u0442\u0435 \u0444\u0430\u0439\u043b <i>index.html<\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 Swagger, \u0438\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f Github <code>&lt;https:\/\/github.com\/domaindrivendev\/Ahoy\/tree\/master\/test\/WebSites\/CustomizedUi\/wwwroot\/swagger\/ui&gt;<\/code>_ \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u0435 \u0435\u0433\u043e \u0432 \u043f\u0430\u043f\u043a\u0443 <code>wwwroot\/swagger\/ui<\/code>, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b <code>custom.css<\/code> \u0432 \u0442\u043e\u0439 \u0436\u0435 \u043f\u0430\u043f\u043a\u0435.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/09c\/6b9\/b1d\/09c6b9b1d1cd4f57b71afb8712b9ccef.png\"\/><\/p>\n<p>  \u0421\u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 <i>custom.css<\/i> \u0432 \u0444\u0430\u0439\u043b\u0435 <i>index.html<\/i>.<br \/>  <code>\/&gt;<\/code><\/p>\n<p>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c CSS \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043e\u0431\u0440\u0430\u0437\u0435\u0446 \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<p>  <i>\u0424\u0430\u0439\u043b custom.css<\/i>  <\/p>\n<pre><code class=\"css\">.swagger-section #header {     border-bottom: 1px solid #000000;     font-style: normal;     font-weight: 400;     font-family: &quot;Segoe UI Light&quot;,&quot;Segoe WP Light&quot;,&quot;Segoe UI&quot;,&quot;Segoe WP&quot;,Tahoma,Arial,sans-serif;     background-color: black; }  .swagger-section #header h1 {     text-align: center;     font-size: 20px;     color: white; }&lt;\/code&gt;  &lt;i&gt;\u0422\u0435\u043b\u043e index.html&lt;\/i&gt; &lt;source lang=&quot;css&quot;&gt;&lt;body class=&quot;swagger-section&quot;&gt;    &lt;div id=&quot;header&quot;&gt;     &lt;h1&gt;ToDo API Documentation&lt;\/h1&gt;    &lt;\/div&gt;     &lt;div id=&quot;message-bar&quot; class=&quot;swagger-ui-wrap&quot; data-sw-translate&gt;&nbsp;&lt;\/div&gt;    &lt;div id=&quot;swagger-ui-container&quot; class=&quot;swagger-ui-wrap&quot;&gt;&lt;\/div&gt; &lt;\/body&gt;<\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/333\/849\/bf8\/333849bf8ce347aa83d3ef425a7a0686.png\"\/><\/p>\n<p>  \u041d\u043e \u044d\u0442\u043e \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0451, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435\u0439. \u0412\u0435\u0441\u044c \u043f\u0435\u0440\u0435\u0447\u0435\u043d\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 <a href=\"https:\/\/github.com\/swagger-api\/swagger-ui\">GitHub \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 Swagger UI<\/a>.<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/325872\/\"> https:\/\/habrahabr.ru\/post\/325872\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0431\u044b\u0432\u0430\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 API. \u0421\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0438 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u044b\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0432\u0435\u0431-API \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c Swagger \u0441 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0435\u0439 Swashbuckle .NET Core \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u043a\u0430\u043a \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u0440\u0443 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 NuGet \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c Startup.cs.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/b78\/039\/55c\/b7803955cc0e4e25981739bf67023d5c.jpg\"\/>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-284565","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=284565"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284565\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}