Unverified Commit dd6987c1 authored by Steve Smith's avatar Steve Smith Committed by GitHub

Merge pull request #8 from ardalis/ardalis/swagger

Adding Swagger
parents f2cb9398 4136bf9f
...@@ -39,7 +39,8 @@ namespace CleanArchitecture.Web.Api ...@@ -39,7 +39,8 @@ namespace CleanArchitecture.Web.Api
} }
// POST: api/ToDoItems // POST: api/ToDoItems
public async Task<IActionResult> Post([FromBody] ToDoItemDTO item) [HttpPost]
public IActionResult Post([FromBody] ToDoItemDTO item)
{ {
var todoItem = new ToDoItem() var todoItem = new ToDoItem()
{ {
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" /> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" PrivateAssets="All" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" PrivateAssets="All" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
...@@ -9,6 +9,7 @@ using Microsoft.Extensions.Configuration; ...@@ -9,6 +9,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using StructureMap; using StructureMap;
using Swashbuckle.AspNetCore.Swagger;
namespace CleanArchitecture.Web namespace CleanArchitecture.Web
{ {
...@@ -32,6 +33,11 @@ namespace CleanArchitecture.Web ...@@ -32,6 +33,11 @@ namespace CleanArchitecture.Web
services.AddMvc() services.AddMvc()
.AddControllersAsServices(); .AddControllersAsServices();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
});
var container = new Container(); var container = new Container();
container.Configure(config => container.Configure(config =>
...@@ -83,6 +89,15 @@ namespace CleanArchitecture.Web ...@@ -83,6 +89,15 @@ namespace CleanArchitecture.Web
app.UseStaticFiles(); app.UseStaticFiles();
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
app.UseMvc(routes => app.UseMvc(routes =>
{ {
routes.MapRoute( routes.MapRoute(
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<ul> <ul>
<li><a asp-area="" asp-controller="ToDo" asp-action="Populate">Load Sample To Do Items</a></li> <li><a asp-area="" asp-controller="ToDo" asp-action="Populate">Load Sample To Do Items</a></li>
<li><a asp-area="" asp-controller="ToDo" asp-action="Index">List To Do Items</a></li> <li><a asp-area="" asp-controller="ToDo" asp-action="Index">List To Do Items</a></li>
<li><a href="/swagger">API Documentation (Swagger)</a></li>
</ul> </ul>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment