Merge pull request #92 from meysamhadeli/feat/add-swagger-response-attribute

feat: Add swagger response type
This commit is contained in:
Meysam Hadeli 2023-01-15 00:44:47 +03:30 committed by GitHub
commit 6552dade50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 234 additions and 36 deletions

View File

@ -12,6 +12,8 @@ using Swashbuckle.AspNetCore.Annotations;
namespace Booking.Booking.Features.CreateBooking.Endpoints.V1;
using Hellang.Middleware.ProblemDetails;
public class CreateBookingEndpoint : IMinimalEndpoint
{
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder endpoints)
@ -22,9 +24,21 @@ public class CreateBookingEndpoint : IMinimalEndpoint
.WithName("CreateBooking")
.WithMetadata(new SwaggerOperationAttribute("Create Booking", "Create Booking"))
.WithApiVersionSet(endpoints.NewApiVersionSet("Booking").Build())
.Produces<ulong>()
.Produces(StatusCodes.Status200OK)
.Produces(StatusCodes.Status400BadRequest)
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status200OK,
"Booking Created",
typeof(ulong)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status400BadRequest,
"BadRequest",
typeof(StatusCodeProblemDetails)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status401Unauthorized,
"UnAuthorized",
typeof(StatusCodeProblemDetails)))
.HasApiVersion(1.0);
return endpoints;

View File

@ -13,6 +13,8 @@ using Swashbuckle.AspNetCore.Annotations;
namespace Flight.Aircrafts.Features.CreateAircraft.Endpoints.V1;
using Hellang.Middleware.ProblemDetails;
public class CreateAircraftEndpoint : IMinimalEndpoint
{
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder endpoints)
@ -23,9 +25,21 @@ public class CreateAircraftEndpoint : IMinimalEndpoint
.WithName("CreateAircraft")
.WithMetadata(new SwaggerOperationAttribute("Create Aircraft", "Create Aircraft"))
.WithApiVersionSet(endpoints.NewApiVersionSet("Flight").Build())
.Produces<AircraftResponseDto>()
.Produces(StatusCodes.Status200OK)
.Produces(StatusCodes.Status400BadRequest)
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status200OK,
"Aircraft Created",
typeof(AircraftResponseDto)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status400BadRequest,
"BadRequest",
typeof(StatusCodeProblemDetails)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status401Unauthorized,
"UnAuthorized",
typeof(StatusCodeProblemDetails)))
.HasApiVersion(1.0);
return endpoints;

View File

@ -13,6 +13,8 @@ using Swashbuckle.AspNetCore.Annotations;
namespace Flight.Airports.Features.CreateAirport.Endpoints.V1;
using Hellang.Middleware.ProblemDetails;
public class CreateAirportEndpoint : IMinimalEndpoint
{
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder endpoints)
@ -23,9 +25,21 @@ public class CreateAirportEndpoint : IMinimalEndpoint
.WithName("CreateAirport")
.WithMetadata(new SwaggerOperationAttribute("Create Airport", "Create Airport"))
.WithApiVersionSet(endpoints.NewApiVersionSet("Flight").Build())
.Produces<AirportResponseDto>()
.Produces(StatusCodes.Status200OK)
.Produces(StatusCodes.Status400BadRequest)
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status200OK,
"Airport Created",
typeof(AirportResponseDto)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status400BadRequest,
"BadRequest",
typeof(StatusCodeProblemDetails)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status401Unauthorized,
"UnAuthorized",
typeof(StatusCodeProblemDetails)))
.HasApiVersion(1.0);
return endpoints;

View File

@ -14,6 +14,8 @@ using Swashbuckle.AspNetCore.Annotations;
namespace Flight.Flights.Features.CreateFlight.Endpoints.V1;
using Hellang.Middleware.ProblemDetails;
public class CreateFlightEndpoint : IMinimalEndpoint
{
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder endpoints)
@ -24,9 +26,21 @@ public class CreateFlightEndpoint : IMinimalEndpoint
.WithName("CreateFlight")
.WithMetadata(new SwaggerOperationAttribute("Create Flight", "Create Flight"))
.WithApiVersionSet(endpoints.NewApiVersionSet("Flight").Build())
.Produces<FlightResponseDto>()
.Produces(StatusCodes.Status201Created)
.Produces(StatusCodes.Status400BadRequest)
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status201Created,
"Flight Created",
typeof(FlightResponseDto)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status400BadRequest,
"BadRequest",
typeof(StatusCodeProblemDetails)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status401Unauthorized,
"UnAuthorized",
typeof(StatusCodeProblemDetails)))
.HasApiVersion(1.0);
return endpoints;

View File

@ -11,6 +11,8 @@ using Swashbuckle.AspNetCore.Annotations;
namespace Flight.Flights.Features.DeleteFlight.Endpoints.V1;
using Hellang.Middleware.ProblemDetails;
public class DeleteFlightEndpoint : IMinimalEndpoint
{
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder endpoints)
@ -21,9 +23,21 @@ public class DeleteFlightEndpoint : IMinimalEndpoint
.WithName("DeleteFlight")
.WithMetadata(new SwaggerOperationAttribute("Delete Flight", "Delete Flight"))
.WithApiVersionSet(endpoints.NewApiVersionSet("Flight").Build())
.Produces<FlightResponseDto>()
.Produces(StatusCodes.Status204NoContent)
.Produces(StatusCodes.Status400BadRequest)
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status204NoContent,
"Flight Deleted",
typeof(FlightResponseDto)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status400BadRequest,
"BadRequest",
typeof(StatusCodeProblemDetails)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status401Unauthorized,
"UnAuthorized",
typeof(StatusCodeProblemDetails)))
.HasApiVersion(1.0);
return endpoints;

View File

@ -12,6 +12,8 @@ using Swashbuckle.AspNetCore.Annotations;
namespace Flight.Flights.Features.GetAvailableFlights.Endpoints.V1;
using Hellang.Middleware.ProblemDetails;
public class GetAvailableFlightsEndpoint : IMinimalEndpoint
{
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder endpoints)
@ -22,9 +24,21 @@ public class GetAvailableFlightsEndpoint : IMinimalEndpoint
.WithName("GetAvailableFlights")
.WithMetadata(new SwaggerOperationAttribute("Get Available Flights", "Get Available Flights"))
.WithApiVersionSet(endpoints.NewApiVersionSet("Flight").Build())
.Produces<IEnumerable<FlightResponseDto>>()
.Produces(StatusCodes.Status200OK)
.Produces(StatusCodes.Status400BadRequest)
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status200OK,
"GetAvailableFlights",
typeof(IEnumerable<FlightResponseDto>)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status400BadRequest,
"BadRequest",
typeof(StatusCodeProblemDetails)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status401Unauthorized,
"UnAuthorized",
typeof(StatusCodeProblemDetails)))
.HasApiVersion(1.0);
return endpoints;

View File

@ -11,6 +11,8 @@ using Swashbuckle.AspNetCore.Annotations;
namespace Flight.Flights.Features.GetFlightById.Endpoints.V1;
using Hellang.Middleware.ProblemDetails;
public class GetFlightByIdEndpoint : IMinimalEndpoint
{
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder endpoints)
@ -24,6 +26,21 @@ public class GetFlightByIdEndpoint : IMinimalEndpoint
.Produces<FlightResponseDto>()
.Produces(StatusCodes.Status200OK)
.Produces(StatusCodes.Status400BadRequest)
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status200OK,
"GetFlightById",
typeof(FlightResponseDto)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status400BadRequest,
"BadRequest",
typeof(StatusCodeProblemDetails)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status401Unauthorized,
"UnAuthorized",
typeof(StatusCodeProblemDetails)))
.HasApiVersion(1.0);
return endpoints;

