Skip to content

feat(autopatch): generate PATCH operation IDs with GenerateOperationID - #1174

Open
mansur-akhmadi wants to merge 1 commit into
danielgtaylor:mainfrom
mansur-akhmadi:feat/autopatch-generate-operation-id
Open

mansur-akhmadi wants to merge 1 commit into
danielgtaylor:mainfrom
mansur-akhmadi:feat/autopatch-generate-operation-id

Conversation

@mansur-akhmadi

Copy link
Copy Markdown

Closes #914

autopatch built the PATCH operation ID by splitting the GET operation ID and re-joining it in kebab case, so it never went through huma.GenerateOperationID. With a camel-case generator (as in #914) you got getV1ThingsByThingId next to patch-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 from huma.GenerateOperationID(http.MethodPatch, path, <GET response type>). That's the same _convenience_id check Group.ModifyOperation already uses. Hand-written GET IDs (huma.Register with OperationID, 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:

  • paths with digits: get-v1-things-by-id used to give patch-v-1-things-by-id, now patch-v1-things-by-id (matches get-…/put-…)
  • GET with a slice body (list-things) on the same path as the PUT: patch-list-things -> patch-things

Other 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

  • The PATCH Summary is still "Patch " + name. It doesn't go through huma.GenerateSummary either, but that's not part of autopatch: Use "huma.GenerateOperationID" to generate operation ID #914.
  • If the GET ID isn't the generated one, nothing changes. That covers explicit IDs, IDs overridden in a handler, and groups with several prefixes, where the prefix modifier rewrites the ID. In those cases the old derivation, including its digit splitting, still applies.
  • The response passed to the generator is the GET's output type, the same value the GET ID was generated from.

How it was verified

  • TestPatchOperationID in autopatch/autopatch_test.go: explicit GET ID, convenience GET, convenience GET with an overridden ID, and a custom camel-case generator inside a /v1 group. Without the change, convenience fails (patch-v-1-things-by-thing-id) and so does custom 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=3 on its own. It also passes on main, and this change doesn't touch it.
  • golangci-lint run ./autopatch/... (v2.13.2 locally, CI pins v2.15.0): 0 issues. go vet/gofmt are clean on the touched files.
  • Docs: a short paragraph in docs/docs/features/auto-patch.md. I didn't build the docs site locally.

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

No deployments
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.

autopatch: Use "huma.GenerateOperationID" to generate operation ID

1 participant