forked from microsoft/typespec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse-descriptions.test.ts
64 lines (60 loc) · 2.46 KB
/
response-descriptions.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { strictEqual } from "assert";
import { describe, it } from "vitest";
import { openApiFor } from "./test-host.js";
describe("openapi3: response descriptions", () => {
it("use a default message by status code if not specified", async () => {
const res = await openApiFor(
`
op read(): {@statusCode _: 200, content: string};
`
);
strictEqual(res.paths["/"].get.responses["200"].description, "The request has succeeded.");
});
it("@returns set doc for all success responses", async () => {
const res = await openApiFor(
`
@error model Error {}
@returnsDoc("A string")
op read(): { @statusCode _: 200, content: string } | { @statusCode _: 201, content: string } | Error;
`
);
strictEqual(res.paths["/"].get.responses["200"].description, "A string");
strictEqual(res.paths["/"].get.responses["201"].description, "A string");
strictEqual(
res.paths["/"].get.responses["default"].description,
"An unexpected error response."
);
});
it("@errors set doc for all success responses", async () => {
const res = await openApiFor(
`
@error model Error {}
@errorsDoc("Generic error")
op read(): { @statusCode _: 200, content: string } | { @statusCode _: 201, content: string } | Error;
`
);
strictEqual(res.paths["/"].get.responses["200"].description, "The request has succeeded.");
strictEqual(
res.paths["/"].get.responses["201"].description,
"The request has succeeded and a new resource has been created as a result."
);
strictEqual(res.paths["/"].get.responses["default"].description, "Generic error");
});
it("@doc explicitly on a response override the operation returns doc", async () => {
const res = await openApiFor(
`
@error model Error {}
@error @doc("Not found model") model NotFound {@statusCode _: 404}
@errorsDoc("Generic error")
op read(): { @statusCode _: 200, content: string } | { @statusCode _: 201, content: string } | Error | NotFound;
`
);
strictEqual(res.paths["/"].get.responses["200"].description, "The request has succeeded.");
strictEqual(
res.paths["/"].get.responses["201"].description,
"The request has succeeded and a new resource has been created as a result."
);
strictEqual(res.paths["/"].get.responses["404"].description, "Not found model");
strictEqual(res.paths["/"].get.responses["default"].description, "Generic error");
});
});