2. Install the Swagger package in the Package Manager window
Install-Package Swashbuckle.AspNetCore3. add swagger generator to services collection which is the dependency injection container
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
});
4. setup the swagger in the configure method
// enable the swagger middleware
app.UseSwagger();
// Enable middleware to serve swagger-ui
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
5. launch the app and view the swagger ui from the link below, please note the port will be different
https://localhost:{port}/swagger/index.html
for my local development i had the following
https://localhost:44392/swagger/index.html
No comments:
Post a Comment