Skip to content

Commit

Permalink
[IDP-1904] Fix client generation
Browse files Browse the repository at this point in the history
  • Loading branch information
tjosepo committed Jul 18, 2024
1 parent dde9873 commit af53b40
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import openapiTS, { astToString } from "openapi-typescript";
import type { Plugin } from "./plugin.ts";

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

export const openapiTypeScriptFilename = "types.ts";

Expand Down
28 changes: 28 additions & 0 deletions packages/create-schemas/tests/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { assert, describe, test } from "vitest";
import { join } from "node:path";
import { pathToFileURL } from "node:url";
import { openapiTypeScriptFilename } from "../src/plugins/openapi-typescript-plugin.ts";
import { writeFile } from "node:fs/promises";

const timeout = 30 * 1000; // 30 seconds

Expand Down Expand Up @@ -96,4 +97,31 @@ describe.concurrent("e2e", () => {
},
timeout
);

test(
"petstore.json / generate openapi-fetch client",
async ({ expect, onTestFinished }) => {
const tempFolder = await createTemporaryFolder({ onTestFinished: onTestFinished });

const configFile = `
import { openapiFetchPlugin } from "../../../src/plugins";
export default { plugins: [openapiFetchPlugin()] };
`;

await writeFile(join(tempFolder, "create-schemas.config.ts"), configFile);

const result = await runCompiledBin({
source: join(dataFolder, "petstore.json"),
outdir: join(tempFolder, "dist"),
cwd: tempFolder
});

console.log(result);

const clientFile = result.find(file => file.filename === "client.ts");
expect(clientFile).toBeDefined();
},
timeout
);
});
11 changes: 11 additions & 0 deletions packages/create-schemas/tests/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { resolveConfig } from "../src/config.ts";
import { join } from "path";
import { dataFolder } from "./fixtures.ts";
import { openapiTypeScriptFilename } from "../src/plugins/openapi-typescript-plugin.ts";
import { openapiFetchPlugin } from "../src/plugins/openapi-fetch-plugin.ts";

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

expect(fn).rejects.toThrow();
});

test("generate client", async ({ expect }) => {
const { files } = await generate(await resolveConfig({
input: join(dataFolder, "todo.json"),
plugins: [openapiFetchPlugin()]
}));

const clientFile = files.find(file => file.filename === "client.ts");
expect(clientFile).toBeDefined();
});
});

0 comments on commit af53b40

Please sign in to comment.