Specify API returns types for swagger
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -16,7 +16,8 @@ public static class CreateConsumption
|
||||
{
|
||||
return builder
|
||||
.MapPost("consumptions", Endpoint)
|
||||
.WithTags("Consumptions");
|
||||
.WithTags("Consumptions")
|
||||
.Produces<Response>(201);
|
||||
}
|
||||
|
||||
public class Validator : AbstractValidator<Request>
|
||||
|
||||
@@ -8,7 +8,9 @@ public static class DeleteConsumption
|
||||
{
|
||||
return builder
|
||||
.MapDelete("consumptions/{id:guid}", Endpoint)
|
||||
.WithTags("Consumptions");
|
||||
.WithTags("Consumptions")
|
||||
.Produces(204)
|
||||
.Produces(404);
|
||||
}
|
||||
|
||||
private static async Task<IResult> Endpoint(
|
||||
|
||||
@@ -10,7 +10,9 @@ public static class GetConsumption
|
||||
{
|
||||
return builder
|
||||
.MapGet("consumptions/{id:guid}", Endpoint)
|
||||
.WithTags("Consumptions");
|
||||
.WithTags("Consumptions")
|
||||
.Produces<Response>()
|
||||
.Produces(404);
|
||||
}
|
||||
|
||||
private static async Task<IResult> Endpoint(
|
||||
|
||||
@@ -31,7 +31,8 @@ public static class GetConsumptions
|
||||
return builder
|
||||
.MapGet("consumptions", Endpoint)
|
||||
.WithDescription("Returns all consumption entries")
|
||||
.WithTags("Consumptions");
|
||||
.WithTags("Consumptions")
|
||||
.Produces<ApiResponse>();
|
||||
}
|
||||
|
||||
private static async Task<Ok<ApiResponse>> Endpoint(
|
||||
@@ -44,7 +45,7 @@ public static class GetConsumptions
|
||||
new ResponseDto(x.Id.Value, x.DateTime, x.Distance, x.Amount, x.IgnoreInCalculation, x.CarId.Value))
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var apiResponse = new ApiResponse
|
||||
ApiResponse apiResponse = new()
|
||||
{
|
||||
Consumptions = consumptions
|
||||
};
|
||||
|
||||
@@ -15,7 +15,10 @@ public static class UpdateConsumption
|
||||
{
|
||||
return builder
|
||||
.MapPut("consumptions/{id:guid}", Endpoint)
|
||||
.WithTags("Consumptions");
|
||||
.WithTags("Consumptions")
|
||||
.Produces<Response>()
|
||||
.ProducesValidationProblem()
|
||||
.Produces(404);
|
||||
}
|
||||
|
||||
public class Validator : AbstractValidator<Request>
|
||||
|
||||
Reference in New Issue
Block a user