Skip to content

Commit a67778a

Browse files
committed
fix: web playground + rm cjs output + mv prettify out of generateFile
1 parent 6fa6252 commit a67778a

File tree

11 files changed

+373
-631
lines changed

11 files changed

+373
-631
lines changed

packages/typed-openapi/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"@types/prettier": "3.0.0",
3737
"tsup": "^8.4.0",
3838
"typescript": "^5.8.3",
39-
"vite-node": "^3.1.3",
4039
"vitest": "^3.1.3"
4140
},
4241
"files": [

packages/typed-openapi/src/cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { allowedRuntimes, generateFile } from "./generator.ts";
99
import { mapOpenApiEndpoints } from "./map-openapi-endpoints.ts";
1010
import { generateTanstackQueryFile } from "./tanstack-query.generator.ts";
1111
import { readFileSync } from "fs";
12+
import { prettify } from "./format.ts";
1213

1314
const { name, version } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
1415
const cwd = process.cwd();
@@ -33,7 +34,7 @@ cli
3334
const ctx = mapOpenApiEndpoints(openApiDoc);
3435
console.log(`Found ${ctx.endpointList.length} endpoints`);
3536

36-
const content = await generateFile({ ...ctx, runtime: options.runtime });
37+
const content = await prettify(generateFile({ ...ctx, runtime: options.runtime }));
3738
const outputPath = join(
3839
cwd,
3940
options.output ?? input + `.${options.runtime === "none" ? "client" : options.runtime}.ts`,

packages/typed-openapi/src/generator.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { capitalize, groupBy } from "pastable/server";
22
import { Box } from "./box.ts";
3-
import { prettify } from "./format.ts";
43
import { mapOpenApiEndpoints } from "./map-openapi-endpoints.ts";
54
import { AnyBox, AnyBoxDef } from "./types.ts";
65
import * as Codegen from "@sinclair/typebox-codegen";
@@ -53,7 +52,7 @@ const replacerByRuntime = {
5352
.replace(new RegExp(`(${endpointExport.source})` + new RegExp(/([\s\S]*? )(z\.object)(\()/).source, "g"), "$1$2("),
5453
};
5554

56-
export const generateFile = async (options: GeneratorOptions) => {
55+
export const generateFile = (options: GeneratorOptions) => {
5756
const ctx = { ...options, runtime: options.runtime ?? "none" } as GeneratorContext;
5857

5958
const schemaList = generateSchemaList(ctx);
@@ -93,7 +92,7 @@ export const generateFile = async (options: GeneratorOptions) => {
9392
${apiClient}
9493
`;
9594

96-
return prettify(file);
95+
return (file);
9796
};
9897

9998
const generateSchemaList = ({ refs, runtime }: GeneratorContext) => {

packages/typed-openapi/tests/generate-runtime.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ samples.forEach((sample) => {
1717
runtimes.forEach((runtime: string) => {
1818
if (runtime === "arktype" && sample === "docker.openapi") return;
1919

20-
test(`generate ${runtime}`, async () => {
21-
const tsRouter = await generateFile({ ...ctx, runtime: runtime as any });
20+
test(`generate ${runtime}`, () => {
21+
const tsRouter = generateFile({ ...ctx, runtime: runtime as any });
2222
const runtimeName = runtime === "none" ? "client" : runtime;
23-
await expect(tsRouter).toMatchFileSnapshot(`./snapshots/${sample}.` + runtimeName + ".ts");
23+
expect(tsRouter).toMatchFileSnapshot(`./snapshots/${sample}.` + runtimeName + ".ts");
2424
});
2525
});
2626
});

packages/typed-openapi/tests/generator-basic-schemas.test.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,33 @@ const makeCtx = (schemas: SchemasObject): OpenapiSchemaConvertContext => ({
1515
});
1616
const makeDoc = (schemas: SchemasObject) => ({ components: { schemas } } as any);
1717

18-
const getSchemaBox = async (schema: LibSchemaObject) => {
19-
const output = await generateFile(mapOpenApiEndpoints(makeDoc({ _Test: schema })));
18+
const getSchemaBox = (schema: LibSchemaObject) => {
19+
const output = generateFile(mapOpenApiEndpoints(makeDoc({ _Test: schema })));
2020
const start = output.indexOf("// <Schemas>");
2121
const end = output.indexOf("// </Schemas>");
2222
return output.substring(start + "// <Schemas>".length, end).trim();
2323
};
2424

2525
test("getSchemaBox", async () => {
26-
expect(await getSchemaBox({ type: "null" })).toMatchInlineSnapshot('"export type _Test = null;"');
27-
expect(await getSchemaBox({ type: "boolean" })).toMatchInlineSnapshot('"export type _Test = boolean;"');
28-
expect(await getSchemaBox({ type: "boolean", nullable: true })).toMatchInlineSnapshot('"export type _Test = boolean | null;"');
29-
expect(await getSchemaBox({ type: "string" })).toMatchInlineSnapshot('"export type _Test = string;"');
30-
expect(await getSchemaBox({ type: "number" })).toMatchInlineSnapshot('"export type _Test = number;"');
31-
expect(await getSchemaBox({ type: "integer" })).toMatchInlineSnapshot('"export type _Test = number;"');
32-
expect(await getSchemaBox({})).toMatchInlineSnapshot('"export type _Test = unknown;"');
33-
34-
expect(await getSchemaBox({ type: "array", items: { type: "string" } })).toMatchInlineSnapshot('"export type _Test = Array<string>;"');
35-
expect(await getSchemaBox({ type: "object" })).toMatchInlineSnapshot(
26+
expect(getSchemaBox({ type: "null" })).toMatchInlineSnapshot('"export type _Test = null;"');
27+
expect(getSchemaBox({ type: "boolean" })).toMatchInlineSnapshot('"export type _Test = boolean;"');
28+
expect(getSchemaBox({ type: "boolean", nullable: true })).toMatchInlineSnapshot('"export type _Test = boolean | null;"');
29+
expect(getSchemaBox({ type: "string" })).toMatchInlineSnapshot('"export type _Test = string;"');
30+
expect(getSchemaBox({ type: "number" })).toMatchInlineSnapshot('"export type _Test = number;"');
31+
expect(getSchemaBox({ type: "integer" })).toMatchInlineSnapshot('"export type _Test = number;"');
32+
expect(getSchemaBox({})).toMatchInlineSnapshot('"export type _Test = unknown;"');
33+
34+
expect(getSchemaBox({ type: "array", items: { type: "string" } })).toMatchInlineSnapshot('"export type _Test = Array<string>;"');
35+
expect(getSchemaBox({ type: "object" })).toMatchInlineSnapshot(
3636
'"export type _Test = Record<string, unknown>;"',
3737
);
38-
expect(await getSchemaBox({ type: "object", properties: { str: { type: "string" } } })).toMatchInlineSnapshot('"export type _Test = Partial<{ str: string }>;"');
39-
expect(await getSchemaBox({ type: "object", properties: { str: { type: "string" }, nb: { type: "number" } } }))
38+
expect(getSchemaBox({ type: "object", properties: { str: { type: "string" } } })).toMatchInlineSnapshot('"export type _Test = Partial<{ str: string }>;"');
39+
expect(getSchemaBox({ type: "object", properties: { str: { type: "string" }, nb: { type: "number" } } }))
4040
.toMatchInlineSnapshot('"export type _Test = Partial<{ str: string; nb: number }>;"');
4141

4242
// AllPropertiesRequired
4343
expect(
44-
await getSchemaBox({
44+
getSchemaBox({
4545
type: "object",
4646
properties: { str: { type: "string" }, nb: { type: "number" } },
4747
required: ["str", "nb"],
@@ -50,7 +50,7 @@ test("getSchemaBox", async () => {
5050

5151
// SomeOptionalProps
5252
expect(
53-
await getSchemaBox({
53+
getSchemaBox({
5454
type: "object",
5555
properties: { str: { type: "string" }, nb: { type: "number" } },
5656
required: ["str"],
@@ -59,7 +59,7 @@ test("getSchemaBox", async () => {
5959

6060
// ObjectWithNestedProp
6161
expect(
62-
await getSchemaBox({
62+
getSchemaBox({
6363
type: "object",
6464
properties: {
6565
str: { type: "string" },
@@ -76,20 +76,20 @@ test("getSchemaBox", async () => {
7676

7777
// ObjectWithAdditionalPropsNb
7878
expect(
79-
await getSchemaBox({ type: "object", properties: { str: { type: "string" } }, additionalProperties: { type: "number" } }),
79+
getSchemaBox({ type: "object", properties: { str: { type: "string" } }, additionalProperties: { type: "number" } }),
8080
).toMatchInlineSnapshot('"export type _Test = Partial<{ str: string } & { string: number }>;"');
8181

8282
// ObjectWithNestedRecordBoolean
8383
expect(
84-
await getSchemaBox({
84+
getSchemaBox({
8585
type: "object",
8686
properties: { str: { type: "string" } },
8787
additionalProperties: { type: "object", properties: { prop: { type: "boolean" } } },
8888
}),
8989
).toMatchInlineSnapshot('"export type _Test = Partial<{ str: string } & { string: Partial<{ prop: boolean }> }>;"');
9090

9191
expect(
92-
await getSchemaBox({
92+
getSchemaBox({
9393
type: "array",
9494
items: {
9595
type: "object",
@@ -101,7 +101,7 @@ test("getSchemaBox", async () => {
101101
).toMatchInlineSnapshot('"export type _Test = Array<Partial<{ str: string }>>;"');
102102

103103
expect(
104-
await getSchemaBox({
104+
getSchemaBox({
105105
type: "array",
106106
items: {
107107
type: "array",
@@ -114,54 +114,54 @@ test("getSchemaBox", async () => {
114114

115115
// ObjectWithEnum
116116
expect(
117-
await getSchemaBox({
117+
getSchemaBox({
118118
type: "object",
119119
properties: {
120120
enumprop: { type: "string", enum: ["aaa", "bbb", "ccc"] },
121121
},
122122
}),
123123
).toMatchInlineSnapshot('"export type _Test = Partial<{ enumprop: "aaa" | "bbb" | "ccc" }>;"');
124124

125-
expect(await getSchemaBox({ type: "string", enum: ["aaa", "bbb", "ccc"] })).toMatchInlineSnapshot(
125+
expect(getSchemaBox({ type: "string", enum: ["aaa", "bbb", "ccc"] })).toMatchInlineSnapshot(
126126
'"export type _Test = "aaa" | "bbb" | "ccc";"',
127127
);
128128

129129
// StringENum
130-
expect(await getSchemaBox({ type: "string", enum: ["aaa", "bbb", "ccc"] })).toMatchInlineSnapshot('"export type _Test = "aaa" | "bbb" | "ccc";"');
130+
expect(getSchemaBox({ type: "string", enum: ["aaa", "bbb", "ccc"] })).toMatchInlineSnapshot('"export type _Test = "aaa" | "bbb" | "ccc";"');
131131

132132
// ObjectWithUnion
133133
expect(
134-
await getSchemaBox({
134+
getSchemaBox({
135135
type: "object",
136136
properties: {
137137
union: { oneOf: [{ type: "string" }, { type: "number" }] },
138138
},
139139
}),
140140
).toMatchInlineSnapshot('"export type _Test = Partial<{ union: string | number }>;"');
141-
expect(await getSchemaBox({ oneOf: [{ type: "string" }, { type: "number" }] })).toMatchInlineSnapshot(
141+
expect(getSchemaBox({ oneOf: [{ type: "string" }, { type: "number" }] })).toMatchInlineSnapshot(
142142
'"export type _Test = string | number;"',
143143
);
144144

145145
// StringOrNumber
146-
expect(await getSchemaBox({ oneOf: [{ type: "string" }, { type: "number" }] })).toMatchInlineSnapshot('"export type _Test = string | number;"');
146+
expect(getSchemaBox({ oneOf: [{ type: "string" }, { type: "number" }] })).toMatchInlineSnapshot('"export type _Test = string | number;"');
147147

148-
expect(await getSchemaBox({ allOf: [{ type: "string" }, { type: "number" }] })).toMatchInlineSnapshot(
148+
expect(getSchemaBox({ allOf: [{ type: "string" }, { type: "number" }] })).toMatchInlineSnapshot(
149149
'"export type _Test = string & number;"',
150150
);
151151

152152
// StringAndNumber
153-
expect(await getSchemaBox({ allOf: [{ type: "string" }, { type: "number" }] })).toMatchInlineSnapshot('"export type _Test = string & number;"');
153+
expect(getSchemaBox({ allOf: [{ type: "string" }, { type: "number" }] })).toMatchInlineSnapshot('"export type _Test = string & number;"');
154154

155-
expect(await getSchemaBox({ anyOf: [{ type: "string" }, { type: "number" }] })).toMatchInlineSnapshot(
155+
expect(getSchemaBox({ anyOf: [{ type: "string" }, { type: "number" }] })).toMatchInlineSnapshot(
156156
'"export type _Test = string | number | Array<string | number>;"',
157157
);
158158

159159
// StringAndNumberMaybeMultiple
160-
expect(await getSchemaBox({ anyOf: [{ type: "string" }, { type: "number" }] })).toMatchInlineSnapshot('"export type _Test = string | number | Array<string | number>;"');
160+
expect(getSchemaBox({ anyOf: [{ type: "string" }, { type: "number" }] })).toMatchInlineSnapshot('"export type _Test = string | number | Array<string | number>;"');
161161

162162
// ObjectWithArrayUnion
163163
expect(
164-
await getSchemaBox({
164+
getSchemaBox({
165165
type: "object",
166166
properties: {
167167
unionOrArrayOfUnion: { anyOf: [{ type: "string" }, { type: "number" }] },
@@ -171,18 +171,18 @@ test("getSchemaBox", async () => {
171171

172172
// ObjectWithIntersection
173173
expect(
174-
await getSchemaBox({
174+
getSchemaBox({
175175
type: "object",
176176
properties: {
177177
intersection: { allOf: [{ type: "string" }, { type: "number" }] },
178178
},
179179
}),
180180
).toMatchInlineSnapshot('"export type _Test = Partial<{ intersection: string & number }>;"');
181181

182-
expect(await getSchemaBox({ type: "string", enum: ["aaa", "bbb", "ccc"] })).toMatchInlineSnapshot(
182+
expect(getSchemaBox({ type: "string", enum: ["aaa", "bbb", "ccc"] })).toMatchInlineSnapshot(
183183
'"export type _Test = "aaa" | "bbb" | "ccc";"',
184184
);
185-
expect(await getSchemaBox({ type: "number", enum: [1, 2, 3] })).toMatchInlineSnapshot('"export type _Test = 1 | 2 | 3;"');
185+
expect(getSchemaBox({ type: "number", enum: [1, 2, 3] })).toMatchInlineSnapshot('"export type _Test = 1 | 2 | 3;"');
186186
});
187187

188188
describe("getSchemaBox with context", () => {

packages/typed-openapi/tests/generator.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { generateFile } from "../src/generator.ts";
77
describe("generator", () => {
88
test("petstore", async ({ expect }) => {
99
const openApiDoc = (await SwaggerParser.parse("./tests/samples/petstore.yaml")) as OpenAPIObject;
10-
expect(await generateFile(mapOpenApiEndpoints(openApiDoc))).toMatchInlineSnapshot(`
10+
expect(generateFile(mapOpenApiEndpoints(openApiDoc))).toMatchInlineSnapshot(`
1111
"export namespace Schemas {
1212
// <Schemas>
1313
export type Order = Partial<{
@@ -380,8 +380,8 @@ describe("generator", () => {
380380
`);
381381
});
382382

383-
test("nullable string", async ({ expect }) => {
384-
expect(await generateFile(mapOpenApiEndpoints({
383+
test("nullable string", ({ expect }) => {
384+
expect(generateFile(mapOpenApiEndpoints({
385385
"openapi": "3.0.0",
386386
"info": {
387387
"version": "1.0.0",

packages/typed-openapi/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ export default defineConfig({
44
entryPoints: ["src/cli.ts", "src/index.ts"],
55
outDir: "dist",
66
dts: true,
7-
format: ["cjs", "esm"],
7+
format: ["esm"],
88
});

packages/web/package.json

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,52 @@
1212
"test": "vitest"
1313
},
1414
"dependencies": {
15-
"@ark-ui/react": "^0.10.0",
16-
"@fontsource/inter": "^5.0.5",
15+
"@ark-ui/react": "0.10.0",
16+
"@fontsource/inter": "5.0.5",
1717
"@monaco-editor/react": "4.5.1",
1818
"@pandacss/dev": "0.9.0",
1919
"@xstate/react": "3.2.2",
20-
"lz-string": "^1.5.0",
20+
"lz-string": "1.5.0",
2121
"monaco-editor": "0.40.0",
22-
"pastable": "^2.2.0",
23-
"react": "^18.2.0",
24-
"react-dom": "^18.2.0",
25-
"react-icons": "^4.10.1",
26-
"react-resizable-panels": "^0.0.53",
27-
"ts-patch": "^3.0.2",
22+
"pastable": "2.2.0",
23+
"prettier": "2.8.4",
24+
"react": "18.2.0",
25+
"react-dom": "18.2.0",
26+
"react-icons": "4.10.1",
27+
"react-resizable-panels": "0.0.53",
28+
"ts-patch": "3.0.2",
2829
"typed-openapi": "workspace:*",
2930
"xstate": "4.38.1",
30-
"yaml": "^2.3.1"
31+
"yaml": "2.3.1"
3132
},
3233
"devDependencies": {
33-
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
34-
"@pandacss/preset-base": "^0.7.0",
35-
"@pandacss/preset-panda": "^0.7.0",
36-
"@park-ui/presets": "^0.2.0",
37-
"@sinclair/typebox": "^0.30.4",
38-
"@types/node": "^20.4.5",
39-
"@types/react": "^18.2.15",
40-
"@types/react-dom": "^18.2.7",
41-
"@vitejs/plugin-react-swc": "^3.3.2",
34+
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
35+
"@pandacss/preset-base": "0.7.0",
36+
"@pandacss/preset-panda": "0.7.0",
37+
"@park-ui/presets": "0.2.0",
38+
"@sinclair/typebox": "0.30.4",
39+
"@types/node": "20.4.5",
40+
"@types/prettier": "2.7.3",
41+
"@types/react": "18.2.15",
42+
"@types/react-dom": "18.2.7",
43+
"@vitejs/plugin-react-swc": "3.3.2",
4244
"arktype": "1.0.18-alpha",
43-
"io-ts": "^2.2.20",
44-
"os-browserify": "^0.3.0",
45-
"path-browserify": "^1.0.1",
46-
"rollup": "^3.26.3",
47-
"rollup-plugin-dts": "^5.3.0",
48-
"tsup": "^7.1.0",
49-
"tsx": "^4.19.4",
50-
"type-fest": "^3.13.1",
51-
"typescript": "^5.1.6",
52-
"util": "^0.12.5",
53-
"valibot": "^0.37.0",
54-
"vite": "^4.4.4",
55-
"vite-plugin-react-click-to-component": "^2.0.0",
56-
"vite-tsconfig-paths": "^4.2.0",
57-
"vitest": "^0.33.0",
58-
"yup": "^1.2.0",
59-
"zod": "^3.21.4"
45+
"io-ts": "2.2.20",
46+
"os-browserify": "0.3.0",
47+
"path-browserify": "1.0.1",
48+
"rollup": "3.26.3",
49+
"rollup-plugin-dts": "5.3.0",
50+
"tsup": "7.1.0",
51+
"tsx": "4.19.4",
52+
"type-fest": "3.13.1",
53+
"typescript": "5.1.6",
54+
"util": "0.12.5",
55+
"valibot": "0.37.0",
56+
"vite": "4.4.4",
57+
"vite-plugin-react-click-to-component": "2.0.0",
58+
"vite-tsconfig-paths": "4.2.0",
59+
"vitest": "0.33.0",
60+
"yup": "1.2.0",
61+
"zod": "3.21.4"
6062
}
6163
}

0 commit comments

Comments
 (0)