Filtered
Filtered
Section titled “Filtered”A 200 response with a paginated list of filtered 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 |
| sortInfo | SortedResultsInfo | The sort order of the items |
| filterInfo | object | The filters applied to the response items |
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 }, "sortInfo": { "field": "name", "direction": "asc" }, "filterInfo": { "filters": { "lastModifiedAt": { "operator": "gte", "value": "2024-01-01T00:00:00Z" }, "status": { "operator": "in", "value": [ "active", "inactive" ] } } }}The JSON Schema for this model.
$schema: https://json-schema.org/draft/2020-12/schema$id: Filtered.yamltype: objectproperties: items: type: array items: {} description: Items from the current page paginationInfo: $ref: PaginatedResultsInfo.yaml description: Details about the paginated results sortInfo: $ref: SortedResultsInfo.yaml description: The sort order of the items filterInfo: type: object properties: filters: {} errors: type: array items: type: string description: Non-fatal errors that occurred during filtering required: - filters unevaluatedProperties: not: {} description: The filters applied to the response itemsrequired: - items - paginationInfo - sortInfo - filterInfoallOf: - $ref: Success.yamlunevaluatedProperties: not: {}description: A paginated list of items with a filterThe TypeSpec code for this model.
/** Body properties shared by `Filtered` and `FilteredT<ItemsT, FilterT>` * * @template ItemsT The schema for the value of the `"items"` property in this response * @template FilterT The schema for the value of the `"filter"` property in this response */@Versioning.added(CommonGrants.Versions.v0_1)model FilteredBase<ItemsT, FilterT> { ...SortedBase<ItemsT>;
/** The filters applied to the response items */ filterInfo: { filters: FilterT;
/** Non-fatal errors that occurred during filtering */ errors?: string[]; };}
/** A paginated list of items of an unspecified shape with a filter * * Routes use the typed `FilteredT<ItemsT, FilterT>` variant. */@doc("A paginated list of items with a filter")@Versioning.added(CommonGrants.Versions.v0_1)model Filtered extends Success { ...FilteredBase<unknown, unknown>;}The Python code for this model.
class FilterInfo(CommonGrantsBaseModel, Generic[FilterT]): """Filter information for search results."""
filters: FilterT = Field( ..., description="The filters applied to the response items" ) errors: Optional[list[str]] = Field( default_factory=lambda: [], description="Non-fatal errors that occurred during filtering", )
class Filtered(Sorted[ItemsT], Generic[ItemsT, FilterT]): """A paginated list of items with a filter."""
filter_info: FilterInfo[FilterT] = Field( ..., description="The filters applied to the response items", )
model_config = {"populate_by_name": True}The TypeScript code for this model.
export const FilteredSchema = <ItemsT extends z.ZodType, FilterT extends z.ZodType>( itemsSchema: ItemsT, filterSchema: FilterT) => SortedSchema(itemsSchema).extend({ /** The filters applied to the response items */ filterInfo: z .object({ filters: filterSchema,
/** Non-fatal errors that occurred during filtering */ errors: z.array(z.string()).nullish(), }) .strict(), });Version headers
Section titled “Version headers”From v0.6.0, the typed FilteredT<ItemsT, FilterT> 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 FilteredT<ItemsT, FilterT> template to define a 200 response with a paginated list of filtered, typed items within an API operation:
import "@common-grants/core";import "@typespec/http";
using TypeSpec.Http;using CommonGrants;using CommonGrants.Pagination;using CommonGrants.Responses;
model TestModel { id: string; name: string;}
model TestFilter extends Record<Filters.DefaultFilter> { lastModifiedAt: Filters.DateComparisonFilter;}
@summary("Search test models")@doc("Get a paginated list of test models matching a filter")@postop searchTest(...PaginatedBodyParams): FilteredT<TestModel, TestFilter>;Changelog
Section titled “Changelog”| Version | Changes | Schema |
|---|---|---|
| 0.1.0 |
| Filtered.yaml |