FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Use net/http constants in boilerplate by mromaszewicz · Pull Request #2398 · oapi-codegen/oapi-codegen · GitHub

Use net/http constants in boilerplate - #2398

Open
mromaszewicz wants to merge 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/issue-2397
Open

Use net/http constants in boilerplate#2398
mromaszewicz wants to merge 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/issue-2397

Conversation

Copy link
Copy Markdown
Member

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.

mromaszewicz requested a review from a team as a code owner June 5, 2026 22:27

greptile-apps Bot commented Jun 5, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR replaces generated raw HTTP status numbers with net/http constants. It changes:

  • Strict server response boilerplate for standard, Fiber, and Iris outputs.
  • Client response parsing comparisons in generated code.
  • Shared codegen helpers for mapping fixed status codes to http.Status* names.
  • Regenerated examples and internal fixtures to match the template output.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

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>

Copy link
Copy Markdown
Member Author

@greptileai, please look again, comments addressed.

Comment thread pkg/codegen/operations.go
return httpStatusConstant(r.StatusCode)
}

func httpStatusConstant(code string) string {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Might be worth a test to help us catch when new statuses are added to the standard library, if straightforward?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Agreed this doesn't really provide too much additional value, but it can help consistency that a lot of folks' "production code" would do

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use constants from net/http for the status codes

2 participants


Back | FazBrowse Home | New Git URL