Skip to content

Commit f09a938

Browse files
committed
wip
1 parent 4051d38 commit f09a938

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

scripts/gen-client.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,14 @@ async function processSchema(schema: OpenApiSchema): Promise<void> {
776776
const fullYamlPath = `${tagsDir}/${tagPath}` as const;
777777
const yamlStr = await Bun.file(fullYamlPath).text();
778778
const schema = Bun.YAML.parse(yamlStr);
779-
const tagSchema = TagSchemaSchema.parse(schema);
780-
const newMethods = processTag(tagSchema, rawApiPath);
779+
console.log(`Parsing ${tagPath}`);
780+
const tagSchema = TagSchemaSchema.safeParse(schema);
781+
if (tagSchema.error) {
782+
console.error(`Error while parsing ${tagSchema}`);
783+
console.error(z.prettifyError(tagSchema.error));
784+
throw tagSchema.error;
785+
}
786+
const newMethods = processTag(tagSchema.data, rawApiPath);
781787
methodsCode.push(...newMethods);
782788
}
783789

scripts/gen-schemas.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { readdirSync } from "node:fs";
22
import * as fs from "node:fs/promises";
33
import * as path from "node:path";
4+
import { ZodError } from "zod";
45
import { prettifyError } from "zod/mini";
56
import { convertToZod, SchemaSchema } from "./shared";
67

@@ -10,15 +11,24 @@ async function processFile(filePath: string) {
1011
const yamlStr = await Bun.file(normalizedFilePath).text();
1112
const yamlContent = Bun.YAML.parse(yamlStr);
1213
const parsedSchema = SchemaSchema.safeParse(yamlContent);
13-
console.log(`Parsing ${normalizedFilePath}`);
1414
if (parsedSchema.error) {
1515
console.error(`Error while parsing ${normalizedFilePath}`);
1616
console.error(prettifyError(parsedSchema.error));
1717
throw parsedSchema.error;
1818
}
19-
const { zodSchema, refs: uniqueRefs } = convertToZod(parsedSchema.data);
19+
const { zodSchema, refs } = (() => {
20+
try {
21+
return convertToZod(parsedSchema.data);
22+
} catch (e) {
23+
if (e instanceof ZodError) {
24+
console.error(`Error while converting ${normalizedFilePath}`);
25+
console.error(prettifyError(e));
26+
}
27+
throw e;
28+
}
29+
})();
2030

21-
const refImports = uniqueRefs
31+
const refImports = refs
2232
.toSorted()
2333
.map((refName) => `import { ${refName} } from "./${refName}";` as const)
2434
.join("\n");

scripts/shared.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ const BaseSchema = z.object({
2121
});
2222

2323
const StringYamlRef = z
24-
.string()
25-
.refine((str) => str.endsWith(".yaml"))
24+
.templateLiteral([z.string(), ".yaml"])
2625
.brand("StringYamlRef");
2726

2827
export const SchemaSchemaRef = BaseSchema.extend({

0 commit comments

Comments
 (0)