|
1 | 1 | import { deepStrictEqual, strictEqual } from "assert"; |
2 | | -import { describe, it } from "vitest"; |
| 2 | +import { expect, it } from "vitest"; |
3 | 3 | import { openApiFor } from "./test-host.js"; |
4 | 4 |
|
5 | | -describe("typespec-autorest: documentation", () => { |
6 | | - it("supports summary and description", async () => { |
7 | | - const openApi = await openApiFor(` |
8 | | - @summary("This is a summary") |
9 | | - @doc("This is the longer description") |
10 | | - op read(): {}; |
11 | | - `); |
12 | | - strictEqual(openApi.paths["/"].get.summary, "This is a summary"); |
13 | | - strictEqual(openApi.paths["/"].get.description, "This is the longer description"); |
| 5 | +it("supports summary and description", async () => { |
| 6 | + const openApi = await openApiFor(` |
| 7 | + @summary("This is a summary") |
| 8 | + @doc("This is the longer description") |
| 9 | + op read(): {}; |
| 10 | + `); |
| 11 | + strictEqual(openApi.paths["/"].get.summary, "This is a summary"); |
| 12 | + strictEqual(openApi.paths["/"].get.description, "This is the longer description"); |
| 13 | +}); |
| 14 | + |
| 15 | +it("supports externalDocs on operation", async () => { |
| 16 | + const openApi = await openApiFor(` |
| 17 | + @externalDocs("https://example.com", "more info") |
| 18 | + op read(): {}; |
| 19 | + `); |
| 20 | + deepStrictEqual(openApi.paths["/"].get.externalDocs, { |
| 21 | + url: "https://example.com", |
| 22 | + description: "more info", |
14 | 23 | }); |
| 24 | +}); |
| 25 | + |
| 26 | +it("supports externalDocs on models", async () => { |
| 27 | + const openApi = await openApiFor(` |
| 28 | + @externalDocs("https://example.com", "more info") |
| 29 | + model Foo { |
| 30 | + name: string; |
| 31 | + } |
| 32 | + `); |
| 33 | + deepStrictEqual(openApi.definitions.Foo.externalDocs, { |
| 34 | + url: "https://example.com", |
| 35 | + description: "more info", |
| 36 | + }); |
| 37 | +}); |
15 | 38 |
|
16 | | - it("supports externalDocs on operation", async () => { |
17 | | - const openApi = await openApiFor(` |
| 39 | +it("supports externalDocs on properties", async () => { |
| 40 | + const openApi = await openApiFor(` |
| 41 | + model Foo { |
18 | 42 | @externalDocs("https://example.com", "more info") |
19 | | - op read(): {}; |
| 43 | + name: string; |
| 44 | + } |
20 | 45 | `); |
21 | | - deepStrictEqual(openApi.paths["/"].get.externalDocs, { |
| 46 | + expect(openApi.definitions.Foo.properties.name).toEqual({ |
| 47 | + type: "string", |
| 48 | + externalDocs: { |
22 | 49 | url: "https://example.com", |
23 | 50 | description: "more info", |
24 | | - }); |
| 51 | + }, |
25 | 52 | }); |
26 | | - |
27 | | - it("supports externalDocs on models", async () => { |
28 | | - const openApi = await openApiFor(` |
29 | | - op read(): Foo; |
30 | | - |
31 | | - @externalDocs("https://example.com", "more info") |
| 53 | +}); |
| 54 | +it("supports externalDocs on properties resulting in a $ref", async () => { |
| 55 | + const openApi = await openApiFor(` |
32 | 56 | model Foo { |
33 | | - name: string; |
| 57 | + @externalDocs("https://example.com", "more info") |
| 58 | + name: Bar; |
34 | 59 | } |
| 60 | + model Bar {} |
35 | 61 | `); |
36 | | - deepStrictEqual(openApi.definitions.Foo.externalDocs, { |
| 62 | + expect(openApi.definitions.Foo.properties.name).toEqual({ |
| 63 | + $ref: "#/definitions/Bar", |
| 64 | + externalDocs: { |
37 | 65 | url: "https://example.com", |
38 | 66 | description: "more info", |
39 | | - }); |
| 67 | + }, |
40 | 68 | }); |
41 | 69 | }); |
0 commit comments