jasontaylordev / CleanArchitecture

Clean Architecture Solution Template for ASP.NET Core

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swagger Specifications are incomplete

xantari opened this issue · comments

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.