Skip to content

Commit

Permalink
load xml doc to swagger. Ref: https://learn.microsoft.com/en-us/aspne…
Browse files Browse the repository at this point in the history
  • Loading branch information
jicking committed Apr 17, 2024
1 parent b3b9091 commit 4d028f2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions JixMinApi/Features/Todo/TodoEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public static async Task<Ok<TodoDto[]>> GetAllTodosAsync(IMediator mediator)
return TypedResults.Ok(todos?.ToArray());
}

/// <summary>
/// Fetches a todo by Id
/// </summary>
public static async Task<Results<BadRequest<ValidationErrorDto>, NotFound, Ok<TodoDto>>> GetTodoByIdAsync(Guid id, IMediator mediator)
{
if (id == Guid.Empty)
Expand All @@ -79,6 +82,21 @@ public static async Task<Results<BadRequest<ValidationErrorDto>, NotFound, Ok<To
return TypedResults.Ok(todo);
}

/// <summary>
/// Creates a new todo
/// </summary>
/// <remarks>
/// Sample request:
///
/// POST /Todo
/// {
/// "name": "Item #1",
/// "isComplete": true
/// }
///
/// </remarks>
/// <response code="201">Returns the newly created item</response>
/// <response code="400">Invalid payload</response>
public static async Task<Results<Created<TodoDto>, BadRequest>> CreateTodoAsync(TodoCreateDto input, IMediator mediator)
{
var result = await mediator.Send(new CreateTodoCommand(input));
Expand Down
2 changes: 2 additions & 0 deletions JixMinApi/JixMinApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
<UserSecretsId>d4957f71-7a37-4e19-a3a2-7d24ed38f9c4</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
Expand Down
5 changes: 5 additions & 0 deletions JixMinApi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using JixMinApi.Features.Todo;
using Microsoft.OpenApi.Models;
using System.Reflection;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -13,6 +14,10 @@
Title = "JixMinApi Demo",
Description = "A simple minimal API Demo that uses vertical slice architecture.",
});

var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
options.IncludeXmlComments(xmlPath);
});

builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(Program).Assembly));
Expand Down

0 comments on commit 4d028f2

Please sign in to comment.