diff --git a/packages/openapi-typescript/scripts/update-examples.ts b/packages/openapi-typescript/scripts/update-examples.ts index 3f508c61f..22afe7b4a 100644 --- a/packages/openapi-typescript/scripts/update-examples.ts +++ b/packages/openapi-typescript/scripts/update-examples.ts @@ -13,13 +13,13 @@ async function generateSchemas() { ...Object.keys(singleFile).map(async (name) => { const start = performance.now(); const ext = path.extname(singleFile[name as keyof typeof singleFile]); - await execa("node", ["./bin/cli.js", `./examples/${name}${ext}`, "-o", `./examples/${name}.ts`], { cwd }); + await execa("./bin/cli.js", [`./examples/${name}${ext}`, "-o", `./examples/${name}.ts`], { cwd }); done++; console.log(`✔︎ [${done}/${allSchemas.length}] Updated ${name} (${Math.round(performance.now() - start)}ms)`); // eslint-disable-line no-console }), ...Object.entries(multiFile).map(async ([name, meta]) => { const start = performance.now(); - await execa("node", ["./bin/cli.js", `./examples/${name}${meta.entry.substring(1)}`, "-o", `./examples/${name}.ts`], { cwd }); + await execa("./bin/cli.js", [`./examples/${name}${meta.entry.substring(1)}`, "-o", `./examples/${name}.ts`], { cwd }); done++; console.log(`✔︎ [${done}/${allSchemas.length}] Updated ${name} (${Math.round(performance.now() - start)}ms)`); // eslint-disable-line no-console }), diff --git a/packages/openapi-typescript/test/fixtures/yaml-merge.yaml b/packages/openapi-typescript/test/fixtures/yaml-merge.yaml new file mode 100644 index 000000000..84e732447 --- /dev/null +++ b/packages/openapi-typescript/test/fixtures/yaml-merge.yaml @@ -0,0 +1,41 @@ +openapi: "3.1.0" +info: + title: Test + version: "1.0.0" +x-error-response: &x-error-response + 4XX: + description: Error response + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPError' +paths: + /admin/ping: + get: + summary: Ping pongs + operationId: AdminPing + responses: + "200": + description: OK + content: + text/plain: + schema: + type: string + example: pong + !!merge <<: *x-error-response + tags: + - admin +components: + schemas: + HTTPError: + description: represents an error message response. + type: object + properties: + title: + type: string + detail: + type: string + status: + type: integer + error: + type: string diff --git a/packages/openapi-typescript/test/yaml.test.ts b/packages/openapi-typescript/test/yaml.test.ts new file mode 100644 index 000000000..61823cfa9 --- /dev/null +++ b/packages/openapi-typescript/test/yaml.test.ts @@ -0,0 +1,66 @@ +import { execa } from "execa"; + +const CMD = "./bin/cli.js"; +const cwd = new URL("../", import.meta.url); + +describe("YAML features", () => { + it("merge", async () => { + const result = await execa(CMD, ["./test/fixtures/yaml-merge.yaml"], { cwd }); + expect(result.stdout).toMatchInlineSnapshot(` + "/** + * This file was auto-generated by openapi-typescript. + * Do not make direct changes to the file. + */ + + + export interface paths { + \\"/admin/ping\\": { + /** Ping pongs */ + get: operations[\\"AdminPing\\"]; + }; + } + + export type webhooks = Record; + + export interface components { + schemas: { + /** @description represents an error message response. */ + HTTPError: { + title?: string; + detail?: string; + status?: number; + error?: string; + }; + }; + responses: never; + parameters: never; + requestBodies: never; + headers: never; + pathItems: never; + } + + export type external = Record; + + export interface operations { + + /** Ping pongs */ + AdminPing: { + responses: { + /** @description OK */ + 200: { + content: { + \\"text/plain\\": string; + }; + }; + /** @description Error response */ + \\"4XX\\": { + content: { + \\"application/json\\": components[\\"schemas\\"][\\"HTTPError\\"]; + }; + }; + }; + }; + }" + `); + }); +});