Skip to content

fix: generate clean OpenAPI operation names without duplicated HTTP verb#383

Open
ALagoni97 wants to merge 1 commit into
mainfrom
fix/openapi-operation-naming
Open

fix: generate clean OpenAPI operation names without duplicated HTTP verb#383
ALagoni97 wants to merge 1 commit into
mainfrom
fix/openapi-operation-naming

Conversation

@ALagoni97

Copy link
Copy Markdown
Contributor

Problem

Generated HTTP client function names for OpenAPI inputs duplicated the HTTP verb and, for specs without operationIds, collapsed into uncasable blobs.

  • GET /v2/connect/{referenceId} (no operationId) → getGetv2connectreferenceId
  • A real operationId: findPetsByStatusAndCategory on GET → getFindPetsByStatusAndCategory

Two causes:

  1. The channel generator always prepended the HTTP method to the pascal-cased operationId, even though the operationId already encodes/represents the verb.
  2. The synthesized operationId (${method}${path.replace(/[^a-zA-Z0-9]/g,'')}) stripped all separators, destroying word boundaries so casing could never be recovered.

Fix

  • Extract a shared deriveOperationId({operationId, method, path}) helper: spec-provided ids are used verbatim; synthesized ids are built from method + path segments with word boundaries preserved (getV2ConnectReferenceId).
  • Use it across payloads, parameters, types, headers and the channel generator so the correlation key stays consistent.
  • Stop re-prepending the method in the channel function name.

Result

GET /v2/connect/{referenceId}getV2ConnectReferenceId; findPetsByStatusAndCategory stays findPetsByStatusAndCategory.

Tests

  • New test/codegen/inputs/openapi/utils.spec.ts covering verbatim ids, synthesis, kebab segments, and the no-double-verb guarantee.
  • Updated channels snapshot (names only).

Note: this changes the names in generated OpenAPI output (function names, OperationIds union, schema $ids) — intended, and strictly an improvement.

🤖 Generated with Claude Code

Generated HTTP client function names for OpenAPI inputs were doubling the
HTTP verb (e.g. `getGetv2connectreferenceId`, `postAddPet`) and, for specs
without `operationId`s, collapsing the path into an uncasable blob because
all non-alphanumeric separators were stripped before casing.

Two causes:
- The channel generator always prepended the HTTP method to the pascal-cased
  operationId, even though the operationId already encodes the verb.
- The synthesized operationId (`${method}${path.replace(/[^a-zA-Z0-9]/g,'')}`)
  destroyed word boundaries, so `/v2/connect/{referenceId}` became
  `v2connectreferenceid` which can no longer be cased.

Extract a shared `deriveOperationId` helper that keeps spec-provided ids
verbatim and synthesizes word-boundary-preserving names from method + path
segments (`GET /v2/connect/{referenceId}` -> `getV2ConnectReferenceId`). Use
it across payloads, parameters, types, headers and the channel generator so
the correlation key stays consistent, and stop re-prepending the method in the
channel function name.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ALagoni97 ALagoni97 requested a review from jonaslagoni as a code owner July 6, 2026 19:51
@netlify

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploy Preview for the-codegen-project canceled.

Name Link
🔨 Latest commit dad0a09
🔍 Latest deploy log https://app.netlify.com/projects/the-codegen-project/deploys/6a4c07348e7e030008b4eca1

@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
the-codegen-project Ready Ready Preview, Comment Jul 6, 2026 7:55pm
the-codegen-project-mcp Ready Ready Preview, Comment Jul 6, 2026 7:55pm

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.

1 participant