-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix] DELETE
methods should always return response status code 204
#367
Conversation
SonarCloud Quality Gate failed. |
You have successfully added a new SonarCloud configuration ``. As part of the setup process, we have scanned this repository and found no existing alerts. In the future, you will see all code scanning alerts on the repository Security tab. |
@@ -81,7 +81,11 @@ protected override void SetParameters(OpenApiOperation operation) | |||
/// <inheritdoc/> | |||
protected override void SetResponses(OpenApiOperation operation) | |||
{ | |||
operation.AddErrorResponses(Context.Settings, true); | |||
// Response for Delete methods should be 204 No Content | |||
OpenApiConvertSettings settings = Context.Settings.Clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit late to the party here. But if we could avoid allocs for that kind of thing, it'd be better. Could we not check the operation method/verb in the AddErrorResponses method instead? @irvinesunday
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it, but I was avoiding growing this function by adding an extra optional parameter (which will only be utilized by delete methods) and conditional checks here. I also wanted to be explicit that we are not using success status code range for delete
methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the additional context here. Would it have been another parameter since it's an extension method on operation and thus it has access to the operation properties?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you can't infer the OperationType
from the operation
object properties. This is in the Operations
property dictionary key of an OpenApiPathItem
object: https://github.com/microsoft/OpenAPI.NET/blob/df1b405e537d0f3c2a829b6a80fef82959d0eab5/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs#L29
Operation
properties: https://github.com/microsoft/OpenAPI.NET/blob/df1b405e537d0f3c2a829b6a80fef82959d0eab5/src/Microsoft.OpenApi/Models/OpenApiOperation.cs#L119-L131
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah right, I forgot about the dictionary pattern, which is a bit painful to carry the context around. Fine, leave it as is for now, thanks for taking the time to discuss this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries.
Fixes #366
This PR:
delete
methods always return status code204
. This is regardless of whetherUseSuccessStatusCodeRange
istrue
.