View File

@ -13,6 +13,8 @@ using Swashbuckle.AspNetCore.Annotations;
namespace Flight.Flights.Features.UpdateFlight.Endpoints.V1;
using Hellang.Middleware.ProblemDetails;
public class UpdateFlightEndpoint : IMinimalEndpoint
{
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder endpoints)
@ -26,6 +28,21 @@ public class UpdateFlightEndpoint : IMinimalEndpoint
.Produces<FlightResponseDto>()
.Produces(StatusCodes.Status204NoContent)
.Produces(StatusCodes.Status400BadRequest)
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status204NoContent,
"Flight Updated",
typeof(FlightResponseDto)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status400BadRequest,
"BadRequest",
typeof(StatusCodeProblemDetails)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status401Unauthorized,
"UnAuthorized",
typeof(StatusCodeProblemDetails)))
.HasApiVersion(1.0);
return endpoints;

View File

@ -13,6 +13,8 @@ using Swashbuckle.AspNetCore.Annotations;
namespace Flight.Seats.Features.CreateSeat.Endpoints.V1;
using Hellang.Middleware.ProblemDetails;
public class CreateSeatEndpoint : IMinimalEndpoint
{
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder endpoints)
@ -23,9 +25,21 @@ public class CreateSeatEndpoint : IMinimalEndpoint
.WithName("CreateSeat")
.WithMetadata(new SwaggerOperationAttribute("Create Seat", "Create Seat"))
.WithApiVersionSet(endpoints.NewApiVersionSet("Flight").Build())
.Produces<SeatResponseDto>()
.Produces(StatusCodes.Status200OK)
.Produces(StatusCodes.Status400BadRequest)
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status200OK,
"Seat Created",
typeof(SeatResponseDto)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status400BadRequest,
"BadRequest",
typeof(StatusCodeProblemDetails)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status401Unauthorized,
"UnAuthorized",
typeof(StatusCodeProblemDetails)))
.HasApiVersion(1.0);
return endpoints;

View File

@ -12,6 +12,8 @@ using Swashbuckle.AspNetCore.Annotations;
namespace Flight.Seats.Features.GetAvailableSeats.Endpoints.V1;
using Hellang.Middleware.ProblemDetails;
public class GetAvailableSeatsEndpoint : IMinimalEndpoint
{
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder endpoints)
@ -22,9 +24,21 @@ public class GetAvailableSeatsEndpoint : IMinimalEndpoint
.WithName("GetAvailableSeats")
.WithMetadata(new SwaggerOperationAttribute("Get Available Seats", "Get Available Seats"))
.WithApiVersionSet(endpoints.NewApiVersionSet("Flight").Build())
.Produces<IEnumerable<SeatResponseDto>>()
.Produces(StatusCodes.Status200OK)
.Produces(StatusCodes.Status400BadRequest)
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status200OK,
"GetAvailableSeats",
typeof(IEnumerable<SeatResponseDto>)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status400BadRequest,
"BadRequest",
typeof(StatusCodeProblemDetails)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status401Unauthorized,
"UnAuthorized",
typeof(StatusCodeProblemDetails)))
.HasApiVersion(1.0);
return endpoints;

View File

@ -13,6 +13,8 @@ using Swashbuckle.AspNetCore.Annotations;
namespace Flight.Seats.Features.ReserveSeat.Endpoints.V1;
using Hellang.Middleware.ProblemDetails;
public class ReserveSeatEndpoint : IMinimalEndpoint
{
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder endpoints)
@ -23,9 +25,21 @@ public class ReserveSeatEndpoint : IMinimalEndpoint
.WithName("ReserveSeat")
.WithMetadata(new SwaggerOperationAttribute("Reserve Seat", "Reserve Seat"))
.WithApiVersionSet(endpoints.NewApiVersionSet("Flight").Build())
.Produces<SeatResponseDto>()
.Produces(StatusCodes.Status200OK)
.Produces(StatusCodes.Status400BadRequest)
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status200OK,
"ReserveSeat",
typeof(SeatResponseDto)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status400BadRequest,
"BadRequest",
typeof(StatusCodeProblemDetails)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status401Unauthorized,
"UnAuthorized",
typeof(StatusCodeProblemDetails)))
.HasApiVersion(1.0);
return endpoints;

