You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the HttpGet attribute serves no purpose and can be eliminated
the return value Task<IActionResult> is untyped. You can return anything and it only will show at runtime if you're right or wrong.
as a result of the untyped return value, you need to specify it explicitly in ProducesResponseType but there again you can specify anything since there is no verifyable relation between the attribute and the actual return value it is decorating.
The generated Swagger code is exactly the same. No more explicit Ok() since it's the default (but you still can return other things like NotFound()). The ProducesResponseType deduces the actual type from the return value of the method.
It would also be good practice to systematically include a CancellationToken on the async methods, but in this particular instance it isn't used in the implementation.
The text was updated successfully, but these errors were encountered:
The guidance generates something like this:
Several things can noticed:
HttpGet
attribute serves no purpose and can be eliminatedTask<IActionResult>
is untyped. You can return anything and it only will show at runtime if you're right or wrong.ProducesResponseType
but there again you can specify anything since there is no verifyable relation between the attribute and the actual return value it is decorating.A more modern and secure way of writing is this:
The generated Swagger code is exactly the same. No more explicit
Ok()
since it's the default (but you still can return other things likeNotFound()
). TheProducesResponseType
deduces the actual type from the return value of the method.Type conversion is implicit for all non-interface types. See https://learn.microsoft.com/en-us/aspnet/core/web-api/action-return-types?view=aspnetcore-6.0#actionresultt-type-1 for more information.
It would also be good practice to systematically include a
CancellationToken
on the async methods, but in this particular instance it isn't used in the implementation.The text was updated successfully, but these errors were encountered: