Skip to content

Commit e40f9a7

Browse files
chore: update Forge for UUID scalars
1 parent 768a01d commit e40f9a7

6 files changed

Lines changed: 67 additions & 7 deletions

File tree

‎packages/cli/generator/plugin/body.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ function makeView(type: Type): Schema {
106106
let kind: Kind | undefined;
107107
switch (type.scalar) {
108108
case "string":
109+
case "uuid":
109110
case "date":
110111
case "date-time":
111112
case "bytes":

‎packages/cli/generator/plugin/operation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ function simpleType(type: Type): string | undefined {
374374
case "boolean":
375375
return "boolean";
376376
case "string":
377+
case "uuid":
377378
case "date":
378379
case "date-time":
379380
case "bytes":

‎packages/cli/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"@cloudflare/codemods": "0.5.1",
8686
"@cloudflare/containers-shared": "0.23.0",
8787
"@cloudflare/deploy-helpers": "0.22.0",
88-
"@cloudflare/forge": "https://pkg.pr.new/cloudflare/forge/@cloudflare/forge@7e230c1f40514ceffe7001823c158f4f0380f7bd",
88+
"@cloudflare/forge": "https://pkg.pr.new/cloudflare/forge/@cloudflare/forge@ca70d7f5d88da223e243bca25810199876242ea6",
8989
"@cloudflare/workers-auth": "0.14.0",
9090
"@cloudflare/workers-utils": "0.47.2",
9191
"@types/node": "25.9.9",

‎packages/cli/src/__tests__/generator/plugin/forge-model.test.ts‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,64 @@ function listing(schema: Json) {
110110
}
111111

112112
describe("the forge model", () => {
113+
it("keeps UUID body fields and referenced UUID arrays as string flags", () => {
114+
const files = generateFiles(
115+
create(
116+
{
117+
type: "object",
118+
required: ["id"],
119+
properties: {
120+
id: { type: "string", format: "uuid" },
121+
parent_id: { type: "string", format: "uuid", nullable: true },
122+
dataset_ids: {
123+
type: "array",
124+
minItems: 1,
125+
maxItems: 50,
126+
items: { $ref: "#/components/schemas/ID" },
127+
},
128+
},
129+
},
130+
{ ID: { type: "string", format: "uuid" } }
131+
)
132+
);
133+
const code = files.get("things/create.ts") ?? "";
134+
expect(code).toContain('.option(\'id\', {"type":"string"');
135+
expect(code).toContain('.option(\'parent-id\', {"type":"string"');
136+
expect(code).toContain(
137+
'.option(\'dataset-ids\', {"type":"string","array":true'
138+
);
139+
expect(code).toContain("promptForRequiredField('id'");
140+
expect(code).toContain('id: resolveFileToken(argv["id"]');
141+
expect(code).toContain('parent_id: resolveFileToken(argv["parent-id"]');
142+
expect(code).toContain('dataset_ids: argv["dataset-ids"]');
143+
const metadata = JSON.parse(files.get("_meta/commands.json") ?? "{}");
144+
expect(metadata.commands[0].options).toEqual(
145+
expect.arrayContaining([
146+
expect.objectContaining({ name: "id", type: "string", required: true }),
147+
expect.objectContaining({ name: "parent-id", type: "string" }),
148+
expect.objectContaining({ name: "dataset-ids", type: "string" }),
149+
])
150+
);
151+
});
152+
153+
it.each([
154+
{ type: "string", format: "uuid" },
155+
{ type: "string", format: "uuid", nullable: true },
156+
{
157+
anyOf: [
158+
{ type: "string", format: "uuid" },
159+
{ type: "array", items: { type: "string", format: "uuid" } },
160+
],
161+
},
162+
])("keeps UUID query parameters as strings: %j", (schema) => {
163+
const files = generateFiles(listing(schema));
164+
const schemas = JSON.parse(files.get("_meta/schemas.json") ?? "{}");
165+
expect(schemas.schemas["things list"].queryParams[0].type).toBe("string");
166+
expect(files.get("things/list.ts")).toContain(
167+
'.option(\'status\', {"type":"string"'
168+
);
169+
});
170+
113171
it("retains required and optional scalar intersections and their enum constraints", () => {
114172
const d = create(
115173
{

‎packages/cli/src/__tests__/helpers/forge-cli.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function plugin(): string {
5252
entry,
5353
[
5454
`import { definePlugin } from ${specifier(require.resolve("@cloudflare/forge/plugin"))};`,
55-
'import { info } from "forge:plugin/forge@0.2.0";',
55+
'import { info } from "forge:plugin/forge@0.3.0";',
5656
`import { generateCli, generateCliGroup } from ${specifier(fileURLToPath(new URL("../../../generator/plugin/index.ts", import.meta.url)))};`,
5757
"",
5858
"const config = () => JSON.parse(info().version);",

‎pnpm-lock.yaml‎

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)