ardalis / ApiEndpoints

A project for supporting API Endpoints in ASP.NET Core web applications.
MIT License
3.13k stars 227 forks source link

Swagger documentation in separate class #184

Open AdisonCavani opened 2 years ago

AdisonCavani commented 2 years ago

Currently, you can document endpoint using SwaggerOperation attribute above HandleAsync method:

[SwaggerOperation(
        Summary = "Submit a new article",
        Description = "Enables the submission of new articles",
        OperationId = "B349A6C4-1198-4B53-B9BE-85232E06F16E",
        Tags = new[] {"Article"})
]

Personally, I don't like this approach. Another library (FastEndpoints) has interesting alternative:

public class DeleteCustomerSummary : Summary<DeleteCustomerEndpoint>
{
    public DeleteCustomerSummary()
    {
        Summary = "Deleted a customer the system";
        Description = "Deleted a customer the system";
        Response(204, "The customer was deleted successfully");
        Response(404, "The customer was not found in the system");
    }
}

which produces this Swagger documentation:
swagger-docs

IMO this is much cleaner, because I don't make my endpoints clogged up with comments. Full project with this solution is here.

Is something like this possible with this library? If not, I'm passing it to you as a feature request.

ardalis commented 2 years ago

I like that, too! I've seen FastEndpoints but didn't notice this. I wonder if they did anything to make it work, or if it's just a Swagger feature we can just use in the same manner?

AdisonCavani commented 2 years ago

I don't think it's a Swagger feature. I've looked at a source code and this is what I found:

Summary contructor EndpointSummary class