forked from microsoft/typespec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenums.test.ts
37 lines (32 loc) · 1.16 KB
/
enums.test.ts
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
import { expectDiagnostics } from "@typespec/compiler/testing";
import { strictEqual } from "assert";
import { describe, it } from "vitest";
import { diagnoseOpenApiFor, oapiForModel } from "./test-host.js";
describe("openapi3: enums", () => {
it("throws diagnostics for empty enum definitions", async () => {
const diagnostics = await diagnoseOpenApiFor(`enum PetType {}`);
expectDiagnostics(diagnostics, {
code: "@typespec/openapi3/empty-enum",
message: "Empty enums are not supported for OpenAPI v3 - enums must have at least one value.",
});
});
it("throws diagnostics for enum with different types", async () => {
const diagnostics = await diagnoseOpenApiFor(`enum PetType {asString: "dog", asNumber: 1}`);
expectDiagnostics(diagnostics, {
code: "@typespec/openapi3/enum-unique-type",
message: "Enums are not supported unless all options are literals of the same type.",
});
});
it("supports summary on enums", async () => {
const res = await oapiForModel(
"Foo",
`
@summary("FooEnum")
enum Foo {
y: 0;
};
`
);
strictEqual(res.schemas.Foo.title, "FooEnum");
});
});