diff --git a/packages/create-schemas/src/plugins/openapi-typescript-plugin.ts b/packages/create-schemas/src/plugins/openapi-typescript-plugin.ts index bc93d2b..af0028c 100644 --- a/packages/create-schemas/src/plugins/openapi-typescript-plugin.ts +++ b/packages/create-schemas/src/plugins/openapi-typescript-plugin.ts @@ -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"; diff --git a/packages/create-schemas/tests/e2e.test.ts b/packages/create-schemas/tests/e2e.test.ts index a1de20f..512ff9f 100644 --- a/packages/create-schemas/tests/e2e.test.ts +++ b/packages/create-schemas/tests/e2e.test.ts @@ -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 @@ -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 + ); }); diff --git a/packages/create-schemas/tests/generate.test.ts b/packages/create-schemas/tests/generate.test.ts index 35a2b12..5a94680 100644 --- a/packages/create-schemas/tests/generate.test.ts +++ b/packages/create-schemas/tests/generate.test.ts @@ -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 }) => { @@ -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(); + }); });