Skip to content

Commit

Permalink
Add YAML merge test (#1285)
Browse files Browse the repository at this point in the history
  • Loading branch information
drwpow authored Aug 9, 2023
1 parent 5cefe35 commit eb894cb
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/openapi-typescript/scripts/update-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}),
Expand Down
41 changes: 41 additions & 0 deletions packages/openapi-typescript/test/fixtures/yaml-merge.yaml
Original file line number Diff line number Diff line change
@@ -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
66 changes: 66 additions & 0 deletions packages/openapi-typescript/test/yaml.test.ts
Original file line number Diff line number Diff line change
@@ -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<string, never>;
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<string, never>;
export interface operations {
/** Ping pongs */
AdminPing: {
responses: {
/** @description OK */
200: {
content: {
\\"text/plain\\": string;
};
};
/** @description Error response */
\\"4XX\\": {
content: {
\\"application/json\\": components[\\"schemas\\"][\\"HTTPError\\"];
};
};
};
};
}"
`);
});
});

0 comments on commit eb894cb

Please sign in to comment.