-
-
Notifications
You must be signed in to change notification settings - Fork 156
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
fix: handle negative property names correctly in case and zod plugins #1919
base: main
Are you sure you want to change the base?
Conversation
Updated the logic in the case and zod plugins to return string literals for negative numeric property names. Added tests and specifications to ensure proper handling of negative property names in the OpenAPI schema.
|
🦋 Changeset detectedLatest commit: ec62470 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be up for adding snapshots for OpenAPI 2.0 and 3.0 as well? I also see Zod plugin has been updated, can you add snapshots for that?
@hey-api/client-axios
@hey-api/client-fetch
@hey-api/client-next
@hey-api/client-nuxt
@hey-api/nuxt
@hey-api/openapi-ts
@hey-api/vite-plugin
commit: |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1919 +/- ##
==========================================
- Coverage 24.15% 24.14% -0.01%
==========================================
Files 193 193
Lines 26851 26862 +11
Branches 787 787
==========================================
Hits 6486 6486
- Misses 20290 20301 +11
Partials 75 75
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
'@hey-api/openapi-ts': patch | ||
--- | ||
|
||
"Fix handling of negative property names in TypeScript code generation" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Fix handling of negative property names in TypeScript code generation" | |
fix: correctly handle numeric property names with signs |
Fix:
Fixes #1918
Handle negative property names in TypeScript code generation
Problem
When parsing OpenAPI schemas that contain property names with negative numbers (like "-1"), the TypeScript compiler would fail with the error:
This is because TypeScript's compiler expects negative numeric literals to be created using a specific approach (
createPrefixUnaryExpression
) rather than directly as negative literals.Solution
Modified the
fieldName
function inpackages/openapi-ts/src/plugins/shared/utils/case.ts
to use string literals for property names containing negative numbers. Also updated the Zod plugin with the same approach for consistency.ts.factory.createStringLiteral("-1")
)Testing
packages/openapi-ts-tests/test/spec/3.1.x/negative-property-names.json
) that includes a schema with both positive and negative property namesAll existing tests continue to pass, showing that this fix doesn't introduce any regressions.
Example
Before this fix, the following OpenAPI schema property would cause errors:
Now it correctly generates TypeScript with string literal property names: