Skip to content

Commit af53b40

Browse files
committed
[IDP-1904] Fix client generation
1 parent dde9873 commit af53b40

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

packages/create-schemas/src/plugins/openapi-typescript-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import openapiTS, { astToString } from "openapi-typescript";
22
import type { Plugin } from "./plugin.ts";
33

4-
export const openapiTypeScriptId = Symbol();
4+
export const openapiTypeScriptId = "internal:openapi-typescript-plugin";
55

66
export const openapiTypeScriptFilename = "types.ts";
77

packages/create-schemas/tests/e2e.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { assert, describe, test } from "vitest";
77
import { join } from "node:path";
88
import { pathToFileURL } from "node:url";
99
import { openapiTypeScriptFilename } from "../src/plugins/openapi-typescript-plugin.ts";
10+
import { writeFile } from "node:fs/promises";
1011

1112
const timeout = 30 * 1000; // 30 seconds
1213

@@ -96,4 +97,31 @@ describe.concurrent("e2e", () => {
9697
},
9798
timeout
9899
);
100+
101+
test(
102+
"petstore.json / generate openapi-fetch client",
103+
async ({ expect, onTestFinished }) => {
104+
const tempFolder = await createTemporaryFolder({ onTestFinished: onTestFinished });
105+
106+
const configFile = `
107+
import { openapiFetchPlugin } from "../../../src/plugins";
108+
109+
export default { plugins: [openapiFetchPlugin()] };
110+
`;
111+
112+
await writeFile(join(tempFolder, "create-schemas.config.ts"), configFile);
113+
114+
const result = await runCompiledBin({
115+
source: join(dataFolder, "petstore.json"),
116+
outdir: join(tempFolder, "dist"),
117+
cwd: tempFolder
118+
});
119+
120+
console.log(result);
121+
122+
const clientFile = result.find(file => file.filename === "client.ts");
123+
expect(clientFile).toBeDefined();
124+
},
125+
timeout
126+
);
99127
});

packages/create-schemas/tests/generate.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { resolveConfig } from "../src/config.ts";
44
import { join } from "path";
55
import { dataFolder } from "./fixtures.ts";
66
import { openapiTypeScriptFilename } from "../src/plugins/openapi-typescript-plugin.ts";
7+
import { openapiFetchPlugin } from "../src/plugins/openapi-fetch-plugin.ts";
78

89
describe.concurrent("generate", () => {
910
test("sanitize names", async ({ expect }) => {
@@ -41,4 +42,14 @@ describe.concurrent("generate", () => {
4142

4243
expect(fn).rejects.toThrow();
4344
});
45+
46+
test("generate client", async ({ expect }) => {
47+
const { files } = await generate(await resolveConfig({
48+
input: join(dataFolder, "todo.json"),
49+
plugins: [openapiFetchPlugin()]
50+
}));
51+
52+
const clientFile = files.find(file => file.filename === "client.ts");
53+
expect(clientFile).toBeDefined();
54+
});
4455
});

0 commit comments

Comments
 (0)