diff --git a/.chronus/changes/spector-continuation-token-paging-2025-1-25-11-50-47.md b/.chronus/changes/spector-continuation-token-paging-2025-1-25-11-50-47.md new file mode 100644 index 0000000000..e7c6c9a650 --- /dev/null +++ b/.chronus/changes/spector-continuation-token-paging-2025-1-25-11-50-47.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@typespec/http-specs" +--- + +all parameters including headers and queries shall be passed when next call for continuation token paging \ No newline at end of file diff --git a/packages/http-specs/package.json b/packages/http-specs/package.json index 8e574f2572..7b74ab7343 100644 --- a/packages/http-specs/package.json +++ b/packages/http-specs/package.json @@ -10,6 +10,7 @@ "clean": "rimraf dist/ temp/", "test:e2e": "pnpm validate-scenarios && pnpm validate-mock-apis && pnpm validate-client-server", "validate:all": "pnpm build && pnpm regen-docs && pnpm test:e2e", + "ci": "prettier specs --write && pnpm validate:all", "validate-scenarios": "tsp-spector validate-scenarios ./specs", "generate-scenarios-summary": "tsp-spector generate-scenarios-summary ./specs", "regen-docs": "pnpm generate-scenarios-summary", diff --git a/packages/http-specs/spec-summary.md b/packages/http-specs/spec-summary.md index b3b321f3c1..941a64cee8 100644 --- a/packages/http-specs/spec-summary.md +++ b/packages/http-specs/spec-summary.md @@ -1670,7 +1670,10 @@ Test case for using continuation token as pagination. Continuation token is pass Two requests need to be tested. 1. Initial request: - Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body + Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body?bar=bar + +Expected request header: +foo=foo Expected response body: @@ -1685,10 +1688,11 @@ Expected response body: ``` 2. Next page request: - Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body + Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body?bar=bar -Expected header: +Expected request header: token=page2 +foo=foo Expected response body: @@ -1710,8 +1714,12 @@ Test case for using continuation token as pagination. Continuation token is pass Two requests need to be tested. 1. Initial request: - Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header - Expected response body: + Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header?bar=bar + +Expected request header: +foo=foo + +Expected response body: ```json { @@ -1726,10 +1734,11 @@ Expected response header: next-token=page2 2. Next page request: - Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header + Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header?bar=bar Expected request header: token=page2 +foo=foo Expected response body: @@ -1751,8 +1760,12 @@ Test case for using continuation token as pagination. Continuation token is pass Two requests need to be tested. 1. Initial request: - Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body - Expected response body: + Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body?bar=bar + +Expected request header: +foo=foo + +Expected response body: ```json { @@ -1765,7 +1778,10 @@ Two requests need to be tested. ``` 2. Next page request: - Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body?token=page2 + Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body?bar=bar&token=page2 + +Expected request header: +foo=foo Expected response body: @@ -1787,8 +1803,12 @@ Test case for using continuation token as pagination. Continuation token is pass Two requests need to be tested. 1. Initial request: - Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header - Expected response body: + Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header?bar=bar + +Expected request header: +foo=foo + +Expected response body: ```json { @@ -1803,8 +1823,12 @@ Expected response header: next-token=page2 2. Next page request: - Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header?token=page2 - Expected response body: + Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header?bar=bar&token=page2 + +Expected request header: +foo=foo + +Expected response body: ```json { diff --git a/packages/http-specs/specs/payload/pageable/main.tsp b/packages/http-specs/specs/payload/pageable/main.tsp index c761d1a3de..f123c65954 100644 --- a/packages/http-specs/specs/payload/pageable/main.tsp +++ b/packages/http-specs/specs/payload/pageable/main.tsp @@ -15,6 +15,11 @@ model Pet { name: string; } +alias HeaderAndQuery = { + @header foo?: string; + @query bar?: string; +}; + @route("/server-driven-pagination") namespace ServerDrivenPagination { @scenario @@ -60,8 +65,13 @@ namespace ServerDrivenPagination { Test case for using continuation token as pagination. Continuation token is passed in the request query and response body. Two requests need to be tested. + 1. Initial request: - Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body + Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body?bar=bar + + Expected request header: + foo=foo + Expected response body: ```json { "pets": [ @@ -73,7 +83,10 @@ namespace ServerDrivenPagination { ``` 2. Next page request: - Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body?token=page2 + Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body?bar=bar&token=page2 + + Expected request header: + foo=foo Expected response body: ```json @@ -86,7 +99,7 @@ namespace ServerDrivenPagination { """) @route("/request-query-response-body") @list - op requestQueryResponseBody(@continuationToken @query token?: string): { + op requestQueryResponseBody(@continuationToken @query token?: string, ...HeaderAndQuery): { @pageItems pets: Pet[]; @@ -98,8 +111,12 @@ namespace ServerDrivenPagination { Test case for using continuation token as pagination. Continuation token is passed in the request header and response body. Two requests need to be tested. + 1. Initial request: - Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body + Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body?bar=bar + + Expected request header: + foo=foo Expected response body: ```json @@ -110,11 +127,13 @@ namespace ServerDrivenPagination { "nextToken": "page2" } ``` + 2. Next page request: - Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body + Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body?bar=bar - Expected header: + Expected request header: token=page2 + foo=foo Expected response body: ```json @@ -127,7 +146,7 @@ namespace ServerDrivenPagination { """) @route("/request-header-response-body") @list - op requestHeaderResponseBody(@continuationToken @header token?: string): { + op requestHeaderResponseBody(@continuationToken @header token?: string, ...HeaderAndQuery): { @pageItems pets: Pet[]; @@ -139,8 +158,13 @@ namespace ServerDrivenPagination { Test case for using continuation token as pagination. Continuation token is passed in the request query and response header. Two requests need to be tested. + 1. Initial request: - Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header + Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header?bar=bar + + Expected request header: + foo=foo + Expected response body: ```json { "pets": [ @@ -154,7 +178,11 @@ namespace ServerDrivenPagination { next-token=page2 2. Next page request: - Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header?token=page2 + Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header?bar=bar&token=page2 + + Expected request header: + foo=foo + Expected response body: ```json { "pets": [ @@ -166,7 +194,7 @@ namespace ServerDrivenPagination { """) @route("/request-query-response-header") @list - op requestQueryResponseHeader(@continuationToken @query token?: string): { + op requestQueryResponseHeader(@continuationToken @query token?: string, ...HeaderAndQuery): { @pageItems pets: Pet[]; @@ -179,7 +207,11 @@ namespace ServerDrivenPagination { Two requests need to be tested. 1. Initial request: - Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header + Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header?bar=bar + + Expected request header: + foo=foo + Expected response body: ```json { "pets": [ @@ -193,10 +225,11 @@ namespace ServerDrivenPagination { next-token=page2 2. Next page request: - Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header + Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header?bar=bar Expected request header: token=page2 + foo=foo Expected response body: ```json @@ -209,7 +242,7 @@ namespace ServerDrivenPagination { """) @route("/request-header-response-header") @list - op requestHeaderResponseHeader(@continuationToken @header token?: string): { + op requestHeaderResponseHeader(@continuationToken @header token?: string, ...HeaderAndQuery): { @pageItems pets: Pet[]; diff --git a/packages/http-specs/specs/payload/pageable/mockapi.ts b/packages/http-specs/specs/payload/pageable/mockapi.ts index 443d632499..13928c2c0d 100644 --- a/packages/http-specs/specs/payload/pageable/mockapi.ts +++ b/packages/http-specs/specs/payload/pageable/mockapi.ts @@ -40,19 +40,23 @@ const FirstResponseTokenInHeader = { }), headers: { "next-token": "page2", + foo: "foo", }, }; const RequestTokenInQuery = { - params: { token: "page2" }, + params: { token: "page2", bar: "bar" }, + headers: { foo: "foo" }, }; -const RequestTokenInHeader = { headers: { token: "page2" } }; +const RequestTokenInHeader = { headers: { token: "page2", foo: "foo" }, params: { bar: "bar" } }; function createTests(reqInfo: "query" | "header", resInfo: "body" | "header") { const uri = `/payload/pageable/server-driven-pagination/continuationtoken/request-${reqInfo}-response-${resInfo}`; function createHandler() { return (req: MockRequest) => { + req.expect.containsHeader("foo", "foo"); + req.expect.containsQueryParam("bar", "bar"); const token = reqInfo === "header" ? req.headers?.token : req.query?.token; switch (token) { case undefined: @@ -73,7 +77,7 @@ function createTests(reqInfo: "query" | "header", resInfo: "body" | "header") { { uri: uri, method: "get", - request: {}, + request: { headers: { foo: "foo" }, params: { bar: "bar" } }, response: resInfo === "header" ? FirstResponseTokenInHeader : FirstResponseTokenInBody, handler: createHandler(), kind: "MockApiDefinition",