Skip to content

Commit 2f56deb

Browse files
Himenonclaude
andcommitted
fix: escape double quotes in generated string literals and enum values
fix: type-checkエラーをすべて解消 - tsconfig.json: test/code/をexcludeに追加(生成済みフィクスチャは型チェック対象外) - factory/index.ts: string enum値とLiteralTypeNodeのダブルクォートをエスケープ処理 - test/__tests__/**/*.ts: vitestのdescribe/test/expectを明示的にimport - examples/readme-sample/*.ts: Params APIの変更(functionName→convertedParams.functionName, comment→operationParams.comment)に対応 - scripts/tools/shell.ts: ExecaChildProcessをexeca v9のResultPromiseに置換 - .github/workflows/build.yml: pnpm type-checkをCIに追加 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f298063 commit 2f56deb

35 files changed

Lines changed: 75 additions & 22 deletions

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
- name: Test & Build
3434
run: |
3535
pnpm build
36+
pnpm type-check
3637
pnpm test:code:gen
3738
pnpm test
3839
env:

examples/readme-sample/ast-code-template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const generator: Types.CodeGenerator.GenerateFunction<Option> = (
1212
return payload.map(params => {
1313
return factory.InterfaceDeclaration.create({
1414
export: true,
15-
name: params.functionName,
15+
name: params.convertedParams.functionName,
1616
members: [],
1717
});
1818
});

examples/readme-sample/generator-template.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CodeGenerator } from "@himenon/openapi-typescript-code-generator";
44
import type * as Types from "@himenon/openapi-typescript-code-generator/dist/types";
55

66
/** ここにCode Templateの定義を記述してください */
7+
// @ts-ignore -- placeholder example, generator is intentionally omitted
78
const customGenerator: Types.CodeGenerator.CustomGenerator<{}> = {
89
/** .... */
910
};

examples/readme-sample/use-extract-schema-params.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type Option = {};
44

55
const generator: Types.CodeGenerator.GenerateFunction<Option> = (payload: Types.CodeGenerator.Params[]): string[] => {
66
return payload.map(params => {
7-
return `function ${params.operationId}() { console.log("${params.comment}") }`;
7+
return `function ${params.operationId}() { console.log("${params.operationParams.comment}") }`;
88
});
99
};
1010

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"test:snapshot": "vitest run --config ./vitest.snapshot.config.ts",
7474
"test:vitest": "vitest run --config ./vitest.config.ts --coverage",
7575
"ts": "node --no-warnings=ExperimentalWarning --experimental-specifier-resolution=node --loader ts-node/esm",
76+
"type-check": "tsc --noEmit",
7677
"update:snapshot": "vitest run --config ./vitest.snapshot.config.ts --update",
7778
"validate": "pnpm ts ./scripts/validate.ts",
7879
"watch": "pnpm ts ./scripts/watch.ts"

scripts/tools/shell.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ExecaChildProcess, execa } from "execa";
1+
import { type ResultPromise, execa } from "execa";
22

