Closed Karitham closed 2 years ago
I think alternatively, we can just export field inside *Response
so the user can do return &oapi.Response{StatusCode: http.StatusNoContent}
.
Ideally, though, the schema should describe the status code, and the generator should generate something like
func DeletePetJSON204Response() *Response {
return &Response{statusCode: 204}
}
I guess exporting responseCode is fine, especially since it's unlikely to really change much later on, and isn't exactly subject to breaking change.
Context
For methods such as DELETE, PATCH, PUT and POST, we are often met with the need of just returning a response code.
Having a helper method landing after #80 (returning a
*Response
) directly means that we are obliged to either return something like(we will go with
openapi
as the generated package name)Or to write the status code directly, similarly to this code @diamondburned refactored.
Proposal
Generating a function to help with this
Which would turn this situation into
I think this would make every single return meaningful, such that developers could identify code paths that actually respond to the request simpler, rather than having them search for status code being set, or not, earlier.