Implement Pagination
Konfig supports pagination out-of-the-box with an incredibly simple implementation process.
1) Configure konfig.yaml for pagination
_20# konfig.yaml_20_20outputDirectory: /tmp/acme-sdks-out_20specPath: openapi.json_20generators:_20 typescript:_20 version: 1.0.0_20 npmName: acme-typescript-sdk_20 outputDirectory: typescript_20 git:_20 userId: konfig-dev_20 repoId: acme-sdks/tree/main/typescript_20 pagination:_20 parameters: # parameter names to match_20 - page_size_20 - page_20 response: # response property names to match_20 - page_size_20 - page_20 - total_pages
2) Implement stubbed methods
_56// page.ts_56_56import { Pageable, PageParametersBase } from "./pageable";_56_56/**_56 * The set of parameters that appear in a paginated operation (requestBody or parameters)_56 */_56export type PageParameterProperties = {_56 // stubbed as: [key: string]: any_56 page?: number;_56 pageSize?: number;_56};_56_56export type PageParameters = PageParametersBase<PageParameterProperties>;_56_56/**_56 * The set of properties that appear in a paginated operation's response_56 */_56export interface PageInfo {_56 // stubbed as: [key: string]: any_56 total_pages?: number;_56 page?: number;_56 page_size?: number;_56}_56_56export class Page<_56 Data extends PageInfo,_56 Parameters extends PageParameters_56> extends Pageable<Data, Parameters> {_56 protected get previousParameters(): PageParameterProperties | null {_56 // stubbed as: throw Error("Stub");_56 if (this.data.page === undefined) return null;_56 return {_56 page: this.data.page - 1,_56 };_56 }_56_56 protected get nextParameters(): PageParameterProperties | null {_56 // stubbed as: throw Error("Stub");_56 if (this.data.page === undefined) return null;_56 return {_56 page: this.data.page + 1,_56 };_56 }_56 hasPrevious(): boolean {_56 // stubbed as: throw Error("Stub");_56 return this.data.page === undefined ? false : this.data.page > 0;_56 }_56_56 hasNext(): boolean {_56 // stubbed as: throw Error("Stub");_56 if (this.data.page === undefined) return false;_56 if (this.data.total_pages === undefined) return false;_56 return this.data.page < this.data.total_pages;_56 }_56}
3) Add custom implementation to .konfigignore
_10❯ konfig ignore -g "typescript/pagination/page.ts"_10Adding pagination/page.ts to typescript/.konfigignore