Paginated
Paginated
Section titled “Paginated”A 200 response with a paginated list of items.
| Parameter | Type | Description |
|---|---|---|
| status | integer | The HTTP status code |
| message | string | The message to return |
| items | array | Items from the current page |
| paginationInfo | PaginatedResultsInfo | Details about the pagination |
Formats
Section titled “Formats”A JSON example of this model.
{ "status": 200, "message": "Success", "items": [ { "id": "123", "name": "Test 1" }, { "id": "124", "name": "Test 2" } ], "paginationInfo": { "page": 1, "pageSize": 10, "totalItems": 25, "totalPages": 3 }}The JSON Schema for this model.
$schema: https://json-schema.org/draft/2020-12/schema$id: Paginated.yamltype: objectproperties: items: type: array items: {} description: Items from the current page paginationInfo: $ref: PaginatedResultsInfo.yaml description: Details about the paginated resultsrequired: - items - paginationInfoallOf: - $ref: Success.yamlunevaluatedProperties: not: {}description: A 200 response with a paginated list of itemsThe TypeSpec code for this model.
/** Body properties shared by `Paginated` and `PaginatedT<T>` * * @template T The schema for the value of the `"items"` property in this response */@Versioning.added(CommonGrants.Versions.v0_1)model PaginatedBase<T> { /** Items from the current page */ @pageItems items: T[];
/** Details about the paginated results */ paginationInfo: Pagination.PaginatedResultsInfo;}
/** A 200 response with a paginated list of items of an unspecified shape * * Routes use the typed `PaginatedT<T>` variant. */@doc("A 200 response with a paginated list of items")@Versioning.added(CommonGrants.Versions.v0_1)model Paginated extends Success { ...PaginatedBase<unknown>;}The Python code for this model.
class Paginated(Success, Generic[ItemsT]): """Template for a response with a paginated list of items."""
items: list[ItemsT] = Field(..., description="Items from the current page") pagination_info: PaginatedResultsInfo = Field( ..., description="Details about the paginated results", )
model_config = {"populate_by_name": True}The TypeScript code for this model.
export const PaginatedSchema = <T extends z.ZodType>(itemsSchema: T) => SuccessSchema.extend({ /** Items from the current page */ items: z.array(itemsSchema),
/** Details about the paginated results */ paginationInfo: PaginatedResultsInfoSchema, });Version headers
Section titled “Version headers”From v0.6.0, the typed PaginatedT<T> response carries the version response headers declared in Headers.VersionResponse: CG-Version-Served, which reports the full protocol version the response was served in, and the optional Vary, Deprecation, Sunset and Link headers. See Versioning and the Versions section of the specification.
Use the PaginatedT<T> template to define a 200 response with a paginated list of typed items within an API operation:
import "@common-grants/core";import "@typespec/http";
using TypeSpec.Http;using CommonGrants.Pagination;using CommonGrants.Responses;
model TestModel { id: string; name: string;}
@summary("List test models")@doc("Get a paginated list of test models")@getop listTest(...PaginatedQueryParams): PaginatedT<TestModel>;Changelog
Section titled “Changelog”| Version | Changes | Schema |
|---|---|---|
| 0.1.0 |
| Paginated.yaml |