Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Azure.Core.nextLink in favor of TypeSpec.nextLink #1886

Merged
merged 13 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-azure-core"
---

Remove `Azure.Core.nextLink` as there is a nextLink instance in `TypeSpec.nextLink`, which is causing an ambiguous problem between the two.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-azure-resource-manager"
---

Replace usage of `Azure.Core.nextLink` to `TypeSpec.nextLink`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/azure-http-specs"
---

Replace usage of `Azure.Core.nextLink` to `TypeSpec.nextLink`.
2 changes: 1 addition & 1 deletion packages/azure-http-specs/specs/azure/core/page/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ model CustomPageModel<T> {
@doc("List of items.")
items: T[];

@global.Azure.Core.nextLink
@nextLink
@doc("Link to fetch more items.")
nextLink?: string;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/cadl-ranch-specs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@azure-tools/typespec-e2e-cadl-ranch-specs",
"dependencies": {
"@azure-tools/cadl-ranch-specs": "0.39.4"
"@azure-tools/cadl-ranch-specs": "0.39.5"
},
"type": "module",
"private": true
Expand Down
4 changes: 2 additions & 2 deletions packages/typespec-autorest/test/paging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("Legacy define paging operation using Azure.Core decorators", () => {
model CustomPageModel<T> {
items: T[];

@Azure.Core.nextLink
@nextLink
\`@odata.nextLink\`?: string;
}
op list(): CustomPageModel<{}>;
Expand All @@ -66,7 +66,7 @@ describe("Legacy define paging operation using Azure.Core decorators", () => {
@Azure.Core.items
itemList?: string[];

@Azure.Core.nextLink
@nextLink
nextLink?: string;
}

Expand Down
17 changes: 0 additions & 17 deletions packages/typespec-azure-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ Available ruleSets:
- [`@lroResult`](#@lroresult)
- [`@lroStatus`](#@lrostatus)
- [`@lroSucceeded`](#@lrosucceeded)
- [`@nextLink`](#@nextlink)
- [`@nextPageOperation`](#@nextpageoperation)
- [`@operationLink`](#@operationlink)
- [`@pagedResult`](#@pagedresult)
Expand Down Expand Up @@ -266,22 +265,6 @@ Identifies an EnumMember as a long-running "Succeeded" terminal state.

None

#### `@nextLink`

Identifies a ModelProperty that contains the next link value. Can only be used on a Model marked with `@pagedResult`.

```typespec
@Azure.Core.nextLink
```

##### Target

`ModelProperty`

##### Parameters

None

#### `@nextPageOperation`

Identifies that an operation is used to retrieve the next page for paged operations.
Expand Down
6 changes: 0 additions & 6 deletions packages/typespec-azure-core/generated-defs/Azure.Core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ export type PollingLocationDecorator = (
*/
export type ItemsDecorator = (context: DecoratorContext, entity: ModelProperty) => void;

/**
* Identifies a ModelProperty that contains the next link value. Can only be used on a Model marked with `@pagedResult`.
*/
export type NextLinkDecorator = (context: DecoratorContext, entity: ModelProperty) => void;

/**
* Marks a Model as a paged collection.
*/
Expand Down Expand Up @@ -194,7 +189,6 @@ export type AzureCoreDecorators = {
finalLocation: FinalLocationDecorator;
pollingLocation: PollingLocationDecorator;
items: ItemsDecorator;
nextLink: NextLinkDecorator;
pagedResult: PagedResultDecorator;
fixed: FixedDecorator;
lroSucceeded: LroSucceededDecorator;
Expand Down
5 changes: 0 additions & 5 deletions packages/typespec-azure-core/lib/decorators.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ namespace Azure.Core {
*/
extern dec items(entity: ModelProperty);

/**
* Identifies a ModelProperty that contains the next link value. Can only be used on a Model marked with `@pagedResult`.
*/
extern dec nextLink(entity: ModelProperty);

/**
* Used for custom StatusMonitor implementation.
* Identifies an Enum or ModelProperty as containing long-running operation
Expand Down
11 changes: 3 additions & 8 deletions packages/typespec-azure-core/src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import {
LroFailedDecorator,
LroStatusDecorator,
LroSucceededDecorator,
NextLinkDecorator,
NextPageOperationDecorator,
OperationLinkDecorator,
PagedResultDecorator,
Expand Down Expand Up @@ -152,7 +151,7 @@ function _getItems(program: Program, entity: Model): PropertyPath | undefined {
}

function _getNextLink(program: Program, entity: Model): PropertyPath | undefined {
return findPathToProperty(program, entity, (prop) => getNextLink(program, prop) !== undefined);
return findPathToProperty(program, entity, (prop) => getNextLink(program, prop) === true);
}

/**
Expand Down Expand Up @@ -268,15 +267,11 @@ export function getItems(program: Program, entity: Type): boolean | undefined {
return program.stateMap(AzureCoreStateKeys.items).get(entity);
}

export const $nextLink: NextLinkDecorator = (context: DecoratorContext, entity: ModelProperty) => {
context.program.stateMap(AzureCoreStateKeys.nextLink).set(entity, true);
};

/**
* Returns `true` if the property is marked with `@nextLink`.
*/
export function getNextLink(program: Program, entity: Type): boolean | undefined {
return program.stateMap(AzureCoreStateKeys.nextLink).get(entity);
export function getNextLink(program: Program, entity: ModelProperty): boolean | undefined {
return program.stateSet(Symbol.for(`TypeSpec.nextLink`)).has(entity);
markcowl marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
1 change: 0 additions & 1 deletion packages/typespec-azure-core/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ export const $lib = createTypeSpecLibrary({
fixed: { description: "Data for `@fixed` decorator" },
pagedResult: { description: "Data for `@pagedResult` decorator" },
items: { description: "Data for `@items` decorator" },
nextLink: { description: "Data for `@nextLink` decorator" },
lroStatus: { description: "Data for `@lroStatus` decorator" },
lroSucceeded: { description: "Data for `@lroSucceeded` decorator" },
lroCanceled: { description: "Data for `@lroCanceled` decorator" },
Expand Down
2 changes: 0 additions & 2 deletions packages/typespec-azure-core/src/tsp-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
$lroStatus,
$lroSucceeded,
$needsRoute,
$nextLink,
$nextPageOperation,
$omitKeyProperties,
$operationLink,
Expand Down Expand Up @@ -58,7 +57,6 @@ export const $decorators = {
pollingLocation: $pollingLocation,
pagedResult: $pagedResult,
items: $items,
nextLink: $nextLink,
fixed: $fixed,
lroSucceeded: $lroSucceeded,
lroCanceled: $lroCanceled,
Expand Down
10 changes: 5 additions & 5 deletions packages/typespec-azure-core/test/decorators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("typespec-azure-core: decorators", () => {
@items
foos: string[];

@Azure.Core.nextLink
@nextLink
nextThing?: string;
}
`);
Expand All @@ -68,7 +68,7 @@ describe("typespec-azure-core: decorators", () => {
things: string[];

doo: {
@Azure.Core.nextLink
@nextLink
next?: string;
}
}
Expand All @@ -90,7 +90,7 @@ describe("typespec-azure-core: decorators", () => {
@items
\`base.things\`: string[];

@Azure.Core.nextLink
@nextLink
\`base.next\`?: string;
}
`);
Expand Down Expand Up @@ -170,7 +170,7 @@ describe("typespec-azure-core: decorators", () => {

@doc(".")
nested: {
@Azure.Core.nextLink
@nextLink
@doc(".")
nextLink: string;
}
Expand Down Expand Up @@ -209,7 +209,7 @@ describe("typespec-azure-core: decorators", () => {
@doc(".")
values?: string[];

@Azure.Core.nextLink
@nextLink
@doc(".")
nextLink: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("typespec-azure-core: use-standard-names rule", () => {

@pagedResult
model FooPage {
@Azure.Core.nextLink
@nextLink
next: string,
@items
value: Foo[];
Expand Down Expand Up @@ -98,7 +98,7 @@ describe("typespec-azure-core: use-standard-names rule", () => {

@pagedResult
model FooPage {
@Azure.Core.nextLink
@nextLink
next: string,
@items
value: Foo[];
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-azure-resource-manager/lib/models.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ model ResourceListCustomResult<Result> {
value: Result[];

/** The link to the next page of items */
@Azure.Core.nextLink
@nextLink
nextLink?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("typespec-client-generator-core: paged operation", () => {
@items
@clientName("values")
tests: Test[];
@Azure.Core.nextLink
@nextLink
@clientName("nextLink")
next: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("typespec-client-generator-core: public-utils", () => {
@items
value: Test[];

@Azure.Core.nextLink
@nextLink
nextLink?: url;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,6 @@ Identifies an EnumMember as a long-running "Succeeded" terminal state.

None

### `@nextLink` {#@Azure.Core.nextLink}

Identifies a ModelProperty that contains the next link value. Can only be used on a Model marked with `@pagedResult`.

```typespec
@Azure.Core.nextLink
```

#### Target

`ModelProperty`

#### Parameters

None

### `@nextPageOperation` {#@Azure.Core.nextPageOperation}

Identifies that an operation is used to retrieve the next page for paged operations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ npm install --save-peer @azure-tools/typespec-azure-core
- [`@lroResult`](./decorators.md#@Azure.Core.lroResult)
- [`@lroStatus`](./decorators.md#@Azure.Core.lroStatus)
- [`@lroSucceeded`](./decorators.md#@Azure.Core.lroSucceeded)
- [`@nextLink`](./decorators.md#@Azure.Core.nextLink)
- [`@nextPageOperation`](./decorators.md#@Azure.Core.nextPageOperation)
- [`@operationLink`](./decorators.md#@Azure.Core.operationLink)
- [`@pagedResult`](./decorators.md#@Azure.Core.pagedResult)
Expand Down
Loading