jasontaylordev / CleanArchitecture

Clean Architecture Solution Template for ASP.NET Core
MIT License
16.13k stars 3.45k forks source link

Swagger Specifications are incomplete #1145

Open xantari opened 3 months ago

xantari commented 3 months ago

Describe the bug

The swagger specifications are missing the other potential response codes. For instance, the TodoItems endpoint has a CreateTodoItem. The swagger specification only mentions HTTP 200 as a potential result status.

However, if you pass in a request to that method with a blank title, the ValidationBehaviour which will throw a validation error. This then in turn gets routed to the CustomExceptionHandler, which returns Status400BadRequest and returns a ValidationProblemDetails.

For completeness, these other return types should be emitted as part of the swagger specification.json but they are not because the endpoint builders are not letting nswag know about these additional return values.

To Reproduce

Use the following json in the POST to /api/TodoItems:

{
  "listId": 0,
  "title": ""
}

You will notice that it works fine. However an undocumented return status code is emitted (HTTP Status 400).

Expected behavior The error is being returned properly. However the swagger specification.json is not showing that as a potential return value and not describing the return object that will be returned when validation errors occur (ValidationProblemDetailsobject). This should be fully described by the API. This is normally done by annotating the API endpoints potential HTTP return status codes.