View File

@ -13,6 +13,8 @@ using Swashbuckle.AspNetCore.Annotations;
namespace Identity.Identity.Features.RegisterNewUser.Endpoints.V1;
using Hellang.Middleware.ProblemDetails;
public class RegisterNewUserEndpoint : IMinimalEndpoint
{
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder endpoints)
@ -22,9 +24,16 @@ public class RegisterNewUserEndpoint : IMinimalEndpoint
.WithName("RegisterUser")
.WithMetadata(new SwaggerOperationAttribute("Register User", "Register User"))
.WithApiVersionSet(endpoints.NewApiVersionSet("Identity").Build())
.Produces<RegisterNewUserResponseDto>()
.Produces(StatusCodes.Status200OK)
.Produces(StatusCodes.Status400BadRequest)
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status200OK,
"User Registered",
typeof(RegisterNewUserResponseDto)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status400BadRequest,
"BadRequest",
typeof(StatusCodeProblemDetails)))
.HasApiVersion(1.0);
return endpoints;

View File

@ -11,6 +11,8 @@ using Swashbuckle.AspNetCore.Annotations;
namespace Passenger.Passengers.Features.CompleteRegisterPassenger.Endpoints.V1;
using Hellang.Middleware.ProblemDetails;
public class CompleteRegisterPassengerEndpoint : IMinimalEndpoint
{
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder endpoints)
@ -21,9 +23,21 @@ public class CompleteRegisterPassengerEndpoint : IMinimalEndpoint
.WithName("CompleteRegisterPassenger")
.WithMetadata(new SwaggerOperationAttribute("Complete Register Passenger", "Complete Register Passenger"))
.WithApiVersionSet(endpoints.NewApiVersionSet("Passenger").Build())
.Produces<PassengerResponseDto>()
.Produces(StatusCodes.Status200OK)
.Produces(StatusCodes.Status400BadRequest)
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status200OK,
"Register Passenger Completed",
typeof(PassengerResponseDto)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status400BadRequest,
"BadRequest",
typeof(StatusCodeProblemDetails)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status401Unauthorized,
"UnAuthorized",
typeof(StatusCodeProblemDetails)))
.HasApiVersion(1.0);
return endpoints;

View File

@ -10,6 +10,9 @@ using Passenger.Passengers.Features.GetPassengerById.Queries.V1;
using Swashbuckle.AspNetCore.Annotations;
namespace Passenger.Passengers.Features.GetPassengerById.Endpoints.V1;
using Hellang.Middleware.ProblemDetails;
public class GetPassengerByIdEndpoint : IMinimalEndpoint
{
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder endpoints)
@ -20,9 +23,21 @@ public class GetPassengerByIdEndpoint : IMinimalEndpoint
.WithName("GetPassengerById")
.WithMetadata(new SwaggerOperationAttribute("Get Passenger By Id", "Get Passenger By Id"))
.WithApiVersionSet(endpoints.NewApiVersionSet("Passenger").Build())
.Produces<PassengerResponseDto>()
.Produces(StatusCodes.Status200OK)
.Produces(StatusCodes.Status400BadRequest)
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status200OK,
"GetPassengerById",
typeof(PassengerResponseDto)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status400BadRequest,
"BadRequest",
typeof(StatusCodeProblemDetails)))
.WithMetadata(
new SwaggerResponseAttribute(
StatusCodes.Status401Unauthorized,
"UnAuthorized",
typeof(StatusCodeProblemDetails)))
.HasApiVersion(1.0);
return endpoints;