Skip to content

Commit

Permalink
Startup: adds Swagger documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
murphynd committed Oct 27, 2020
1 parent acdf00a commit 2e03f07
Show file tree
Hide file tree
Showing 15 changed files with 494 additions and 64 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ user_name
authenticate user to only mess with what they have written.

search places (FOR FUN)

For Docmuentation, run and visit:
http://localhost:5003/swagger/index.html
28 changes: 15 additions & 13 deletions Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Mvc.Versioning;
using Swashbuckle.AspNetCore.Swagger;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;


namespace TravelApi
{
Expand All @@ -18,30 +21,29 @@ public Startup(IConfiguration configuration)

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddApiVersioning(o => { })
services.AddDbContext<TravelApiContext>(opt =>
opt.UseMySql(Configuration.GetConnectionString("DefaultConnection")));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
opt.UseMySql(Configuration.GetConnectionString("DefaultConnection")));
services.AddMvc();
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)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
app.UseSwagger();
app.UseSwaggerUI(c =>
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

// app.UseHttpsRedirection();
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
app.UseMvc();
}
}
}
}


//http://localhost:5003/swagger/v1/swagger.json
1 change: 1 addition & 0 deletions TravelApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>

</Project>
Loading

0 comments on commit 2e03f07

Please sign in to comment.