Specify API returns types for swagger

This commit is contained in:
2025-06-16 20:28:37 +02:00
parent b989c43ec3
commit bcbf76fda6
10 changed files with 35 additions and 14 deletions

View File

@@ -16,7 +16,9 @@ public static class CreateCar
{
return builder
.MapPost("cars", Endpoint)
.WithTags("Cars");
.WithTags("Cars")
.Produces<Response>(201)
.ProducesValidationProblem();
}
public class Validator : AbstractValidator<Request>

View File

@@ -8,7 +8,9 @@ public static class DeleteCar
{
return builder
.MapDelete("cars/{id:guid}", Endpoint)
.WithTags("Cars");
.WithTags("Cars")
.Produces(204)
.Produces(404);
}
public static async Task<IResult> Endpoint(

View File

@@ -1,4 +1,5 @@
using Vegasco.Server.Api.Persistence;
using Microsoft.AspNetCore.Http.HttpResults;
using Vegasco.Server.Api.Persistence;
namespace Vegasco.Server.Api.Cars;
@@ -10,7 +11,10 @@ public static class GetCar
{
return builder
.MapGet("cars/{id:guid}", Endpoint)
.WithTags("Cars");
.WithDescription("Returns a single car by ID")
.WithTags("Cars")
.Produces<Response>()
.Produces(404);
}
private static async Task<IResult> Endpoint(
@@ -28,4 +32,4 @@ public static class GetCar
var response = new Response(car.Id.Value, car.Name);
return TypedResults.Ok(response);
}
}
}

View File

@@ -25,10 +25,11 @@ public static class GetCars
return builder
.MapGet("cars", Endpoint)
.WithDescription("Returns all cars")
.WithTags("Cars");
.WithTags("Cars")
.Produces<ApiResponse>();
}
private static async Task<Ok<ApiResponse>> Endpoint(
private static async Task<IResult> Endpoint(
[AsParameters] Request request,
ApplicationDbContext dbContext,
CancellationToken cancellationToken)

View File

@@ -15,7 +15,10 @@ public static class UpdateCar
{
return builder
.MapPut("cars/{id:guid}", Endpoint)
.WithTags("Cars");
.WithTags("Cars")
.Produces<Response>()
.ProducesValidationProblem()
.Produces(404);
}
public class Validator : AbstractValidator<Request>