diff --git a/DemoDotnetWebApi/Controllers/PasswordController.cs b/DemoDotnetWebApi/Controllers/PasswordController.cs deleted file mode 100644 index 896c215..0000000 --- a/DemoDotnetWebApi/Controllers/PasswordController.cs +++ /dev/null @@ -1,24 +0,0 @@ -using DemoDotnetWebApi.Interfaces; -using Microsoft.AspNetCore.Mvc; - -namespace DemoDotnetWebApi.Controllers; - -[ApiController] -[Route("api/v1/[controller]")] -public class PasswordController : ControllerBase -{ - private readonly ILogger _logger; - private readonly IPasswordGenerator _passwordGenerator; - - public PasswordController(ILogger logger, IPasswordGenerator passwordGenerator) - { - _logger = logger; - _passwordGenerator = passwordGenerator; - } - - [HttpGet] - public string Get() - { - return _passwordGenerator.Generate(); - } -} diff --git a/DemoDotnetWebApi/Program.cs b/DemoDotnetWebApi/Program.cs index 1b8cd58..ce130b5 100644 --- a/DemoDotnetWebApi/Program.cs +++ b/DemoDotnetWebApi/Program.cs @@ -8,24 +8,26 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); -builder.Services.AddControllers(); -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); +builder.Services.AddOpenApi(); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { - app.UseSwagger(); - app.UseSwaggerUI(); + app.MapOpenApi(); + app.UseSwaggerUI(options => + { + options.SwaggerEndpoint("/openapi/v1.json", "Demo API"); + }); } app.UseHttpsRedirection(); -app.UseAuthorization(); - -app.MapControllers(); +app.MapGet("/api/v1/password", (IPasswordGenerator _passwordGenerator) => +{ + return _passwordGenerator.Generate(); +}) +.WithName("GetPassword"); app.Run();