Skip to content

Commit

Permalink
Improve generated paging methods when next operation is not specified (
Browse files Browse the repository at this point in the history
  • Loading branch information
xirzec authored Nov 29, 2022
1 parent cd004be commit 3a74a90
Show file tree
Hide file tree
Showing 366 changed files with 237 additions and 1,933 deletions.
8 changes: 4 additions & 4 deletions packages/autorest.typescript/src/pagingHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export interface PageInfo {
const pageMap = new WeakMap<object, PageInfo>();

/**
* Given a result page from a pageable operation, returns a
* continuation token that can be used to begin paging from
* Given the last `.value` produced by the `byPage` iterator,
* returns a continuation token that can be used to begin paging from
* that point later.
* @param page A result object from calling .byPage() on a paged operation.
* @returns The continuation token that can be passed into byPage().
* @param page An object from accessing `value` on the IteratorResult from a `byPage` iterator.
* @returns The continuation token that can be passed into byPage() during future calls.
*/
export function getContinuationToken(page: unknown): string | undefined {
if (typeof page !== "object" || page === null) {
Expand Down
15 changes: 14 additions & 1 deletion packages/autorest.typescript/src/transforms/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,22 @@ function addPageableMethods(codeModel: CodeModel) {
}
);

// Filter out query parameters from the original operation.
if (nextLinkMethod.parameters) {
nextLinkMethod.parameters = nextLinkMethod.parameters.filter(
param => param.protocol.http?.in !== ParameterLocation.Query
);
if (nextLinkMethod.signatureParameters) {
nextLinkMethod.updateSignatureParameters();
}
}

// Ensure all overloads support the nextLink parameter.
for (const request of nextLinkMethod.requests ?? []) {
const parameters = request.parameters ?? [];
let parameters = request.parameters ?? [];
parameters = parameters.filter(param => {
return param.protocol.http?.in !== ParameterLocation.Query;
});
parameters.push(nextLinkParameter);
request.parameters = parameters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,6 @@ const getKeysNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
queryParameters: [Parameters.name, Parameters.apiVersion, Parameters.after],
urlParameters: [Parameters.endpoint, Parameters.nextLink],
headerParameters: [
Parameters.accept,
Expand All @@ -926,13 +925,6 @@ const getKeyValuesNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
queryParameters: [
Parameters.apiVersion,
Parameters.after,
Parameters.key,
Parameters.label,
Parameters.select
],
urlParameters: [Parameters.endpoint, Parameters.nextLink],
headerParameters: [
Parameters.syncToken,
Expand All @@ -953,12 +945,6 @@ const getLabelsNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
queryParameters: [
Parameters.name,
Parameters.apiVersion,
Parameters.after,
Parameters.select4
],
urlParameters: [Parameters.endpoint, Parameters.nextLink],
headerParameters: [
Parameters.syncToken,
Expand All @@ -979,13 +965,6 @@ const getRevisionsNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
queryParameters: [
Parameters.apiVersion,
Parameters.after,
Parameters.key,
Parameters.label,
Parameters.select5
],
urlParameters: [Parameters.endpoint, Parameters.nextLink],
headerParameters: [
Parameters.syncToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,6 @@ export type CheckRevisionsResponse = AppConfigurationClientCheckRevisionsHeaders

/** Optional parameters. */
export interface GetKeysNextOptionalParams extends coreClient.OperationOptions {
/** A filter for the name of the returned keys. */
name?: string;
/** Instructs the server to return elements that appear after the element referred to by the specified token. */
after?: string;
/** Requests the server to respond with the state of the resource at the specified time. */
acceptDatetime?: string;
}
Expand All @@ -649,16 +645,8 @@ export type GetKeysNextResponse = AppConfigurationClientGetKeysNextHeaders &
/** Optional parameters. */
export interface GetKeyValuesNextOptionalParams
extends coreClient.OperationOptions {
/** Instructs the server to return elements that appear after the element referred to by the specified token. */
after?: string;
/** Requests the server to respond with the state of the resource at the specified time. */
acceptDatetime?: string;
/** A filter used to match keys. */
key?: string;
/** A filter used to match labels */
label?: string;
/** Used to select what fields are present in the returned resource(s). */
select?: Get6ItemsItem[];
}

/** Contains response data for the getKeyValuesNext operation. */
Expand All @@ -668,14 +656,8 @@ export type GetKeyValuesNextResponse = AppConfigurationClientGetKeyValuesNextHea
/** Optional parameters. */
export interface GetLabelsNextOptionalParams
extends coreClient.OperationOptions {
/** A filter for the name of the returned labels. */
name?: string;
/** Instructs the server to return elements that appear after the element referred to by the specified token. */
after?: string;
/** Requests the server to respond with the state of the resource at the specified time. */
acceptDatetime?: string;
/** Used to select what fields are present in the returned resource(s). */
select?: string[];
}

/** Contains response data for the getLabelsNext operation. */
Expand All @@ -685,16 +667,8 @@ export type GetLabelsNextResponse = AppConfigurationClientGetLabelsNextHeaders &
/** Optional parameters. */
export interface GetRevisionsNextOptionalParams
extends coreClient.OperationOptions {
/** Instructs the server to return elements that appear after the element referred to by the specified token. */
after?: string;
/** Requests the server to respond with the state of the resource at the specified time. */
acceptDatetime?: string;
/** A filter used to match keys. */
key?: string;
/** A filter used to match labels */
label?: string;
/** Used to select what fields are present in the returned resource(s). */
select?: Enum4[];
}

/** Contains response data for the getRevisionsNext operation. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export interface PageInfo {
const pageMap = new WeakMap<object, PageInfo>();

/**
* Given a result page from a pageable operation, returns a
* continuation token that can be used to begin paging from
* Given the last `.value` produced by the `byPage` iterator,
* returns a continuation token that can be used to begin paging from
* that point later.
* @param page A result object from calling .byPage() on a paged operation.
* @returns The continuation token that can be passed into byPage().
* @param page An object from accessing `value` on the IteratorResult from a `byPage` iterator.
* @returns The continuation token that can be passed into byPage() during future calls.
*/
export function getContinuationToken(page: unknown): string | undefined {
if (typeof page !== "object" || page === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,6 @@ const getKeysNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
queryParameters: [Parameters.name, Parameters.apiVersion, Parameters.after],
urlParameters: [Parameters.endpoint, Parameters.nextLink],
headerParameters: [
Parameters.accept,
Expand All @@ -927,13 +926,6 @@ const getKeyValuesNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
queryParameters: [
Parameters.apiVersion,
Parameters.after,
Parameters.key,
Parameters.label,
Parameters.select
],
urlParameters: [Parameters.endpoint, Parameters.nextLink],
headerParameters: [
Parameters.syncToken,
Expand All @@ -954,12 +946,6 @@ const getLabelsNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
queryParameters: [
Parameters.name,
Parameters.apiVersion,
Parameters.after,
Parameters.select4
],
urlParameters: [Parameters.endpoint, Parameters.nextLink],
headerParameters: [
Parameters.syncToken,
Expand All @@ -980,13 +966,6 @@ const getRevisionsNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
queryParameters: [
Parameters.apiVersion,
Parameters.after,
Parameters.key,
Parameters.label,
Parameters.select5
],
urlParameters: [Parameters.endpoint, Parameters.nextLink],
headerParameters: [
Parameters.syncToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,6 @@ export type CheckRevisionsResponse = AppConfigurationClientCheckRevisionsHeaders

/** Optional parameters. */
export interface GetKeysNextOptionalParams extends coreClient.OperationOptions {
/** A filter for the name of the returned keys. */
name?: string;
/** Instructs the server to return elements that appear after the element referred to by the specified token. */
after?: string;
/** Requests the server to respond with the state of the resource at the specified time. */
acceptDatetime?: string;
}
Expand All @@ -649,16 +645,8 @@ export type GetKeysNextResponse = AppConfigurationClientGetKeysNextHeaders &
/** Optional parameters. */
export interface GetKeyValuesNextOptionalParams
extends coreClient.OperationOptions {
/** Instructs the server to return elements that appear after the element referred to by the specified token. */
after?: string;
/** Requests the server to respond with the state of the resource at the specified time. */
acceptDatetime?: string;
/** A filter used to match keys. */
key?: string;
/** A filter used to match labels */
label?: string;
/** Used to select what fields are present in the returned resource(s). */
select?: Get6ItemsItem[];
}

/** Contains response data for the getKeyValuesNext operation. */
Expand All @@ -668,14 +656,8 @@ export type GetKeyValuesNextResponse = AppConfigurationClientGetKeyValuesNextHea
/** Optional parameters. */
export interface GetLabelsNextOptionalParams
extends coreClient.OperationOptions {
/** A filter for the name of the returned labels. */
name?: string;
/** Instructs the server to return elements that appear after the element referred to by the specified token. */
after?: string;
/** Requests the server to respond with the state of the resource at the specified time. */
acceptDatetime?: string;
/** Used to select what fields are present in the returned resource(s). */
select?: string[];
}

/** Contains response data for the getLabelsNext operation. */
Expand All @@ -685,16 +667,8 @@ export type GetLabelsNextResponse = AppConfigurationClientGetLabelsNextHeaders &
/** Optional parameters. */
export interface GetRevisionsNextOptionalParams
extends coreClient.OperationOptions {
/** Instructs the server to return elements that appear after the element referred to by the specified token. */
after?: string;
/** Requests the server to respond with the state of the resource at the specified time. */
acceptDatetime?: string;
/** A filter used to match keys. */
key?: string;
/** A filter used to match labels */
label?: string;
/** Used to select what fields are present in the returned resource(s). */
select?: Enum4[];
}

/** Contains response data for the getRevisionsNext operation. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export interface PageInfo {
const pageMap = new WeakMap<object, PageInfo>();

/**
* Given a result page from a pageable operation, returns a
* continuation token that can be used to begin paging from
* Given the last `.value` produced by the `byPage` iterator,
* returns a continuation token that can be used to begin paging from
* that point later.
* @param page A result object from calling .byPage() on a paged operation.
* @returns The continuation token that can be passed into byPage().
* @param page An object from accessing `value` on the IteratorResult from a `byPage` iterator.
* @returns The continuation token that can be passed into byPage() during future calls.
*/
export function getContinuationToken(page: unknown): string | undefined {
if (typeof page !== "object" || page === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export interface PageInfo {
const pageMap = new WeakMap<object, PageInfo>();

/**
* Given a result page from a pageable operation, returns a
* continuation token that can be used to begin paging from
* Given the last `.value` produced by the `byPage` iterator,
* returns a continuation token that can be used to begin paging from
* that point later.
* @param page A result object from calling .byPage() on a paged operation.
* @returns The continuation token that can be passed into byPage().
* @param page An object from accessing `value` on the IteratorResult from a `byPage` iterator.
* @returns The continuation token that can be passed into byPage() during future calls.
*/
export function getContinuationToken(page: unknown): string | undefined {
if (typeof page !== "object" || page === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,6 @@ const queryByFactoryNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.nextLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ const listByFactoryNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.nextLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ const listByFactoryNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.nextLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ const listNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.nextLink,
Expand All @@ -593,7 +592,6 @@ const listByResourceGroupNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.nextLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,6 @@ const listByFactoryNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.nextLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ const listByFactoryNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.nextLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ const listByFactoryNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.nextLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ const listByFactoryNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.nextLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ const listNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host, Parameters.nextLink],
headerParameters: [Parameters.accept],
serializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ const listByFactoryNextOperationSpec: coreClient.OperationSpec = {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.nextLink,
Expand Down
Loading

0 comments on commit 3a74a90

Please sign in to comment.