Skip to content

Commit 5459844

Browse files
Himenonclaude
andcommitted
feat(LiteralTypeNode): handle negative number literals with prefix unary expression
fix: TypeScript 6.0 で負の数リテラルを PrefixUnaryExpression で生成するよう修正 Co-Authored-By: Claude Sonnet <noreply@anthropic.com>
1 parent 9e0d837 commit 5459844

24 files changed

Lines changed: 52 additions & 47 deletions

src/internal/TsGenerator/factory/LiteralTypeNode.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export const create =
2121
}
2222

2323
if (typeof params.value === "number") {
24+
if (params.value < 0) {
25+
return factory.createLiteralTypeNode(
26+
factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, factory.createNumericLiteral(-params.value)),
27+
);
28+
}
2429
return factory.createLiteralTypeNode(factory.createNumericLiteral(params.value));
2530
}
2631
return factory.createLiteralTypeNode(params.value ? factory.createTrue() : factory.createFalse());

test/__tests__/class/__snapshots__/argo-rollout-test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`Argo Rollout client.ts 1`] = `
3+
exports[`Argo Rollout > client.ts 1`] = `
44
"//
55
// Generated by @himenon/openapi-typescript-code-generator
66
//

test/__tests__/class/__snapshots__/cloudflare-test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`Unknown client.ts 1`] = `
3+
exports[`Unknown > client.ts 1`] = `
44
"//
55
// Generated by @himenon/openapi-typescript-code-generator
66
//

test/__tests__/class/__snapshots__/format.domain.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`Format Types format.domain 1`] = `
3+
exports[`Format Types > format.domain 1`] = `
44
"//
55
// Generated by @himenon/openapi-typescript-code-generator
66
//

test/__tests__/class/__snapshots__/kubernetes-test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`Kubernetes client-v1.18.5.ts 1`] = `
3+
exports[`Kubernetes > client-v1.18.5.ts 1`] = `
44
"//
55
// Generated by @himenon/openapi-typescript-code-generator
66
//

test/__tests__/class/__snapshots__/multi-type.test.domain.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`Multi Type apiClient 1`] = `
3+
exports[`Multi Type > apiClient 1`] = `
44
"//
55
// Generated by @himenon/openapi-typescript-code-generator
66
//
@@ -99,7 +99,7 @@ export class Client<RequestOption> {
9999
"
100100
`;
101101
102-
exports[`Multi Type types 1`] = `
102+
exports[`Multi Type > types 1`] = `
103103
"//
104104
// Generated by @himenon/openapi-typescript-code-generator
105105
//

test/__tests__/class/__snapshots__/parameter-test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`Parameter api.test.domain 1`] = `
3+
exports[`Parameter > api.test.domain 1`] = `
44
"[
55
{
66
"operationId": "getIncludeLocalReference",
@@ -670,4 +670,4 @@ exports[`Parameter api.test.domain 1`] = `
670670
]"
671671
`;
672672

673-
exports[`Parameter infer.domain 1`] = `"[]"`;
673+
exports[`Parameter > infer.domain 1`] = `"[]"`;

test/__tests__/class/__snapshots__/spit-code-test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`Split Code apiClient 1`] = `
3+
exports[`Split Code > apiClient 1`] = `
44
"//
55
// Generated by @himenon/openapi-typescript-code-generator
66
//
@@ -285,7 +285,7 @@ export class Client<RequestOption> {
285285
"
286286
`;
287287
288-
exports[`Split Code types 1`] = `
288+
exports[`Split Code > types 1`] = `
289289
"//
290290
// Generated by @himenon/openapi-typescript-code-generator
291291
//

test/__tests__/class/__snapshots__/template-only-test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`Template Only api.test.domain 1`] = `
3+
exports[`Template Only > api.test.domain 1`] = `
44
"//
55
// Generated by @himenon/openapi-typescript-code-generator
66
//
@@ -190,7 +190,7 @@ export class Client<RequestOption> {
190190
"
191191
`;
192192
193-
exports[`Template Only async-api.test.domain 1`] = `
193+
exports[`Template Only > async-api.test.domain 1`] = `
194194
"//
195195
// Generated by @himenon/openapi-typescript-code-generator
196196
//
@@ -380,7 +380,7 @@ export class Client<RequestOption> {
380380
"
381381
`;
382382
383-
exports[`Template Only infer.domain 1`] = `
383+
exports[`Template Only > infer.domain 1`] = `
384384
"//
385385
// Generated by @himenon/openapi-typescript-code-generator
386386
//

test/__tests__/class/__snapshots__/typedef-only-test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`Typedef only Reference test that include nested properties 1`] = `
3+
exports[`Typedef only > Reference test that include nested properties 1`] = `
44
"//
55
// Generated by @himenon/openapi-typescript-code-generator
66
//
@@ -34,7 +34,7 @@ export namespace Schemas {
3434
"
3535
`;
3636

37-
exports[`Typedef only typedef-api.test.domain 1`] = `
37+
exports[`Typedef only > typedef-api.test.domain 1`] = `
3838
"//
3939
// Generated by @himenon/openapi-typescript-code-generator
4040
//
@@ -334,7 +334,7 @@ export namespace RequestBodies {
334334
"
335335
`;
336336

337-
exports[`Typedef only typedef-infer.domain 1`] = `
337+
exports[`Typedef only > typedef-infer.domain 1`] = `
338338
"//
339339
// Generated by @himenon/openapi-typescript-code-generator
340340
//

0 commit comments

Comments
 (0)