diff --git a/.chronus/changes/remove-azure-core-nextlink-2024-10-18-20-51-27.md b/.chronus/changes/remove-azure-core-nextlink-2024-10-18-20-51-27.md new file mode 100644 index 0000000000..a44217d20a --- /dev/null +++ b/.chronus/changes/remove-azure-core-nextlink-2024-10-18-20-51-27.md @@ -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. diff --git a/.chronus/changes/remove-azure-core-nextlink-2024-11-2-16-55-46.md b/.chronus/changes/remove-azure-core-nextlink-2024-11-2-16-55-46.md new file mode 100644 index 0000000000..bc970a7a3b --- /dev/null +++ b/.chronus/changes/remove-azure-core-nextlink-2024-11-2-16-55-46.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-azure-resource-manager" +--- + +Replace usage of `Azure.Core.nextLink` to `TypeSpec.nextLink`. diff --git a/.chronus/changes/remove-azure-core-nextlink-2024-11-2-17-14-6.md b/.chronus/changes/remove-azure-core-nextlink-2024-11-2-17-14-6.md new file mode 100644 index 0000000000..060daa350e --- /dev/null +++ b/.chronus/changes/remove-azure-core-nextlink-2024-11-2-17-14-6.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/azure-http-specs" +--- + +Replace usage of `Azure.Core.nextLink` to `TypeSpec.nextLink`. \ No newline at end of file diff --git a/packages/azure-http-specs/specs/azure/core/page/main.tsp b/packages/azure-http-specs/specs/azure/core/page/main.tsp index 5bdfcf2d82..e592ed29d1 100644 --- a/packages/azure-http-specs/specs/azure/core/page/main.tsp +++ b/packages/azure-http-specs/specs/azure/core/page/main.tsp @@ -146,7 +146,7 @@ model CustomPageModel { @doc("List of items.") items: T[]; - @global.Azure.Core.nextLink + @nextLink @doc("Link to fetch more items.") nextLink?: string; } diff --git a/packages/e2e-tests/cadl-ranch-specs/package.json b/packages/e2e-tests/cadl-ranch-specs/package.json index b814844704..2ab4d289de 100644 --- a/packages/e2e-tests/cadl-ranch-specs/package.json +++ b/packages/e2e-tests/cadl-ranch-specs/package.json @@ -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 diff --git a/packages/typespec-autorest/test/paging.test.ts b/packages/typespec-autorest/test/paging.test.ts index 4fbdec9be2..0195027682 100644 --- a/packages/typespec-autorest/test/paging.test.ts +++ b/packages/typespec-autorest/test/paging.test.ts @@ -46,7 +46,7 @@ describe("Legacy define paging operation using Azure.Core decorators", () => { model CustomPageModel { items: T[]; - @Azure.Core.nextLink + @nextLink \`@odata.nextLink\`?: string; } op list(): CustomPageModel<{}>; @@ -66,7 +66,7 @@ describe("Legacy define paging operation using Azure.Core decorators", () => { @Azure.Core.items itemList?: string[]; - @Azure.Core.nextLink + @nextLink nextLink?: string; } diff --git a/packages/typespec-azure-core/README.md b/packages/typespec-azure-core/README.md index e9ddd4e7f0..3dfb5380f5 100644 --- a/packages/typespec-azure-core/README.md +++ b/packages/typespec-azure-core/README.md @@ -82,7 +82,6 @@ Available ruleSets: - [`@lroResult`](#@lroresult) - [`@lroStatus`](#@lrostatus) - [`@lroSucceeded`](#@lrosucceeded) -- [`@nextLink`](#@nextlink) - [`@nextPageOperation`](#@nextpageoperation) - [`@operationLink`](#@operationlink) - [`@pagedResult`](#@pagedresult) @@ -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. diff --git a/packages/typespec-azure-core/generated-defs/Azure.Core.ts b/packages/typespec-azure-core/generated-defs/Azure.Core.ts index 391c141f11..c77cab8841 100644 --- a/packages/typespec-azure-core/generated-defs/Azure.Core.ts +++ b/packages/typespec-azure-core/generated-defs/Azure.Core.ts @@ -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. */ @@ -194,7 +189,6 @@ export type AzureCoreDecorators = { finalLocation: FinalLocationDecorator; pollingLocation: PollingLocationDecorator; items: ItemsDecorator; - nextLink: NextLinkDecorator; pagedResult: PagedResultDecorator; fixed: FixedDecorator; lroSucceeded: LroSucceededDecorator; diff --git a/packages/typespec-azure-core/lib/decorators.tsp b/packages/typespec-azure-core/lib/decorators.tsp index 3239278433..17f07161ea 100644 --- a/packages/typespec-azure-core/lib/decorators.tsp +++ b/packages/typespec-azure-core/lib/decorators.tsp @@ -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 diff --git a/packages/typespec-azure-core/src/decorators.ts b/packages/typespec-azure-core/src/decorators.ts index 18da1f7769..79677eadcb 100644 --- a/packages/typespec-azure-core/src/decorators.ts +++ b/packages/typespec-azure-core/src/decorators.ts @@ -58,7 +58,6 @@ import { LroFailedDecorator, LroStatusDecorator, LroSucceededDecorator, - NextLinkDecorator, NextPageOperationDecorator, OperationLinkDecorator, PagedResultDecorator, @@ -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); } /** @@ -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); } /** diff --git a/packages/typespec-azure-core/src/lib.ts b/packages/typespec-azure-core/src/lib.ts index e5da72ad78..ec81c9963d 100644 --- a/packages/typespec-azure-core/src/lib.ts +++ b/packages/typespec-azure-core/src/lib.ts @@ -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" }, diff --git a/packages/typespec-azure-core/src/tsp-index.ts b/packages/typespec-azure-core/src/tsp-index.ts index 7bc300cc91..a1d9f8ec68 100644 --- a/packages/typespec-azure-core/src/tsp-index.ts +++ b/packages/typespec-azure-core/src/tsp-index.ts @@ -20,7 +20,6 @@ import { $lroStatus, $lroSucceeded, $needsRoute, - $nextLink, $nextPageOperation, $omitKeyProperties, $operationLink, @@ -58,7 +57,6 @@ export const $decorators = { pollingLocation: $pollingLocation, pagedResult: $pagedResult, items: $items, - nextLink: $nextLink, fixed: $fixed, lroSucceeded: $lroSucceeded, lroCanceled: $lroCanceled, diff --git a/packages/typespec-azure-core/test/decorators.test.ts b/packages/typespec-azure-core/test/decorators.test.ts index b012ecd26a..52025eab09 100644 --- a/packages/typespec-azure-core/test/decorators.test.ts +++ b/packages/typespec-azure-core/test/decorators.test.ts @@ -46,7 +46,7 @@ describe("typespec-azure-core: decorators", () => { @items foos: string[]; - @Azure.Core.nextLink + @nextLink nextThing?: string; } `); @@ -68,7 +68,7 @@ describe("typespec-azure-core: decorators", () => { things: string[]; doo: { - @Azure.Core.nextLink + @nextLink next?: string; } } @@ -90,7 +90,7 @@ describe("typespec-azure-core: decorators", () => { @items \`base.things\`: string[]; - @Azure.Core.nextLink + @nextLink \`base.next\`?: string; } `); @@ -170,7 +170,7 @@ describe("typespec-azure-core: decorators", () => { @doc(".") nested: { - @Azure.Core.nextLink + @nextLink @doc(".") nextLink: string; } @@ -209,7 +209,7 @@ describe("typespec-azure-core: decorators", () => { @doc(".") values?: string[]; - @Azure.Core.nextLink + @nextLink @doc(".") nextLink: string; } diff --git a/packages/typespec-azure-core/test/rules/use-standard-names.test.ts b/packages/typespec-azure-core/test/rules/use-standard-names.test.ts index 998a86e279..41d762191a 100644 --- a/packages/typespec-azure-core/test/rules/use-standard-names.test.ts +++ b/packages/typespec-azure-core/test/rules/use-standard-names.test.ts @@ -24,7 +24,7 @@ describe("typespec-azure-core: use-standard-names rule", () => { @pagedResult model FooPage { - @Azure.Core.nextLink + @nextLink next: string, @items value: Foo[]; @@ -98,7 +98,7 @@ describe("typespec-azure-core: use-standard-names rule", () => { @pagedResult model FooPage { - @Azure.Core.nextLink + @nextLink next: string, @items value: Foo[]; diff --git a/packages/typespec-azure-resource-manager/lib/models.tsp b/packages/typespec-azure-resource-manager/lib/models.tsp index 7b5cc1999b..f59be03064 100644 --- a/packages/typespec-azure-resource-manager/lib/models.tsp +++ b/packages/typespec-azure-resource-manager/lib/models.tsp @@ -308,7 +308,7 @@ model ResourceListCustomResult { value: Result[]; /** The link to the next page of items */ - @Azure.Core.nextLink + @nextLink nextLink?: string; } diff --git a/packages/typespec-client-generator-core/test/packages/paged-operation.test.ts b/packages/typespec-client-generator-core/test/packages/paged-operation.test.ts index 749663f7df..a8aede3811 100644 --- a/packages/typespec-client-generator-core/test/packages/paged-operation.test.ts +++ b/packages/typespec-client-generator-core/test/packages/paged-operation.test.ts @@ -25,7 +25,7 @@ describe("typespec-client-generator-core: paged operation", () => { @items @clientName("values") tests: Test[]; - @Azure.Core.nextLink + @nextLink @clientName("nextLink") next: string; } diff --git a/packages/typespec-client-generator-core/test/public-utils/is-paged-result-model.test.ts b/packages/typespec-client-generator-core/test/public-utils/is-paged-result-model.test.ts index 05e0e1e507..4563cb0505 100644 --- a/packages/typespec-client-generator-core/test/public-utils/is-paged-result-model.test.ts +++ b/packages/typespec-client-generator-core/test/public-utils/is-paged-result-model.test.ts @@ -23,7 +23,7 @@ describe("typespec-client-generator-core: public-utils", () => { @items value: Test[]; - @Azure.Core.nextLink + @nextLink nextLink?: url; } diff --git a/website/src/content/docs/docs/libraries/azure-core/reference/decorators.md b/website/src/content/docs/docs/libraries/azure-core/reference/decorators.md index 2e375cbe20..eb738c32e8 100644 --- a/website/src/content/docs/docs/libraries/azure-core/reference/decorators.md +++ b/website/src/content/docs/docs/libraries/azure-core/reference/decorators.md @@ -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. diff --git a/website/src/content/docs/docs/libraries/azure-core/reference/index.mdx b/website/src/content/docs/docs/libraries/azure-core/reference/index.mdx index ee43cf3b58..650f604614 100644 --- a/website/src/content/docs/docs/libraries/azure-core/reference/index.mdx +++ b/website/src/content/docs/docs/libraries/azure-core/reference/index.mdx @@ -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)