feat: use http.MethodXXX constants instead of string literals in generated code#2294
Open
imsugeno wants to merge 2 commits intooapi-codegen:mainfrom
Open
feat: use http.MethodXXX constants instead of string literals in generated code#2294imsugeno wants to merge 2 commits intooapi-codegen:mainfrom
imsugeno wants to merge 2 commits intooapi-codegen:mainfrom
Conversation
Add httpMethodConstant template helper that converts HTTP method strings (e.g. "GET") to net/http constants (e.g. http.MethodGet) and apply it to the client, gorilla, and stdhttp templates. Refs oapi-codegen#659
Run make generate to update all generated files with the new http.MethodXXX constants in place of string literals.
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace HTTP method string literals (e.g.
"GET","POST") withnet/httpconstants (e.g.http.MethodGet,http.MethodPost) in generated code.Changes
httpMethodConstanttemplate helper function that maps HTTP method strings to theirhttp.MethodXXXequivalentsclient.tmpl—http.NewRequest("GET", ...)→http.NewRequest(http.MethodGet, ...)gorilla/gorilla-register.tmpl—.Methods("GET")→.Methods(http.MethodGet)stdhttp/std-http-handler.tmpl—"GET "+pattern→http.MethodGet+" "+patternOther server templates (Chi, Echo, Gin, Fiber, Iris) use
.Methodas a router method name (e.g.router.Get(...)) rather than a string literal, so no changes are needed there.This is a cosmetic change only —
http.MethodGet == "GET"— so there is no behavioral difference and no breaking change to consumers.Fixes #659