3-
export const shell = (command: string, cwd: string = process.cwd()): ExecaChildProcess<string> => {
3+
export const shell = (command: string, cwd: string = process.cwd()): ResultPromise => {
44
return execa(command, {
55
stdio: ["pipe", "pipe", "inherit"],
66
shell: true,

src/internal/TsGenerator/factory/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ export const create = (): Type => {
228228
create(p) {
229229
const node = (() => {
230230
if (typeof p.value === "string") {
231-
return `"${p.value}"`;
231+
const escaped = p.value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
232+
return `"${escaped}"`;
232233
}
233234
if (typeof p.value === "number") {
234235
return `${p.value}`;
@@ -244,7 +245,7 @@ export const create = (): Type => {
244245
switch (p.type) {
245246
case "string":
246247
if (p.enum) {
247-
return p.enum.map(v => `"${v}"`).join(" | ");
248+
return p.enum.map(v => `"${v.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`).join(" | ");
248249
}
249250
return "string";
250251
case "number":

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10459,7 +10459,7 @@ mode?: string;
1045910459
port?: number;
1046010460
}
1046110461
/** The session_affinity specifies the type of session affinity the load balancer should use unless specified as "none" or ""(default). The supported types are "cookie" and "ip_cookie". "cookie" - On the first request to a proxied load balancer, a cookie is generated, encoding information of which origin the request will be forwarded to. Subsequent requests, by the same client to the same load balancer, will be sent to the origin server the cookie encodes, for the duration of the cookie and as long as the origin server remains healthy. If the cookie has expired or the origin server is unhealthy then a new origin server is calculated and used. "ip_cookie" behaves the same as "cookie" except the initial origin selection is stable and based on the client’s ip address. */
10462-
export type legacy$jhs_session_affinity = "none" | "cookie" | "ip_cookie" | """";
10462+
export type legacy$jhs_session_affinity = "none" | "cookie" | "ip_cookie" | "\\"\\"";
1046310463
/** Configures cookie attributes for session affinity cookie. */
1046410464
export interface legacy$jhs_session_affinity_attributes {
1046510465
/** Configures the drain duration in seconds. This field is only used when session affinity is enabled on the load balancer. */
@@ -10611,7 +10611,7 @@ export type legacy$jhs_std_dev_rtt_ms = number;
1061110611
* - \`"proximity"\`: Use the pools' latitude and longitude to select the closest pool using the Cloudflare PoP location for proxied requests or the location determined by \`location_strategy\` for non-proxied requests.
1061210612
* - \`""\`: Will map to \`"geo"\` if you use \`region_pools\`/\`country_pools\`/\`pop_pools\` otherwise \`"off"\`.
1061310613
*/
10614-
export type legacy$jhs_steering_policy = "off" | "geo" | "random" | "dynamic_latency" | "proximity" | """";
10614+
export type legacy$jhs_steering_policy = "off" | "geo" | "random" | "dynamic_latency" | "proximity" | "\\"\\"";
1061510615
/** STIX 2.1 identifier: https://docs.oasis-open.org/cti/stix/v2.1/cs02/stix-v2.1-cs02.html#_64yvzeku5a5c */
1061610616
export type legacy$jhs_stix_identifier = string;
1061710617
export type legacy$jhs_subdomain$response = Schemas.legacy$jhs_api$response$common & {
@@ -11427,7 +11427,7 @@ policy?: "random" | "hash" | "least_outstanding_requests" | "least_connections";
1142711427
/** The list of origins within this pool. Traffic directed at this pool is balanced across all currently healthy origins, provided the pool itself is healthy. */
1142811428
export type load$balancing_origins = Schemas.load$balancing_origin[];
1142911429
/** The email address to send health status notifications to. This field is now deprecated in favor of Cloudflare Notifications for Load Balancing, so only resetting this field with an empty string \`""\` is accepted. */
11430-
export type load$balancing_patch_pools_notification_email = """";
11430+
export type load$balancing_patch_pools_notification_email = "\\"\\"";
1143111431
/** The endpoint path you want to conduct a health check against. This parameter is only valid for HTTP and HTTPS monitors. */
1143211432
export type load$balancing_path = string;
1143311433
export interface load$balancing_pool {
@@ -11617,7 +11617,7 @@ references?: "" | "*" | "referral" | "referrer";
1161711617
* - \`"ip_cookie"\`: Behaves the same as \`"cookie"\` except the initial origin selection is stable and based on the client's ip address.
1161811618
* - \`"header"\`: On the first request to a proxied load balancer, a session key based on the configured HTTP headers (see \`session_affinity_attributes.headers\`) is generated, encoding the request headers used for storing in the load balancer session state which origin the request will be forwarded to. Subsequent requests to the load balancer with the same headers will be sent to the same origin server, for the duration of the session and as long as the origin server remains healthy. If the session has been idle for the duration of \`session_affinity_ttl\` seconds or the origin server is unhealthy, then a new origin server is calculated and used. See \`headers\` in \`session_affinity_attributes\` for additional required configuration.
1161911619
*/
11620-
export type load$balancing_session_affinity = "none" | "cookie" | "ip_cookie" | "header" | """";
11620+
export type load$balancing_session_affinity = "none" | "cookie" | "ip_cookie" | "header" | "\\"\\"";
1162111621
/** Configures attributes for session affinity. */
1162211622
export interface load$balancing_session_affinity_attributes {
1162311623
/** Configures the drain duration in seconds. This field is only used when session affinity is enabled on the load balancer. */
@@ -11659,7 +11659,7 @@ export type load$balancing_session_affinity_ttl = number;
1165911659
* - \`"least_connections"\`: Select a pool by taking into consideration \`random_steering\` weights, as well as each pool's number of open connections. Pools with more open connections are weighted proportionately less relative to others. Supported for HTTP/1 and HTTP/2 connections.
1166011660
* - \`""\`: Will map to \`"geo"\` if you use \`region_pools\`/\`country_pools\`/\`pop_pools\` otherwise \`"off"\`.
1166111661
*/
11662-
export type load$balancing_steering_policy = "off" | "geo" | "random" | "dynamic_latency" | "proximity" | "least_outstanding_requests" | "least_connections" | """";
11662+
export type load$balancing_steering_policy = "off" | "geo" | "random" | "dynamic_latency" | "proximity" | "least_outstanding_requests" | "least_connections" | "\\"\\"";
1166311663
/** Two-letter subdivision code followed in ISO 3166-2. */
1166411664
export type load$balancing_subdivision_code_a2 = string;
1166511665
/** The timeout (in seconds) before marking the health check as failed. */

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, test } from "vitest";
2+
13
import * as fs from "fs";
24

35
import * as Utils from "../../utils";

test/__tests__/class/cloudflare-test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, test } from "vitest";
2+
13
import * as fs from "fs";
24

35
import * as Utils from "../../utils";

0 commit comments

Comments
 (0)