Use net/http constants in boilerplate#2398
Conversation
e06f625 to
31d000a
Compare
Greptile SummaryThis PR replaces generated raw HTTP status numbers with
Confidence Score: 5/5This looks safe to merge.
|
| Filename | Overview |
|---|---|
| pkg/codegen/operations.go | Adds the fixed status-code to net/http constant mapping used by generated output. |
| pkg/codegen/template_helpers.go | Updates generated client response conditions to compare against HTTP status constants. |
| pkg/codegen/templates/strict/strict-interface.tmpl | Emits HTTP status constants for fixed strict-server response codes. |
| pkg/codegen/templates/strict/strict-fiber-interface.tmpl | Emits HTTP status constants for fixed Fiber strict-server responses. |
| pkg/codegen/templates/strict/strict-iris-interface.tmpl | Emits HTTP status constants for fixed Iris strict-server responses. |
Reviews (2): Last reviewed commit: "Use net/http constants in boilerplate" | Re-trigger Greptile
Closes: oapi-codegen#2397 Replace raw integer literals in generated strict server code with named net/http constants (e.g. http.StatusOK instead of 200). Covers WriteHeader/Status/StatusCode calls in all strict server templates and status code comparisons in generated client switch statements. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
31d000a to
3988907
Compare
|
@greptileai, please look again, comments addressed. |
| return httpStatusConstant(r.StatusCode) | ||
| } | ||
|
|
||
| func httpStatusConstant(code string) string { |
There was a problem hiding this comment.
Might be worth a test to help us catch when new statuses are added to the standard library, if straightforward?
There was a problem hiding this comment.
We'd have to grep the standard library source. I think being lazy here is ok. The fallback to not using the constant will work, and we can address as-needed.
jamietanna
left a comment
There was a problem hiding this comment.
Agreed this doesn't really provide too much additional value, but it can help consistency that a lot of folks' "production code" would do
Closes: #2397
Replace raw integer literals in generated strict server code with named net/http constants (e.g. http.StatusOK instead of 200). Covers WriteHeader/Status/StatusCode calls in all strict server templates and status code comparisons in generated client switch statements.