Skip to content

Fixes operationId starting with integers crashes generation #1326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 11, 2025

Conversation

thejhh
Copy link
Contributor

@thejhh thejhh commented Jul 9, 2025

Fixes issue #952 by quoting invalid operationIds using double quotes.

Copy link

changeset-bot bot commented Jul 9, 2025

🦋 Changeset detected

Latest commit: 41a0b20

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
swagger-typescript-api Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@js2me
Copy link
Member

js2me commented Jul 11, 2025

Hello @thejhh !
Thank you!

@js2me js2me merged commit 99b5f50 into acacode:main Jul 11, 2025
3 checks passed
@github-actions github-actions bot mentioned this pull request Jul 11, 2025
@smorimoto smorimoto requested a review from Copilot July 11, 2025 06:37
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes issue #952 by ensuring operationIds starting with numbers are quoted in generated TypeScript to avoid invalid identifiers.

  • Adds a test schema and snapshot for operationIds beginning with digits
  • Updates templates to wrap invalid identifiers in quotes
  • Documents the change in a new changeset

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/spec/operationId-starting-with-number/schema.json Added OpenAPI schema with operationIds beginning with numbers
tests/spec/operationId-starting-with-number/basic.test.ts New test verifying quoted vs. unquoted operationId names
tests/spec/operationId-starting-with-number/snapshots Snapshot updated to include quoted identifiers
templates/modular/procedure-call.ejs Wrapped invalid procedure call names in quotes
templates/default/procedure-call.ejs Wrapped invalid procedure call names in quotes
templates/base/route-type.ejs Wrapped invalid namespace names in quotes
.changeset/fix-operationid-starting-with-number.md Added release notes for this patch
Comments suppressed due to low confidence (1)

@@ -79,6 +79,8 @@ const describeReturnType = () => {
}
}

const isValidIdentifier = (name) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
Copy link
Preview

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

The helper function isValidIdentifier is duplicated across multiple templates; consider extracting it into the shared utils object or a common helper file to centralize this logic and simplify future updates.

Copilot uses AI. Check for mistakes.

@@ -4,6 +4,7 @@ const { _, pascalCase, require } = utils;
const { query, payload, pathParams, headers } = route.request;

const routeDocs = includeFile("@base/route-docs", { config, route, utils });
const isValidIdentifier = (name) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
Copy link
Preview

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

Extracting isValidIdentifier into a shared utility would avoid repeating the same regex in multiple template files and ensure consistency if validation rules change.

Copilot uses AI. Check for mistakes.

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.

2 participants