Skip to content

Add pagination and partial fetching options to listTemplates operation #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,31 @@ Development tool SDKs each development tool typically provides a library for int
## Reference Implementation

A reference implementation of the protocol is available in the [server](./server) directory.

## Pagination and Partial Fetching

The `listTemplates` operation now supports pagination and partial fetching options. The following query parameters are available:

- `offset`: The number of items to skip before starting to collect the result set.
- `limit`: The number of items to return.
- `fields`: A comma-separated list of fields to include in the response.

The response includes pagination metadata and pagination links:

```json
{
"data": [...],
"meta": {
"total": 100,
"offset": 0,
"limit": 10
},
"links": {
"self": "/templates?offset=0&limit=10",
"next": "/templates?offset=10&limit=10",
"prev": null,
"first": "/templates?offset=0&limit=10",
"last": "/templates?offset=90&limit=10"
}
}
```
30 changes: 29 additions & 1 deletion client/typescript/apap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ export interface paths {
* @description Creates a new instance of a `template`.
*/
post: operations["createTemplate"];
parameters: {
query: {
offset?: number;
limit?: number;
fields?: string;
};
};
};
"/templates/{name}": {
/**
Expand Down Expand Up @@ -1576,11 +1583,32 @@ export interface operations {
* List All Templates
* @description Gets a list of all `template` entities.
*/
parameters: {
query: {
offset?: number;
limit?: number;
fields?: string;
};
};
responses: {
/** @description Successful response - returns an array of `template` entities. */
200: {
content: {
"application/json": (components["schemas"]["[email protected]"])[];
"application/json": {
data: (components["schemas"]["[email protected]"])[],
meta: {
total: number;
offset: number;
limit: number;
},
links: {
self: string;
next?: string;
prev?: string;
first: string;
last: string;
}
};
};
};
};
Expand Down
26 changes: 23 additions & 3 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,28 @@ const api = new OpenAPIBackend({
quick: true, // disabled validation of OpenAPI on load
definition: openApiPath,
handlers: {
listTemplates: async (c, req: Express.Request, res: Express.Response) =>
res.status(200).json([]),
listTemplates: async (c, req: Express.Request, res: Express.Response) => {
const { offset = 0, limit = 10, fields } = req.query;
const templates = []; // Fetch templates from your data source
const total = templates.length;
const paginatedTemplates = templates.slice(offset, offset + limit);
const response = {
data: paginatedTemplates,
meta: {
total,
offset,
limit,
},
links: {
self: `/templates?offset=${offset}&limit=${limit}`,
next: offset + limit < total ? `/templates?offset=${offset + limit}&limit=${limit}` : null,
prev: offset > 0 ? `/templates?offset=${offset - limit}&limit=${limit}` : null,
first: `/templates?offset=0&limit=${limit}`,
last: `/templates?offset=${Math.floor(total / limit) * limit}&limit=${limit}`,
},
};
res.status(200).json(response);
},
createTemplate: async (c, req: Express.Request, res: Express.Response) =>
res.status(200).json({}),
getTemplate: async (c, req: Express.Request, res: Express.Response) =>
Expand All @@ -45,4 +65,4 @@ app.use(morgan('combined'));
app.use((req, res) => api.handleRequest(req as Request, req, res));

// start server
app.listen(9000, () => console.info('api listening at http://localhost:9000'));
app.listen(9000, () => console.info('api listening at http://localhost:9000'));