Skip to content

Commit

Permalink
Optimize api documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager committed Jun 17, 2024
1 parent a6477f3 commit 69c1802
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ public async Task<ActionResult> GetMfaActivationAsync(
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <response code="204">Password changed</response>
/// <response code="204">Mfa activated</response>
/// <response code="400">Mfa workflow error</response>
/// <response code="500">Unexpected error</response>
[HttpPost]
[Route("Mfa/Activate")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(MfaErrorResponseDto))]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult> ActivateMfaAsync(
[Required][FromBody] TimeBasedOneTimeTokenRequestDto request,
Expand All @@ -135,7 +137,7 @@ public async Task<ActionResult> ActivateMfaAsync(

case MfaActivationResult.AlreadyActive:
case MfaActivationResult.InvalidCode:
return StatusCode(StatusCodes.Status400BadRequest, new { error = mfaResult.ToString() });
return StatusCode(StatusCodes.Status400BadRequest, new MfaErrorResponseDto { Error = mfaResult.ToString() });

default:
return StatusCode(StatusCodes.Status500InternalServerError);
Expand All @@ -148,11 +150,13 @@ public async Task<ActionResult> ActivateMfaAsync(
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <response code="204">Password changed</response>
/// <response code="204">Mfa deactivated</response>
/// <response code="400">Mfa workflow error</response>
/// <response code="500">Unexpected error</response>
[HttpPost]
[Route("Mfa/Deactivate")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(MfaErrorResponseDto))]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult> DeactivateMfaAsync(
[Required][FromBody] TimeBasedOneTimeTokenRequestDto request,
Expand All @@ -177,7 +181,7 @@ public async Task<ActionResult> DeactivateMfaAsync(

case MfaDeactivationResult.NotActive:
case MfaDeactivationResult.InvalidCode:
return StatusCode(StatusCodes.Status400BadRequest, new { error = mfaResult.ToString() });
return StatusCode(StatusCodes.Status400BadRequest, new MfaErrorResponseDto { Error = mfaResult.ToString() });

default:
return StatusCode(StatusCodes.Status500InternalServerError);
Expand Down
7 changes: 7 additions & 0 deletions src/Nager.Authentication.AspNet/Dtos/MfaErrorResponseDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Nager.Authentication.AspNet.Dtos
{
public class MfaErrorResponseDto
{
public string Error { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<Nullable>enable</Nullable>

<Version>2.0.1</Version>
<Version>2.0.2</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 69c1802

Please sign in to comment.