microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
bd60b0a68bb23817a01ab4aef22170c18abd81ed

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

packages/openapi3/test/array.test.ts

79lines · modecode

1import { deepStrictEqual, ok } from "assert";
2import { oapiForModel } from "./test-host.js";
3
4describe("openapi3: Array", () => {
5 it("defines array inline", async () => {
6 const res = await oapiForModel(
7 "Pet",
8 `
9 model Pet { names: string[] };
10 `
11 );
12
13 ok(res.isRef);
14 ok(res.schemas.Pet, "expected definition named Pet");
15 deepStrictEqual(res.schemas.Pet.properties.names, {
16 type: "array",
17 items: { type: "string" },
18 "x-cadl-name": "string[]",
19 });
20 });
21
22 it("define a named array using model is", async () => {
23 const res = await oapiForModel(
24 "Pet",
25 `
26 model PetNames is string[] {}
27 model Pet { names: PetNames };
28 `
29 );
30
31 ok(res.isRef);
32 ok(res.schemas.PetNames, "expected definition named myArray");
33 ok(res.schemas.Pet, "expected definition named Pet");
34 deepStrictEqual(res.schemas.PetNames, {
35 type: "array",
36 items: { type: "string" },
37 });
38 });
39
40 it("can specify minItems using @minItems decorator", async () => {
41 const res = await oapiForModel(
42 "Pet",
43 `
44 model Pet {
45 @minItems(1)
46 names: string[]
47 };
48 `
49 );
50
51 ok(res.schemas.Pet, "expected definition named Pet");
52 deepStrictEqual(res.schemas.Pet.properties.names, {
53 type: "array",
54 minItems: 1,
55 items: { type: "string" },
56 "x-cadl-name": "string[]",
57 });
58 });
59
60 it("can specify maxItems using @maxItems decorator", async () => {
61 const res = await oapiForModel(
62 "Pet",
63 `
64 model Pet {
65 @maxItems(3)
66 names: string[]
67 };
68 `
69 );
70
71 ok(res.schemas.Pet, "expected definition named Pet");
72 deepStrictEqual(res.schemas.Pet.properties.names, {
73 type: "array",
74 maxItems: 3,
75 items: { type: "string" },
76 "x-cadl-name": "string[]",
77 });
78 });
79});
80