Skip to content

Commit

Permalink
(feature, IRv48): Add offset pagination step (#3865)
Browse files Browse the repository at this point in the history
amckinney authored Jun 18, 2024
1 parent cd84dec commit c8b81b0
Showing 117 changed files with 7,090 additions and 288 deletions.
10 changes: 10 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
4 changes: 4 additions & 0 deletions fern.schema.dev.json
Original file line number Diff line number Diff line change
@@ -759,6 +759,10 @@
"results": {
"type": "string",
"description": "The path to the response property for the page elements."
},
"step": {
"type": "string",
"description": "The path to the request property for the page step."
}
},
"required": ["offset", "results"],
4 changes: 4 additions & 0 deletions fern.schema.json
Original file line number Diff line number Diff line change
@@ -759,6 +759,10 @@
"results": {
"type": "string",
"description": "The path to the response property for the page elements."
},
"step": {
"type": "string",
"description": "The path to the request property for the page step."
}
},
"required": ["offset", "results"],
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ import { RawSchemas } from "@fern-api/yaml-schema";
import { FernFileContext } from "../../FernFileContext";
import { PropertyResolver } from "../../resolvers/PropertyResolver";
import { CursorPaginationPropertyComponents } from "./convertPaginationUtils";
import { convertQueryParameter } from "./convertQueryParameter";

