forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypescript-codegen.test.ts
More file actions
46 lines (42 loc) · 1.68 KB
/
Copy pathtypescript-codegen.test.ts
File metadata and controls
46 lines (42 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import type { JSONSchema7 } from "json-schema";
import { compile } from "json-schema-to-typescript";
import { describe, expect, it } from "vitest";
import { normalizeSchemaForTypeScript } from "../../scripts/codegen/typescript.ts";
describe("typescript schema codegen", () => {
it("emits JSDoc comments for described enum values", async () => {
const schema: JSONSchema7 = {
title: "SyntheticOptions",
type: "object",
additionalProperties: false,
properties: {
namedMode: {
title: "SyntheticMode",
type: "string",
enum: ["alpha", "beta"],
description: "Synthetic mode.",
"x-enumDescriptions": {
alpha: "Use alpha mode.",
},
},
inlineMode: {
type: "string",
enum: ["direct", "indirect"],
description: "Inline mode.",
"x-enumDescriptions": {
direct: "Use a direct value.",
},
},
},
required: ["namedMode", "inlineMode"],
};
const code = await compile(normalizeSchemaForTypeScript(schema), "SyntheticOptions", {
bannerComment: "",
style: { semi: true, singleQuote: false },
additionalProperties: false,
});
expect(code).toContain(
'export type SyntheticMode = /** Use alpha mode. */ "alpha" | "beta";'
);
expect(code).toContain('inlineMode: /** Use a direct value. */ "direct" | "indirect";');
});
});