Repository navigation
feat(autopatch): generate PATCH operation IDs with GenerateOperationID - #1174
Open
mansur-akhmadi wants to merge 1 commit into
Open
mansur-akhmadi wants to merge 1 commit into
mansur-akhmadi wants to merge 1 commit into
Conversation
The PATCH operation ID was always derived from the GET operation ID and re-joined in kebab case, so an overridden huma.GenerateOperationID (e.g. camel case) produced getThingsByThingId next to patch-Things-By-Thing-Id, and digits were split off (get-v1-things became patch-v-1-things). When the GET operation ID was generated by a convenience function and not overridden, generate the PATCH one with huma.GenerateOperationID as well. Hand-written GET operation IDs keep the previous derivation. Closes danielgtaylor#914
This branch has not been deployed
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.
Closes #914
autopatchbuilt the PATCH operation ID by splitting the GET operation ID and re-joining it in kebab case, so it never went throughhuma.GenerateOperationID. With a camel-case generator (as in #914) you gotgetV1ThingsByThingIdnext topatch-V-1-Things-By-Thing-Id.Now, when the GET operation ID was generated by a convenience function (
huma.Get, also after group prefixes) and not overridden, the PATCH ID comes fromhuma.GenerateOperationID(http.MethodPatch, path, <GET response type>). That's the same_convenience_idcheckGroup.ModifyOperationalready uses. Hand-written GET IDs (huma.RegisterwithOperationID, or an override in an operation handler) keep the old derivation (fetch-thing->patch-thing).Generated IDs that change with the default generator
Only when the GET was registered with a convenience function:
get-v1-things-by-idused to givepatch-v-1-things-by-id, nowpatch-v1-things-by-id(matchesget-…/put-…)list-things) on the same path as the PUT:patch-list-things->patch-thingsOther default IDs stay the same (
patch-things-by-thing-id). These IDs end up in generated SDKs, so I'm calling the change out here.Not changed
Summaryis still"Patch " + name. It doesn't go throughhuma.GenerateSummaryeither, but that's not part of autopatch: Use "huma.GenerateOperationID" to generate operation ID #914.How it was verified
TestPatchOperationIDinautopatch/autopatch_test.go: explicit GET ID, convenience GET, convenience GET with an overridden ID, and a custom camel-case generator inside a/v1group. Without the change,conveniencefails (patch-v-1-things-by-thing-id) and so doescustom generator(patch-V-1-Things-By-Thing-Id). With the change, all four pass.go test -race ./...: everything passes.adapters/humafiber(TestHumaFiberV2, timing-based) failed once under a full parallel run and passed with-count=3on its own. It also passes onmain, and this change doesn't touch it.golangci-lint run ./autopatch/...(v2.13.2 locally, CI pins v2.15.0): 0 issues.go vet/gofmtare clean on the touched files.docs/docs/features/auto-patch.md. I didn't build the docs site locally.