@typespec/http-specs 0.1.0-alpha.10-dev.1 → 0.1.0-alpha.10-dev.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"mockapi.d.ts","sourceRoot":"","sources":["../../../../specs/payload/pageable/mockapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEvF,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAM,CAAC"}
1
+ {"version":3,"file":"mockapi.d.ts","sourceRoot":"","sources":["../../../../specs/payload/pageable/mockapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,eAAe,EAEhB,MAAM,oBAAoB,CAAC;AAE5B,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAM,CAAC"}
@@ -1,5 +1,73 @@
1
- import { json, passOnSuccess } from "@typespec/spec-api";
1
+ import { json, passOnSuccess, ValidationError, } from "@typespec/spec-api";
2
2
  export const Scenarios = {};
3
+ const FirstPage = [
4
+ { id: "1", name: "dog" },
5
+ { id: "2", name: "cat" },
6
+ ];
7
+ const SecondPage = [
8
+ { id: "3", name: "bird" },
9
+ { id: "4", name: "fish" },
10
+ ];
11
+ const FirstResponseTokenInBody = {
12
+ status: 200,
13
+ body: json({
14
+ pets: FirstPage,
15
+ nextToken: "page2",
16
+ }),
17
+ };
18
+ const SecondResponse = {
19
+ status: 200,
20
+ body: json({
21
+ pets: SecondPage,
22
+ }),
23
+ };
24
+ const FirstResponseTokenInHeader = {
25
+ status: 200,
26
+ body: json({
27
+ pets: FirstPage,
28
+ }),
29
+ headers: {
30
+ "next-token": "page2",
31
+ },
32
+ };
33
+ const RequestTokenInQuery = {
34
+ params: { token: "page2" },
35
+ };
36
+ const RequestTokenInHeader = { headers: { token: "page2" } };
37
+ function createTests(reqInfo, resInfo) {
38
+ const uri = `/payload/pageable/server-driven-pagination/continuationtoken/request-${reqInfo}-response-${resInfo}`;
39
+ function createHandler() {
40
+ return (req) => {
41
+ const token = reqInfo === "header" ? req.headers?.token : req.query?.token;
42
+ switch (token) {
43
+ case undefined:
44
+ return resInfo === "header" ? FirstResponseTokenInHeader : FirstResponseTokenInBody;
45
+ case "page2":
46
+ return SecondResponse;
47
+ default:
48
+ throw new ValidationError("Unsupported continuation token", `"undefined" | "page2"`, token);
49
+ }
50
+ };
51
+ }
52
+ return passOnSuccess([
53
+ {
54
+ uri: uri,
55
+ method: "get",
56
+ request: {},
57
+ response: resInfo === "header" ? FirstResponseTokenInHeader : FirstResponseTokenInBody,
58
+ handler: createHandler(),
59
+ kind: "MockApiDefinition",
60
+ },
61
+ {
62
+ uri: uri,
63
+ method: "get",
64
+ request: reqInfo === "header" ? RequestTokenInHeader : RequestTokenInQuery,
65
+ response: SecondResponse,
66
+ handler: createHandler(),
67
+ kind: "MockApiDefinition",
68
+ },
69
+ ]);
70
+ }
3
71
  Scenarios.Payload_Pageable_ServerDrivenPagination_link = passOnSuccess([
4
72
  {
5
73
  uri: "/payload/pageable/server-driven-pagination/link",
@@ -8,10 +76,7 @@ Scenarios.Payload_Pageable_ServerDrivenPagination_link = passOnSuccess([
8
76
  response: {
9
77
  status: 200,
10
78
  body: json({
11
- pets: [
12
- { id: "1", name: "dog" },
13
- { id: "2", name: "cat" },
14
- ],
79
+ pets: FirstPage,
15
80
  next: "/payload/pageable/server-driven-pagination/link/nextPage",
16
81
  }),
17
82
  },
@@ -19,10 +84,7 @@ Scenarios.Payload_Pageable_ServerDrivenPagination_link = passOnSuccess([
19
84
  return {
20
85
  status: 200,
21
86
  body: json({
22
- pets: [
23
- { id: "1", name: "dog" },
24
- { id: "2", name: "cat" },
25
- ],
87
+ pets: FirstPage,
26
88
  next: `${req.baseUrl}/payload/pageable/server-driven-pagination/link/nextPage`,
27
89
  }),
28
90
  };
@@ -33,16 +95,16 @@ Scenarios.Payload_Pageable_ServerDrivenPagination_link = passOnSuccess([
33
95
  uri: "/payload/pageable/server-driven-pagination/link/nextPage",
34
96
  method: "get",
35
97
  request: {},
36
- response: {
37
- status: 200,
38
- body: json({
39
- pets: [
40
- { id: "3", name: "bird" },
41
- { id: "4", name: "fish" },
42
- ],
43
- }),
44
- },
98
+ response: SecondResponse,
45
99
  kind: "MockApiDefinition",
46
100
  },
47
101
  ]);
102
+ Scenarios.Payload_Pageable_ServerDrivenPagination_ContinuationToken_requestQueryResponseBody =
103
+ createTests("query", "body");
104
+ Scenarios.Payload_Pageable_ServerDrivenPagination_ContinuationToken_requestHeaderResponseBody =
105
+ createTests("header", "body");
106
+ Scenarios.Payload_Pageable_ServerDrivenPagination_ContinuationToken_requestQueryResponseHeader =
107
+ createTests("query", "header");
108
+ Scenarios.Payload_Pageable_ServerDrivenPagination_ContinuationToken_requestHeaderResponseHeader =
109
+ createTests("header", "header");
48
110
  //# sourceMappingURL=mockapi.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mockapi.js","sourceRoot":"","sources":["../../../../specs/payload/pageable/mockapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAe,aAAa,EAAmB,MAAM,oBAAoB,CAAC;AAEvF,MAAM,CAAC,MAAM,SAAS,GAAoC,EAAE,CAAC;AAE7D,SAAS,CAAC,4CAA4C,GAAG,aAAa,CAAC;IACrE;QACE,GAAG,EAAE,iDAAiD;QACtD,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,EAAE;QACX,QAAQ,EAAE;YACR,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,IAAI,CAAC;gBACT,IAAI,EAAE;oBACJ,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE;oBACxB,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE;iBACzB;gBACD,IAAI,EAAE,0DAA0D;aACjE,CAAC;SACH;QACD,OAAO,EAAE,CAAC,GAAgB,EAAE,EAAE;YAC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AAC,CAAC;AAE/B,SAAS,CAAC,mFAAmF;IAC3F,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAEhC,SAAS,CAAC,oFAAoF;IAC5F,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACjC,SAAS,CAAC,qFAAqF;IAC7F,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/http-specs",
3
- "version": "0.1.0-alpha.10-dev.1",
3
+ "version": "0.1.0-alpha.10-dev.3",
4
4
  "description": "Spec scenarios and mock apis",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -42,6 +42,7 @@
42
42
  "build": "tsc -p ./tsconfig.build.json",
43
43
  "clean": "rimraf dist/ temp/",
44
44
  "test:e2e": "pnpm validate-scenarios && pnpm validate-mock-apis && pnpm validate-client-server",
45
+ "validate:all": "pnpm build && pnpm regen-docs && pnpm test:e2e",
45
46
  "validate-scenarios": "tsp-spector validate-scenarios ./specs",
46
47
  "generate-scenarios-summary": "tsp-spector generate-scenarios-summary ./specs",
47
48
  "regen-docs": "pnpm generate-scenarios-summary",
package/spec-summary.md CHANGED
@@ -1661,6 +1661,160 @@ Content-Type: application/octet-stream
1661
1661
  --abcde12345--
1662
1662
  ```
1663
1663
 
1664
+ ### Payload_Pageable_ServerDrivenPagination_ContinuationToken_requestHeaderResponseBody
1665
+
1666
+ - Endpoint: `get /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body`
1667
+
1668
+ Test case for using continuation token as pagination. Continuation token is passed in the request header and response body.
1669
+
1670
+ Two requests need to be tested.
1671
+
1672
+ 1. Initial request:
1673
+ Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body
1674
+
1675
+ Expected response body:
1676
+
1677
+ ```json
1678
+ {
1679
+ "pets": [
1680
+ { "id": "1", "name": "dog" },
1681
+ { "id": "2", "name": "cat" }
1682
+ ],
1683
+ "nextToken": "page2"
1684
+ }
1685
+ ```
1686
+
1687
+ 2. Next page request:
1688
+ Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body
1689
+
1690
+ Expected header:
1691
+ token=page2
1692
+
1693
+ Expected response body:
1694
+
1695
+ ```json
1696
+ {
1697
+ "pets": [
1698
+ { "id": "3", "name": "bird" },
1699
+ { "id": "4", "name": "fish" }
1700
+ ]
1701
+ }
1702
+ ```
1703
+
1704
+ ### Payload_Pageable_ServerDrivenPagination_ContinuationToken_requestHeaderResponseHeader
1705
+
1706
+ - Endpoint: `get /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header`
1707
+
1708
+ Test case for using continuation token as pagination. Continuation token is passed in the request header and response header.
1709
+
1710
+ Two requests need to be tested.
1711
+
1712
+ 1. Initial request:
1713
+ Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header
1714
+ Expected response body:
1715
+
1716
+ ```json
1717
+ {
1718
+ "pets": [
1719
+ { "id": "1", "name": "dog" },
1720
+ { "id": "2", "name": "cat" }
1721
+ ]
1722
+ }
1723
+ ```
1724
+
1725
+ Expected response header:
1726
+ next-token=page2
1727
+
1728
+ 2. Next page request:
1729
+ Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header
1730
+
1731
+ Expected request header:
1732
+ token=page2
1733
+
1734
+ Expected response body:
1735
+
1736
+ ```json
1737
+ {
1738
+ "pets": [
1739
+ { "id": "3", "name": "bird" },
1740
+ { "id": "4", "name": "fish" }
1741
+ ]
1742
+ }
1743
+ ```
1744
+
1745
+ ### Payload_Pageable_ServerDrivenPagination_ContinuationToken_requestQueryResponseBody
1746
+
1747
+ - Endpoint: `get /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body`
1748
+
1749
+ Test case for using continuation token as pagination. Continuation token is passed in the request query and response body.
1750
+
1751
+ Two requests need to be tested.
1752
+
1753
+ 1. Initial request:
1754
+ Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body
1755
+ Expected response body:
1756
+
1757
+ ```json
1758
+ {
1759
+ "pets": [
1760
+ { "id": "1", "name": "dog" },
1761
+ { "id": "2", "name": "cat" }
1762
+ ],
1763
+ "nextToken": "page2"
1764
+ }
1765
+ ```
1766
+
1767
+ 2. Next page request:
1768
+ Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body?token=page2
1769
+
1770
+ Expected response body:
1771
+
1772
+ ```json
1773
+ {
1774
+ "pets": [
1775
+ { "id": "3", "name": "bird" },
1776
+ { "id": "4", "name": "fish" }
1777
+ ]
1778
+ }
1779
+ ```
1780
+
1781
+ ### Payload_Pageable_ServerDrivenPagination_ContinuationToken_requestQueryResponseHeader
1782
+
1783
+ - Endpoint: `get /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header`
1784
+
1785
+ Test case for using continuation token as pagination. Continuation token is passed in the request query and response header.
1786
+
1787
+ Two requests need to be tested.
1788
+
1789
+ 1. Initial request:
1790
+ Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header
1791
+ Expected response body:
1792
+
1793
+ ```json
1794
+ {
1795
+ "pets": [
1796
+ { "id": "1", "name": "dog" },
1797
+ { "id": "2", "name": "cat" }
1798
+ ]
1799
+ }
1800
+ ```
1801
+
1802
+ Expected response header:
1803
+ next-token=page2
1804
+
1805
+ 2. Next page request:
1806
+ Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header?token=page2
1807
+ Expected response body:
1808
+
1809
+ ```json
1810
+ {
1811
+ "pets": [
1812
+ { "id": "3", "name": "bird" },
1813
+ { "id": "4", "name": "fish" }
1814
+ ]
1815
+ }
1816
+ ```
1817
+
1664
1818
  ### Payload_Pageable_ServerDrivenPagination_link
1665
1819
 
1666
1820
  - Endpoint: `get /payload/pageable/server-driven-pagination/link`
@@ -2200,7 +2354,7 @@ Expected path: /routes/path/label/standard/record.a,1,b,2
2200
2354
 
2201
2355
  Test matrix expansion with explode: true when passed an array value.
2202
2356
  Param value: ["a","b"]
2203
- Expected path: /routes/path/matrix/explode/array;a.b
2357
+ Expected path: /routes/path/matrix/explode/array;param=a;param=b
2204
2358
 
2205
2359
  ### Routes_PathParameters_MatrixExpansion_Explode_primitive
2206
2360
 
@@ -2208,7 +2362,7 @@ Expected path: /routes/path/matrix/explode/array;a.b
2208
2362
 
2209
2363
  Test matrix expansion with explode: true when passed a primitive value.
2210
2364
  Param value: "a"
2211
- Expected path: /routes/path/matrix/explode/primitive;a
2365
+ Expected path: /routes/path/matrix/explode/primitive;param=a
2212
2366
 
2213
2367
  ### Routes_PathParameters_MatrixExpansion_Explode_record
2214
2368
 
@@ -2224,7 +2378,7 @@ Expected path: /routes/path/matrix/explode/record;a=1;b=2
2224
2378
 
2225
2379
  Test matrix expansion with explode: false when passed an array value.
2226
2380
  Param value: ["a","b"]
2227
- Expected path: /routes/path/matrix/standard/array;a,b
2381
+ Expected path: /routes/path/matrix/standard/array;param=a;param=b
2228
2382
 
2229
2383
  ### Routes_PathParameters_MatrixExpansion_Standard_primitive
2230
2384
 
@@ -2232,7 +2386,7 @@ Expected path: /routes/path/matrix/standard/array;a,b
2232
2386
 
2233
2387
  Test matrix expansion with explode: false when passed a primitive value.
2234
2388
  Param value: "a"
2235
- Expected path: /routes/path/matrix/standard/primitive;a
2389
+ Expected path: /routes/path/matrix/standard/primitive;param=a
2236
2390
 
2237
2391
  ### Routes_PathParameters_MatrixExpansion_Standard_record
2238
2392
 
@@ -2240,7 +2394,7 @@ Expected path: /routes/path/matrix/standard/primitive;a
2240
2394
 
2241
2395
  Test matrix expansion with explode: false when passed a record value.
2242
2396
  Param value: {a: 1, b: 2}
2243
- Expected path: /routes/path/matrix/standard/record;a,1,b,2
2397
+ Expected path: /routes/path/matrix/standard/record;a=1;b=2
2244
2398
 
2245
2399
  ### Routes_PathParameters_PathExpansion_Explode_array
2246
2400
 
@@ -52,4 +52,168 @@ namespace ServerDrivenPagination {
52
52
 
53
53
  @nextLink next?: url;
54
54
  };
55
+
56
+ @route("/continuationtoken")
57
+ namespace ContinuationToken {
58
+ @scenario
59
+ @scenarioDoc("""
60
+ Test case for using continuation token as pagination. Continuation token is passed in the request query and response body.
61
+
62
+ Two requests need to be tested.
63
+ 1. Initial request:
64
+ Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body
65
+ Expected response body:
66
+ ```json
67
+ { "pets": [
68
+ { "id": "1", "name": "dog" },
69
+ { "id": "2", "name": "cat" }
70
+ ],
71
+ "nextToken": "page2"
72
+ }
73
+ ```
74
+
75
+ 2. Next page request:
76
+ Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body?token=page2
77
+
78
+ Expected response body:
79
+ ```json
80
+ { "pets": [
81
+ { "id": "3", "name": "bird" },
82
+ { "id": "4", "name": "fish" }
83
+ ]
84
+ }
85
+ ```
86
+ """)
87
+ @route("/request-query-response-body")
88
+ @list
89
+ op requestQueryResponseBody(@continuationToken @query token?: string): {
90
+ @pageItems
91
+ pets: Pet[];
92
+
93
+ @continuationToken nextToken?: string;
94
+ };
95
+
96
+ @scenario
97
+ @scenarioDoc("""
98
+ Test case for using continuation token as pagination. Continuation token is passed in the request header and response body.
99
+
100
+ Two requests need to be tested.
101
+ 1. Initial request:
102
+ Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body
103
+
104
+ Expected response body:
105
+ ```json
106
+ { "pets": [
107
+ { "id": "1", "name": "dog" },
108
+ { "id": "2", "name": "cat" }
109
+ ],
110
+ "nextToken": "page2"
111
+ }
112
+ ```
113
+ 2. Next page request:
114
+ Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body
115
+
116
+ Expected header:
117
+ token=page2
118
+
119
+ Expected response body:
120
+ ```json
121
+ { "pets": [
122
+ { "id": "3", "name": "bird" },
123
+ { "id": "4", "name": "fish" }
124
+ ]
125
+ }
126
+ ```
127
+ """)
128
+ @route("/request-header-response-body")
129
+ @list
130
+ op requestHeaderResponseBody(@continuationToken @header token?: string): {
131
+ @pageItems
132
+ pets: Pet[];
133
+
134
+ @continuationToken nextToken?: string;
135
+ };
136
+
137
+ @scenario
138
+ @scenarioDoc("""
139
+ Test case for using continuation token as pagination. Continuation token is passed in the request query and response header.
140
+
141
+ Two requests need to be tested.
142
+ 1. Initial request:
143
+ Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header
144
+ Expected response body:
145
+ ```json
146
+ { "pets": [
147
+ { "id": "1", "name": "dog" },
148
+ { "id": "2", "name": "cat" }
149
+ ]
150
+ }
151
+ ```
152
+
153
+ Expected response header:
154
+ next-token=page2
155
+
156
+ 2. Next page request:
157
+ Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header?token=page2
158
+ Expected response body:
159
+ ```json
160
+ { "pets": [
161
+ { "id": "3", "name": "bird" },
162
+ { "id": "4", "name": "fish" }
163
+ ]
164
+ }
165
+ ```
166
+ """)
167
+ @route("/request-query-response-header")
168
+ @list
169
+ op requestQueryResponseHeader(@continuationToken @query token?: string): {
170
+ @pageItems
171
+ pets: Pet[];
172
+
173
+ @continuationToken @header nextToken?: string;
174
+ };
175
+
176
+ @scenario
177
+ @scenarioDoc("""
178
+ Test case for using continuation token as pagination. Continuation token is passed in the request header and response header.
179
+
180
+ Two requests need to be tested.
181
+ 1. Initial request:
182
+ Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header
183
+ Expected response body:
184
+ ```json
185
+ { "pets": [
186
+ { "id": "1", "name": "dog" },
187
+ { "id": "2", "name": "cat" }
188
+ ]
189
+ }
190
+ ```
191
+
192
+ Expected response header:
193
+ next-token=page2
194
+
195
+ 2. Next page request:
196
+ Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header
197
+
198
+ Expected request header:
199
+ token=page2
200
+
201
+ Expected response body:
202
+ ```json
203
+ { "pets": [
204
+ { "id": "3", "name": "bird" },
205
+ { "id": "4", "name": "fish" }
206
+ ]
207
+ }
208
+ ```
209
+ """)
210
+ @route("/request-header-response-header")
211
+ @list
212
+ op requestHeaderResponseHeader(@continuationToken @header token?: string): {
213
+ @pageItems
214
+ pets: Pet[];
215
+
216
+ @continuationToken @header nextToken?: string;
217
+ };
218
+ }
55
219
  }
@@ -1,7 +1,94 @@
1
- import { json, MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
1
+ import {
2
+ json,
3
+ MockRequest,
4
+ passOnSuccess,
5
+ ScenarioMockApi,
6
+ ValidationError,
7
+ } from "@typespec/spec-api";
2
8
 
3
9
  export const Scenarios: Record<string, ScenarioMockApi> = {};
4
10
 
11
+ const FirstPage = [
12
+ { id: "1", name: "dog" },
13
+ { id: "2", name: "cat" },
14
+ ];
15
+
16
+ const SecondPage = [
17
+ { id: "3", name: "bird" },
18
+ { id: "4", name: "fish" },
19
+ ];
20
+
21
+ const FirstResponseTokenInBody = {
22
+ status: 200,
23
+ body: json({
24
+ pets: FirstPage,
25
+ nextToken: "page2",
26
+ }),
27
+ };
28
+
29
+ const SecondResponse = {
30
+ status: 200,
31
+ body: json({
32
+ pets: SecondPage,
33
+ }),
34
+ };
35
+
36
+ const FirstResponseTokenInHeader = {
37
+ status: 200,
38
+ body: json({
39
+ pets: FirstPage,
40
+ }),
41
+ headers: {
42
+ "next-token": "page2",
43
+ },
44
+ };
45
+
46
+ const RequestTokenInQuery = {
47
+ params: { token: "page2" },
48
+ };
49
+
50
+ const RequestTokenInHeader = { headers: { token: "page2" } };
51
+
52
+ function createTests(reqInfo: "query" | "header", resInfo: "body" | "header") {
53
+ const uri = `/payload/pageable/server-driven-pagination/continuationtoken/request-${reqInfo}-response-${resInfo}`;
54
+ function createHandler() {
55
+ return (req: MockRequest) => {
56
+ const token = reqInfo === "header" ? req.headers?.token : req.query?.token;
57
+ switch (token) {
58
+ case undefined:
59
+ return resInfo === "header" ? FirstResponseTokenInHeader : FirstResponseTokenInBody;
60
+ case "page2":
61
+ return SecondResponse;
62
+ default:
63
+ throw new ValidationError(
64
+ "Unsupported continuation token",
65
+ `"undefined" | "page2"`,
66
+ token,
67
+ );
68
+ }
69
+ };
70
+ }
71
+
72
+ return passOnSuccess([
73
+ {
74
+ uri: uri,
75
+ method: "get",
76
+ request: {},
77
+ response: resInfo === "header" ? FirstResponseTokenInHeader : FirstResponseTokenInBody,
78
+ handler: createHandler(),
79
+ kind: "MockApiDefinition",
80
+ },
81
+ {
82
+ uri: uri,
83
+ method: "get",
84
+ request: reqInfo === "header" ? RequestTokenInHeader : RequestTokenInQuery,
85
+ response: SecondResponse,
86
+ handler: createHandler(),
87
+ kind: "MockApiDefinition",
88
+ },
89
+ ]);
90
+ }
91
+
5
92
  Scenarios.Payload_Pageable_ServerDrivenPagination_link = passOnSuccess([
6
93
  {
7
94
  uri: "/payload/pageable/server-driven-pagination/link",
@@ -10,10 +97,7 @@ Scenarios.Payload_Pageable_ServerDrivenPagination_link = passOnSuccess([
10
97
  response: {
11
98
  status: 200,
12
99
  body: json({
13
- pets: [
14
- { id: "1", name: "dog" },
15
- { id: "2", name: "cat" },
16
- ],
100
+ pets: FirstPage,
17
101
  next: "/payload/pageable/server-driven-pagination/link/nextPage",
18
102
  }),
19
103
  },
@@ -21,10 +105,7 @@ Scenarios.Payload_Pageable_ServerDrivenPagination_link = passOnSuccess([
21
105
  return {
22
106
  status: 200,
23
107
  body: json({
24
- pets: [
25
- { id: "1", name: "dog" },
26
- { id: "2", name: "cat" },
27
- ],
108
+ pets: FirstPage,
28
109
  next: `${req.baseUrl}/payload/pageable/server-driven-pagination/link/nextPage`,
29
110
  }),
30
111
  };
@@ -35,15 +116,18 @@ Scenarios.Payload_Pageable_ServerDrivenPagination_link = passOnSuccess([
35
116
  uri: "/payload/pageable/server-driven-pagination/link/nextPage",
36
117
  method: "get",
37
118
  request: {},
38
- response: {
39
- status: 200,
40
- body: json({
41
- pets: [
42
- { id: "3", name: "bird" },
43
- { id: "4", name: "fish" },
44
- ],
45
- }),
46
- },
119
+ response: SecondResponse,
47
120
  kind: "MockApiDefinition",
48
121
  },
49
122
  ]);
123
+
124
+ Scenarios.Payload_Pageable_ServerDrivenPagination_ContinuationToken_requestQueryResponseBody =
125
+ createTests("query", "body");
126
+
127
+ Scenarios.Payload_Pageable_ServerDrivenPagination_ContinuationToken_requestHeaderResponseBody =
128
+ createTests("header", "body");
129
+
130
+ Scenarios.Payload_Pageable_ServerDrivenPagination_ContinuationToken_requestQueryResponseHeader =
131
+ createTests("query", "header");
132
+ Scenarios.Payload_Pageable_ServerDrivenPagination_ContinuationToken_requestHeaderResponseHeader =
133
+ createTests("header", "header");
@@ -463,6 +463,7 @@ interface SpreadRecordUnion
463
463
  > {}
464
464
 
465
465
  // ****************** spread record of discriminated unions **************************
466
+ #suppress "deprecated" "Legacy to replace with @discriminated(#{envelope: none})"
466
467
  @discriminator("kind")
467
468
  union WidgetData {
468
469
  kind0: WidgetData0,