export async function convertCursorPagination({
propertyResolver,
@@ -18,18 +17,11 @@ export async function convertCursorPagination({
endpointSchema: RawSchemas.HttpEndpointSchema;
paginationPropertyComponents: CursorPaginationPropertyComponents;
}): Promise<Pagination | undefined> {
const queryParameterSchema =
typeof endpointSchema.request !== "string" && endpointSchema.request?.["query-parameters"] != null
? endpointSchema?.request?.["query-parameters"]?.[paginationPropertyComponents.cursor]
: undefined;
if (queryParameterSchema == null) {
return undefined;
}
return Pagination.cursor({
page: await convertQueryParameter({
page: await propertyResolver.resolveRequestPropertyOrThrow({
file,
queryParameterKey: paginationPropertyComponents.cursor,
queryParameter: queryParameterSchema
endpoint: endpointName,
propertyComponents: paginationPropertyComponents.cursor
}),
next: await propertyResolver.resolveResponsePropertyOrThrow({
file,
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ import { RawSchemas } from "@fern-api/yaml-schema";
import { FernFileContext } from "../../FernFileContext";
import { PropertyResolver } from "../../resolvers/PropertyResolver";
import { OffsetPaginationPropertyComponents } from "./convertPaginationUtils";
import { convertQueryParameter } from "./convertQueryParameter";

export async function convertOffsetPagination({
propertyResolver,
@@ -18,23 +17,24 @@ export async function convertOffsetPagination({
endpointSchema: RawSchemas.HttpEndpointSchema;
paginationPropertyComponents: OffsetPaginationPropertyComponents;
}): Promise<Pagination | undefined> {
const queryParameterSchema =
typeof endpointSchema.request !== "string" && endpointSchema.request?.["query-parameters"] != null
? endpointSchema?.request?.["query-parameters"]?.[paginationPropertyComponents.offset]
: undefined;
if (queryParameterSchema == null) {
return undefined;
}
return Pagination.offset({
page: await convertQueryParameter({
page: await propertyResolver.resolveRequestPropertyOrThrow({
file,
queryParameterKey: paginationPropertyComponents.offset,
queryParameter: queryParameterSchema
endpoint: endpointName,
propertyComponents: paginationPropertyComponents.offset
}),
results: await propertyResolver.resolveResponsePropertyOrThrow({
file,
endpoint: endpointName,
propertyComponents: paginationPropertyComponents.results
})
}),
step:
paginationPropertyComponents.step != null
? await propertyResolver.resolveRequestPropertyOrThrow({
file,
endpoint: endpointName,
propertyComponents: paginationPropertyComponents.step
})
: undefined
});
}
Original file line number Diff line number Diff line change
@@ -2,21 +2,22 @@ import { RawSchemas } from "@fern-api/yaml-schema";
import { FernFileContext } from "../../FernFileContext";
import { ResolvedType } from "../../resolvers/ResolvedType";
import { TypeResolver } from "../../resolvers/TypeResolver";
import { getRequestProperty, getResponsePropertyComponents } from "./convertProperty";
import { getRequestPropertyComponents, getResponsePropertyComponents } from "./convertProperty";

export type PaginationPropertyComponents = CursorPaginationPropertyComponents | OffsetPaginationPropertyComponents;

export interface CursorPaginationPropertyComponents {
type: "cursor";
cursor: string;
cursor: string[];
next_cursor: string[];
results: string[];
}

export interface OffsetPaginationPropertyComponents {
type: "offset";
offset: string;
offset: string[];
results: string[];
step: string[] | undefined;
}

export function getPaginationPropertyComponents(
@@ -25,13 +26,14 @@ export function getPaginationPropertyComponents(
if (isRawOffsetPaginationSchema(endpointPagination)) {
return {
type: "offset",
offset: getRequestProperty(endpointPagination.offset),
results: getResponsePropertyComponents(endpointPagination.results)
offset: getRequestPropertyComponents(endpointPagination.offset),
results: getResponsePropertyComponents(endpointPagination.results),
step: endpointPagination.step != null ? getRequestPropertyComponents(endpointPagination.step) : undefined
};
}
return {
type: "cursor",
cursor: getRequestProperty(endpointPagination.cursor),
cursor: getRequestPropertyComponents(endpointPagination.cursor),
next_cursor: getResponsePropertyComponents(endpointPagination.next_cursor),
results: getResponsePropertyComponents(endpointPagination.results)
};
Original file line number Diff line number Diff line change
@@ -192,10 +192,6 @@ function maybeObjectSchema(resolvedType: ResolvedType | undefined): RawSchemas.O
return undefined;
}

export function getRequestProperty(value: string): string {
return value.substring("$request.".length);
}

export function getRequestPropertyComponents(value: string): string[] {
const trimmed = value.substring("$request.".length);
return trimmed?.split(".") ?? [];
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import {
getNestedObjectPropertyFromResolvedType,
maybeFileFromResolvedType
} from "../converters/services/convertProperty";
import { convertQueryParameter } from "../converters/services/convertQueryParameter";
import { FernFileContext } from "../FernFileContext";
import { EndpointResolver } from "./EndpointResolver";
import { TypeResolver } from "./TypeResolver";
@@ -73,7 +74,7 @@ export class PropertyResolverImpl implements PropertyResolver {
return undefined;
}
if (typeof resolvedEndpoint.endpoint.request !== "string") {
return this.resolveRequestPropertyFromInlinedRequestBody({
return this.resolveRequestPropertyFromInlinedRequest({
typeResolver: this.typeResolver,
file: resolvedEndpoint.file,
requestType: resolvedEndpoint.endpoint.request,
@@ -148,6 +149,45 @@ export class PropertyResolverImpl implements PropertyResolver {
};
}

private async resolveRequestPropertyFromInlinedRequest({
typeResolver,
file,
requestType,
propertyComponents
}: {
typeResolver: TypeResolver;
file: FernFileContext;
requestType: RawSchemas.HttpRequestSchema;
propertyComponents: string[];
}): Promise<RequestProperty | undefined> {
if (propertyComponents.length === 1) {
// Query parameters can only be defined on the root level of the request.
const queryParameterKey = propertyComponents[0] ?? "";
const queryParameter =
typeof requestType["query-parameters"] != null
? requestType["query-parameters"]?.[queryParameterKey]
: undefined;
if (queryParameter != null) {
return {
property: RequestPropertyValue.query(
await convertQueryParameter({
file,
queryParameterKey,
queryParameter
})
),
propertyPath: undefined
};
}
}
return this.resolveRequestPropertyFromInlinedRequestBody({
typeResolver,
file,
requestType,
propertyComponents
});
}

private async resolveRequestPropertyFromInlinedRequestBody({
typeResolver,
file,
1 change: 1 addition & 0 deletions packages/cli/generation/ir-migrations/package.json
Original file line number Diff line number Diff line change
@@ -77,6 +77,7 @@
"@fern-fern/ir-v44-sdk": "0.0.1",
"@fern-fern/ir-v45-sdk": "0.0.3",
"@fern-fern/ir-v46-sdk": "0.0.1",
"@fern-fern/ir-v47-sdk": "0.0.1",
"@fern-fern/ir-v5-model": "0.0.3",
"@fern-fern/ir-v6-model": "0.0.33",
"@fern-fern/ir-v7-model": "0.0.2",
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ import { V44_TO_V43_MIGRATION } from "./migrations/v44-to-v43/migrateFromV44ToV4
import { V45_TO_V44_MIGRATION } from "./migrations/v45-to-v44/migrateFromV45ToV44";
import { V46_TO_V45_MIGRATION } from "./migrations/v46-to-v45/migrateFromV46ToV45";
import { V47_TO_V46_MIGRATION } from "./migrations/v47-to-v46/migrateFromV47ToV46";
import { V48_TO_V47_MIGRATION } from "./migrations/v48-to-v47/migrateFromV48ToV47";
import { V5_TO_V4_MIGRATION } from "./migrations/v5-to-v4/migrateFromV5ToV4";
import { V6_TO_V5_MIGRATION } from "./migrations/v6-to-v5/migrateFromV6ToV5";
import { V7_TO_V6_MIGRATION } from "./migrations/v7-to-v6/migrateFromV7ToV6";
@@ -272,6 +273,7 @@ const IntermediateRepresentationMigrator = {

const INTERMEDIATE_REPRESENTATION_MIGRATOR = IntermediateRepresentationMigrator.Builder
// put new migrations here
.withMigration(V48_TO_V47_MIGRATION)
.withMigration(V47_TO_V46_MIGRATION)
.withMigration(V46_TO_V45_MIGRATION)
.withMigration(V45_TO_V44_MIGRATION)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { serialization as V47 } from "@fern-api/ir-sdk";
export { serialization as V48 } from "@fern-api/ir-sdk";
export * as V23 from "@fern-fern/ir-v23-sdk/serialization";
export * as V24 from "@fern-fern/ir-v24-sdk/serialization";
export * as V25 from "@fern-fern/ir-v25-sdk/serialization";
@@ -23,3 +23,4 @@ export * as V43 from "@fern-fern/ir-v43-sdk/serialization";
export * as V44 from "@fern-fern/ir-v44-sdk/serialization";
export * as V45 from "@fern-fern/ir-v45-sdk/serialization";
export * as V46 from "@fern-fern/ir-v46-sdk/serialization";
export * as V47 from "@fern-fern/ir-v47-sdk/serialization";
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { FernIr as V47 } from "@fern-api/ir-sdk";
export { FernIr as V48 } from "@fern-api/ir-sdk";
export * as V1 from "@fern-fern/ir-v1-model";
export * as V10 from "@fern-fern/ir-v10-model";
export * as V11 from "@fern-fern/ir-v11-model";
@@ -40,6 +40,7 @@ export { FernIrV43 as V43 } from "@fern-fern/ir-v43-sdk";
export { FernIrV44 as V44 } from "@fern-fern/ir-v44-sdk";
export { FernIrV45 as V45 } from "@fern-fern/ir-v45-sdk";
export { FernIrV46 as V46 } from "@fern-fern/ir-v46-sdk";
export { FernIrV47 as V47 } from "@fern-fern/ir-v47-sdk";
export * as V5 from "@fern-fern/ir-v5-model";
export * as V6 from "@fern-fern/ir-v6-model";
export * as V7 from "@fern-fern/ir-v7-model";
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
name: simple-api

auth: bearer
Loading

0 comments on commit c8b81b0

Please sign in to comment.