Skip to content

Commit

Permalink
add check for default value
Browse files Browse the repository at this point in the history
  • Loading branch information
Pete Siki authored and Pete Siki committed Dec 16, 2024
1 parent dbf68a1 commit a7754c0
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Name,
NameAndWireValue,
OffsetPagination,
RequestProperty,
ResponseError,
TypeReference
} from "@fern-fern/ir-sdk/api";
Expand Down Expand Up @@ -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 }))
Expand Down Expand Up @@ -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("0")
ts.factory.createNumericLiteral(defaultValue.toString())
)
)
],
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit a7754c0

Please sign in to comment.