Skip to content

Commit eb894cb

Browse files
authored
Add YAML merge test (#1285)
1 parent 5cefe35 commit eb894cb

File tree

3 files changed

+109
-2
lines changed

3 files changed

+109
-2
lines changed

packages/openapi-typescript/scripts/update-examples.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ async function generateSchemas() {
1313
...Object.keys(singleFile).map(async (name) => {
1414
const start = performance.now();
1515
const ext = path.extname(singleFile[name as keyof typeof singleFile]);
16-
await execa("node", ["./bin/cli.js", `./examples/${name}${ext}`, "-o", `./examples/${name}.ts`], { cwd });
16+
await execa("./bin/cli.js", [`./examples/${name}${ext}`, "-o", `./examples/${name}.ts`], { cwd });
1717
done++;
1818
console.log(`✔︎ [${done}/${allSchemas.length}] Updated ${name} (${Math.round(performance.now() - start)}ms)`); // eslint-disable-line no-console
1919
}),
2020
...Object.entries(multiFile).map(async ([name, meta]) => {
2121
const start = performance.now();
22-
await execa("node", ["./bin/cli.js", `./examples/${name}${meta.entry.substring(1)}`, "-o", `./examples/${name}.ts`], { cwd });
22+
await execa("./bin/cli.js", [`./examples/${name}${meta.entry.substring(1)}`, "-o", `./examples/${name}.ts`], { cwd });
2323
done++;
2424
console.log(`✔︎ [${done}/${allSchemas.length}] Updated ${name} (${Math.round(performance.now() - start)}ms)`); // eslint-disable-line no-console
2525
}),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
openapi: "3.1.0"
2+
info:
3+
title: Test
4+
version: "1.0.0"
5+
x-error-response: &x-error-response
6+
4XX:
7+
description: Error response
8+
content:
9+
application/json:
10+
schema:
11+
$ref: '#/components/schemas/HTTPError'
12+
paths:
13+
/admin/ping:
14+
get:
15+
summary: Ping pongs
16+
operationId: AdminPing
17+
responses:
18+
"200":
19+
description: OK
20+
content:
21+
text/plain:
22+
schema:
23+
type: string
24+
example: pong
25+
!!merge <<: *x-error-response
26+
tags:
27+
- admin
28+
components:
29+
schemas:
30+
HTTPError:
31+
description: represents an error message response.
32+
type: object
33+
properties:
34+
title:
35+
type: string
36+
detail:
37+
type: string
38+
status:
39+
type: integer
40+
error:
41+
type: string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { execa } from "execa";
2+
3+
const CMD = "./bin/cli.js";
4+
const cwd = new URL("../", import.meta.url);
5+
6+
describe("YAML features", () => {
7+
it("merge", async () => {
8+
const result = await execa(CMD, ["./test/fixtures/yaml-merge.yaml"], { cwd });
9+
expect(result.stdout).toMatchInlineSnapshot(`
10+
"/**
11+
* This file was auto-generated by openapi-typescript.
12+
* Do not make direct changes to the file.
13+
*/
14+
15+
16+
export interface paths {
17+
\\"/admin/ping\\": {
18+
/** Ping pongs */
19+
get: operations[\\"AdminPing\\"];
20+
};
21+
}
22+
23+
export type webhooks = Record<string, never>;
24+
25+
export interface components {
26+
schemas: {
27+
/** @description represents an error message response. */
28+
HTTPError: {
29+
title?: string;
30+
detail?: string;
31+
status?: number;
32+
error?: string;
33+
};
34+
};
35+
responses: never;
36+
parameters: never;
37+
requestBodies: never;
38+
headers: never;
39+
pathItems: never;
40+
}
41+
42+
export type external = Record<string, never>;
43+
44+
export interface operations {
45+
46+
/** Ping pongs */
47+
AdminPing: {
48+
responses: {
49+
/** @description OK */
50+
200: {
51+
content: {
52+
\\"text/plain\\": string;
53+
};
54+
};
55+
/** @description Error response */
56+
\\"4XX\\": {
57+
content: {
58+
\\"application/json\\": components[\\"schemas\\"][\\"HTTPError\\"];
59+
};
60+
};
61+
};
62+
};
63+
}"
64+
`);
65+
});
66+
});

0 commit comments

Comments
 (0)