Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/generator/plugin/body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function makeView(type: Type): Schema {
let kind: Kind | undefined;
switch (type.scalar) {
case "string":
case "uuid":
case "date":
case "date-time":
case "bytes":
Expand Down
1 change: 1 addition & 0 deletions packages/cli/generator/plugin/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ function simpleType(type: Type): string | undefined {
case "boolean":
return "boolean";
case "string":
case "uuid":
case "date":
case "date-time":
case "bytes":
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"@cloudflare/codemods": "0.5.1",
"@cloudflare/containers-shared": "0.23.0",
"@cloudflare/deploy-helpers": "0.22.0",
"@cloudflare/forge": "https://pkg.pr.new/cloudflare/forge/@cloudflare/forge@7e230c1f40514ceffe7001823c158f4f0380f7bd",
"@cloudflare/forge": "https://pkg.pr.new/cloudflare/forge/@cloudflare/forge@ca70d7f5d88da223e243bca25810199876242ea6",
"@cloudflare/workers-auth": "0.14.0",
"@cloudflare/workers-utils": "0.47.2",
"@types/node": "25.9.9",
Expand Down
58 changes: 58 additions & 0 deletions packages/cli/src/__tests__/generator/plugin/forge-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,64 @@ function listing(schema: Json) {
}

describe("the forge model", () => {
it("keeps UUID body fields and referenced UUID arrays as string flags", () => {
const files = generateFiles(
create(
{
type: "object",
required: ["id"],
properties: {
id: { type: "string", format: "uuid" },
parent_id: { type: "string", format: "uuid", nullable: true },
dataset_ids: {
type: "array",
minItems: 1,
maxItems: 50,
items: { $ref: "#/components/schemas/ID" },
},
},
},
{ ID: { type: "string", format: "uuid" } }
)
);
const code = files.get("things/create.ts") ?? "";
expect(code).toContain('.option(\'id\', {"type":"string"');
expect(code).toContain('.option(\'parent-id\', {"type":"string"');
expect(code).toContain(
'.option(\'dataset-ids\', {"type":"string","array":true'
);
expect(code).toContain("promptForRequiredField('id'");
expect(code).toContain('id: resolveFileToken(argv["id"]');
expect(code).toContain('parent_id: resolveFileToken(argv["parent-id"]');
expect(code).toContain('dataset_ids: argv["dataset-ids"]');
const metadata = JSON.parse(files.get("_meta/commands.json") ?? "{}");
expect(metadata.commands[0].options).toEqual(
expect.arrayContaining([
expect.objectContaining({ name: "id", type: "string", required: true }),
expect.objectContaining({ name: "parent-id", type: "string" }),
expect.objectContaining({ name: "dataset-ids", type: "string" }),
])
);
});

it.each([
{ type: "string", format: "uuid" },
{ type: "string", format: "uuid", nullable: true },
{
anyOf: [
{ type: "string", format: "uuid" },
{ type: "array", items: { type: "string", format: "uuid" } },
],
},
])("keeps UUID query parameters as strings: %j", (schema) => {
const files = generateFiles(listing(schema));
const schemas = JSON.parse(files.get("_meta/schemas.json") ?? "{}");
expect(schemas.schemas["things list"].queryParams[0].type).toBe("string");
expect(files.get("things/list.ts")).toContain(
'.option(\'status\', {"type":"string"'
);
});

it("retains required and optional scalar intersections and their enum constraints", () => {
const d = create(
{
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/helpers/forge-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function plugin(): string {
entry,
[
`import { definePlugin } from ${specifier(require.resolve("@cloudflare/forge/plugin"))};`,
'import { info } from "forge:plugin/forge@0.2.0";',
'import { info } from "forge:plugin/forge@0.3.0";',
`import { generateCli, generateCliGroup } from ${specifier(fileURLToPath(new URL("../../../generator/plugin/index.ts", import.meta.url)))};`,
"",
"const config = () => JSON.parse(info().version);",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading