diff --git a/generators/typescript/sdk/CHANGELOG.md b/generators/typescript/sdk/CHANGELOG.md index dfcaf565457..ffc3b000c85 100644 --- a/generators/typescript/sdk/CHANGELOG.md +++ b/generators/typescript/sdk/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.44.2] - 2024-12-16 + +- Fix: Sets default pagination offset to 0 or default if provided + ## [0.44.1] - 2024-12-16 - Fix: When there is an environment variable set, you do not need to pass in any parameters diff --git a/generators/typescript/sdk/VERSION b/generators/typescript/sdk/VERSION index 73f8a5ac928..b51b5439eef 100644 --- a/generators/typescript/sdk/VERSION +++ b/generators/typescript/sdk/VERSION @@ -1 +1 @@ -0.44.1 +0.44.2 diff --git a/generators/typescript/sdk/client-class-generator/src/endpoints/default/endpoint-response/GeneratedThrowingEndpointResponse.ts b/generators/typescript/sdk/client-class-generator/src/endpoints/default/endpoint-response/GeneratedThrowingEndpointResponse.ts index f272f24ad59..c708ee8a93d 100644 --- a/generators/typescript/sdk/client-class-generator/src/endpoints/default/endpoint-response/GeneratedThrowingEndpointResponse.ts +++ b/generators/typescript/sdk/client-class-generator/src/endpoints/default/endpoint-response/GeneratedThrowingEndpointResponse.ts @@ -7,6 +7,7 @@ import { Name, NameAndWireValue, OffsetPagination, + RequestProperty, ResponseError, TypeReference } from "@fern-fern/ir-sdk/api"; @@ -211,6 +212,9 @@ export class GeneratedThrowingEndpointResponse implements GeneratedEndpointRespo // initializeOffset uses the offset property if set const pageProperty = this.getNameFromWireValue({ name: offset.page.property.name, context }); + + const defaultValue = this.getDefaultValue(offset.page); + const pagePropertyPath = [ "request", ...(offset.page.propertyPath ?? []).map((name) => this.getName({ name, context })) @@ -241,7 +245,7 @@ export class GeneratedThrowingEndpointResponse implements GeneratedEndpointRespo ts.factory.createToken(ts.SyntaxKind.QuestionToken), pagePropertyAccess, ts.factory.createToken(ts.SyntaxKind.ColonToken), - ts.factory.createNumericLiteral("1") + ts.factory.createNumericLiteral(defaultValue.toString()) ) ) ], @@ -370,6 +374,16 @@ export class GeneratedThrowingEndpointResponse implements GeneratedEndpointRespo : name.name.camelCase.safeName; } + public getDefaultValue(page: RequestProperty): number { + if (page.property.valueType.type === "primitive") { + const v2PrimitiveType = page.property.valueType.primitive.v2; + if (v2PrimitiveType?.type === "integer") { + return v2PrimitiveType.default ?? 0; + } + } + return 0; + } + public getResponseVariableName(): string { return GeneratedThrowingEndpointResponse.RESPONSE_VARIABLE_NAME; }