From 39e87018248f02aa013999dabc3ef66d1882c1d5 Mon Sep 17 00:00:00 2001 From: Xiaogang Ding Date: Tue, 12 Aug 2025 09:44:58 +0800 Subject: [PATCH] tsp - add support for @list and upgrade to 1.3.0 --- common/config/rush/pnpm-lock.yaml | 318 +++++++++--------- packages/typespec-powershell/package.json | 14 +- .../src/convertor/convertor.ts | 12 +- .../src/utils/modelUtils.ts | 2 +- .../src/utils/operationUtil.ts | 106 +++++- .../main.tsp | 1 + .../Sphere.Management/catalog.tsp | 4 + .../Sphere.Management/product.tsp | 1 + tests-upgrade/tests-emitter/package.json | 24 +- 9 files changed, 291 insertions(+), 191 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 6cc4e777b6f..52f8d31203c 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -30,20 +30,20 @@ dependencies: specifier: ~3.0.0 version: 3.0.255 '@azure-tools/typespec-autorest': - specifier: 0.58.0 - version: 0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@azure-tools/typespec-azure-resource-manager@0.58.0)(@azure-tools/typespec-client-generator-core@0.58.0)(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/openapi@1.2.1)(@typespec/rest@0.72.1)(@typespec/versioning@0.72.1) + specifier: 0.59.0 + version: 0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@azure-tools/typespec-azure-resource-manager@0.59.0)(@azure-tools/typespec-client-generator-core@0.59.0)(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/openapi@1.3.0)(@typespec/rest@0.73.0)(@typespec/versioning@0.73.0) '@azure-tools/typespec-azure-core': - specifier: 0.58.0 - version: 0.58.0(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/rest@0.72.1) + specifier: 0.59.0 + version: 0.59.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/rest@0.73.0) '@azure-tools/typespec-azure-resource-manager': - specifier: 0.58.0 - version: 0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/openapi@1.2.1)(@typespec/rest@0.72.1)(@typespec/versioning@0.72.1) + specifier: 0.59.0 + version: 0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/openapi@1.3.0)(@typespec/rest@0.73.0)(@typespec/versioning@0.73.0) '@azure-tools/typespec-azure-rulesets': - specifier: 0.58.0 - version: 0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@azure-tools/typespec-azure-resource-manager@0.58.0)(@azure-tools/typespec-client-generator-core@0.58.0)(@typespec/compiler@1.2.1) + specifier: 0.59.0 + version: 0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@azure-tools/typespec-azure-resource-manager@0.59.0)(@azure-tools/typespec-client-generator-core@0.59.0)(@typespec/compiler@1.3.0) '@azure-tools/typespec-client-generator-core': - specifier: 0.58.0 - version: 0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/openapi@1.2.1)(@typespec/rest@0.72.1)(@typespec/streams@0.72.1)(@typespec/versioning@0.72.1)(@typespec/xml@0.72.1) + specifier: 0.59.0 + version: 0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/openapi@1.3.0)(@typespec/rest@0.73.0)(@typespec/streams@0.73.0)(@typespec/versioning@0.73.0)(@typespec/xml@0.73.0) '@azure-tools/typespec-liftr-base': specifier: 0.8.0 version: 0.8.0 @@ -81,26 +81,26 @@ dependencies: specifier: ~5.62.0 version: 5.62.0(eslint@8.12.0)(typescript@5.1.6) '@typespec/compiler': - specifier: 1.2.1 - version: 1.2.1(@types/node@20.14.15) + specifier: 1.3.0 + version: 1.3.0(@types/node@20.14.15) '@typespec/http': - specifier: 1.2.1 - version: 1.2.1(@typespec/compiler@1.2.1)(@typespec/streams@0.72.1) + specifier: 1.3.0 + version: 1.3.0(@typespec/compiler@1.3.0)(@typespec/streams@0.73.0) '@typespec/openapi': - specifier: 1.2.1 - version: 1.2.1(@typespec/compiler@1.2.1)(@typespec/http@1.2.1) + specifier: 1.3.0 + version: 1.3.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0) '@typespec/rest': - specifier: 0.72.1 - version: 0.72.1(@typespec/compiler@1.2.1)(@typespec/http@1.2.1) + specifier: 0.73.0 + version: 0.73.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0) '@typespec/streams': - specifier: 0.72.1 - version: 0.72.1(@typespec/compiler@1.2.1) + specifier: 0.73.0 + version: 0.73.0(@typespec/compiler@1.3.0) '@typespec/versioning': - specifier: 0.72.1 - version: 0.72.1(@typespec/compiler@1.2.1) + specifier: 0.73.0 + version: 0.73.0(@typespec/compiler@1.3.0) '@typespec/xml': - specifier: 0.72.1 - version: 0.72.1(@typespec/compiler@1.2.1) + specifier: 0.73.0 + version: 0.73.0(@typespec/compiler@1.3.0) autorest: specifier: ~3.6.3 version: 3.6.3 @@ -233,101 +233,101 @@ packages: engines: {node: '>=10.12.0'} dev: false - /@azure-tools/typespec-autorest@0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@azure-tools/typespec-azure-resource-manager@0.58.0)(@azure-tools/typespec-client-generator-core@0.58.0)(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/openapi@1.2.1)(@typespec/rest@0.72.1)(@typespec/versioning@0.72.1): - resolution: {integrity: sha512-zhQbbbp7SekE7uNeyAdAzpTKimsaRbpI5g4mBReCT2X2CS4BWuk+mRDTb617Wrkn8Axy2M9dtlopGT0AXdMNTw==} + /@azure-tools/typespec-autorest@0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@azure-tools/typespec-azure-resource-manager@0.59.0)(@azure-tools/typespec-client-generator-core@0.59.0)(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/openapi@1.3.0)(@typespec/rest@0.73.0)(@typespec/versioning@0.73.0): + resolution: {integrity: sha512-IdjicuLJRNFZUWHJd1Z8e9RQUlVUyUb2v7pT1rYkhpxAxFb9uluVVpi09GkUFimkrUZ+HkFO/jI2zbIAptZ2FQ==} engines: {node: '>=20.0.0'} peerDependencies: - '@azure-tools/typespec-azure-core': ^0.58.0 - '@azure-tools/typespec-azure-resource-manager': ^0.58.0 - '@azure-tools/typespec-client-generator-core': ^0.58.0 - '@typespec/compiler': ^1.2.0 - '@typespec/http': ^1.2.0 - '@typespec/openapi': ^1.2.0 - '@typespec/rest': ^0.72.0 - '@typespec/versioning': ^0.72.0 - dependencies: - '@azure-tools/typespec-azure-core': 0.58.0(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/rest@0.72.1) - '@azure-tools/typespec-azure-resource-manager': 0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/openapi@1.2.1)(@typespec/rest@0.72.1)(@typespec/versioning@0.72.1) - '@azure-tools/typespec-client-generator-core': 0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/openapi@1.2.1)(@typespec/rest@0.72.1)(@typespec/streams@0.72.1)(@typespec/versioning@0.72.1)(@typespec/xml@0.72.1) - '@typespec/compiler': 1.2.1(@types/node@20.14.15) - '@typespec/http': 1.2.1(@typespec/compiler@1.2.1)(@typespec/streams@0.72.1) - '@typespec/openapi': 1.2.1(@typespec/compiler@1.2.1)(@typespec/http@1.2.1) - '@typespec/rest': 0.72.1(@typespec/compiler@1.2.1)(@typespec/http@1.2.1) - '@typespec/versioning': 0.72.1(@typespec/compiler@1.2.1) - dev: false - - /@azure-tools/typespec-azure-core@0.58.0(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/rest@0.72.1): - resolution: {integrity: sha512-Z4vX+ic85hCPr27t9DKCVTj2MjHDaXDvh10Z4wVokXIR2/GjAQrHQp4OFu/0R+cwqmuXb6nnuBZNikwKk7dNzw==} + '@azure-tools/typespec-azure-core': ^0.59.0 + '@azure-tools/typespec-azure-resource-manager': ^0.59.0 + '@azure-tools/typespec-client-generator-core': ^0.59.0 + '@typespec/compiler': ^1.3.0 + '@typespec/http': ^1.3.0 + '@typespec/openapi': ^1.3.0 + '@typespec/rest': ^0.73.0 + '@typespec/versioning': ^0.73.0 + dependencies: + '@azure-tools/typespec-azure-core': 0.59.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/rest@0.73.0) + '@azure-tools/typespec-azure-resource-manager': 0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/openapi@1.3.0)(@typespec/rest@0.73.0)(@typespec/versioning@0.73.0) + '@azure-tools/typespec-client-generator-core': 0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/openapi@1.3.0)(@typespec/rest@0.73.0)(@typespec/streams@0.73.0)(@typespec/versioning@0.73.0)(@typespec/xml@0.73.0) + '@typespec/compiler': 1.3.0(@types/node@20.14.15) + '@typespec/http': 1.3.0(@typespec/compiler@1.3.0)(@typespec/streams@0.73.0) + '@typespec/openapi': 1.3.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0) + '@typespec/rest': 0.73.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0) + '@typespec/versioning': 0.73.0(@typespec/compiler@1.3.0) + dev: false + + /@azure-tools/typespec-azure-core@0.59.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/rest@0.73.0): + resolution: {integrity: sha512-3vTWDTSR+P0qeyFcOKTgXortNOeA3nsyKTPpZqfFZVTtNFiiO17UWAM2Eg3i0IpNQ3qxMMAksIkwt1bqltTDqA==} engines: {node: '>=20.0.0'} peerDependencies: - '@typespec/compiler': ^1.2.0 - '@typespec/http': ^1.2.0 - '@typespec/rest': ^0.72.0 + '@typespec/compiler': ^1.3.0 + '@typespec/http': ^1.3.0 + '@typespec/rest': ^0.73.0 dependencies: - '@typespec/compiler': 1.2.1(@types/node@20.14.15) - '@typespec/http': 1.2.1(@typespec/compiler@1.2.1)(@typespec/streams@0.72.1) - '@typespec/rest': 0.72.1(@typespec/compiler@1.2.1)(@typespec/http@1.2.1) + '@typespec/compiler': 1.3.0(@types/node@20.14.15) + '@typespec/http': 1.3.0(@typespec/compiler@1.3.0)(@typespec/streams@0.73.0) + '@typespec/rest': 0.73.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0) dev: false - /@azure-tools/typespec-azure-resource-manager@0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/openapi@1.2.1)(@typespec/rest@0.72.1)(@typespec/versioning@0.72.1): - resolution: {integrity: sha512-OSDADgmvvTiQgAh/7cu2yiSdc4SM5JYk3W84F+1lRiM80JG8PiRXMSZcIHIQnnySUVSiT1oMuVK+Fx5prUWJuQ==} + /@azure-tools/typespec-azure-resource-manager@0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/openapi@1.3.0)(@typespec/rest@0.73.0)(@typespec/versioning@0.73.0): + resolution: {integrity: sha512-q0UkBnwWE4+9ivAkwAOOrDF9kvSb+qRIvMXJdUlqGfwFqDkOvQFwHSzSDeL/mBNK2fB9NIePKPFjDGP9lpC0vQ==} engines: {node: '>=20.0.0'} peerDependencies: - '@azure-tools/typespec-azure-core': ^0.58.0 - '@typespec/compiler': ^1.2.0 - '@typespec/http': ^1.2.0 - '@typespec/openapi': ^1.2.0 - '@typespec/rest': ^0.72.0 - '@typespec/versioning': ^0.72.0 - dependencies: - '@azure-tools/typespec-azure-core': 0.58.0(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/rest@0.72.1) - '@typespec/compiler': 1.2.1(@types/node@20.14.15) - '@typespec/http': 1.2.1(@typespec/compiler@1.2.1)(@typespec/streams@0.72.1) - '@typespec/openapi': 1.2.1(@typespec/compiler@1.2.1)(@typespec/http@1.2.1) - '@typespec/rest': 0.72.1(@typespec/compiler@1.2.1)(@typespec/http@1.2.1) - '@typespec/versioning': 0.72.1(@typespec/compiler@1.2.1) + '@azure-tools/typespec-azure-core': ^0.59.0 + '@typespec/compiler': ^1.3.0 + '@typespec/http': ^1.3.0 + '@typespec/openapi': ^1.3.0 + '@typespec/rest': ^0.73.0 + '@typespec/versioning': ^0.73.0 + dependencies: + '@azure-tools/typespec-azure-core': 0.59.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/rest@0.73.0) + '@typespec/compiler': 1.3.0(@types/node@20.14.15) + '@typespec/http': 1.3.0(@typespec/compiler@1.3.0)(@typespec/streams@0.73.0) + '@typespec/openapi': 1.3.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0) + '@typespec/rest': 0.73.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0) + '@typespec/versioning': 0.73.0(@typespec/compiler@1.3.0) change-case: 5.4.4 pluralize: 8.0.0 dev: false - /@azure-tools/typespec-azure-rulesets@0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@azure-tools/typespec-azure-resource-manager@0.58.0)(@azure-tools/typespec-client-generator-core@0.58.0)(@typespec/compiler@1.2.1): - resolution: {integrity: sha512-AkbhFxbeD3mYHbdnQEd1iWhSuQ2KxoN5JOU6BFP7mo/RVjIgGjj2ekro1tCnq381LOXdFfEoJievSFI5fvyRxQ==} + /@azure-tools/typespec-azure-rulesets@0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@azure-tools/typespec-azure-resource-manager@0.59.0)(@azure-tools/typespec-client-generator-core@0.59.0)(@typespec/compiler@1.3.0): + resolution: {integrity: sha512-+eKYH25ptj6SZHT+/YfxrX+g6HMAQQTphmHmqOoRCbbfPaE8l855OaDrwEgh5NDLV8WXnHpzTNI0dsYipEp10g==} engines: {node: '>=20.0.0'} peerDependencies: - '@azure-tools/typespec-azure-core': ^0.58.0 - '@azure-tools/typespec-azure-resource-manager': ^0.58.0 - '@azure-tools/typespec-client-generator-core': ^0.58.0 - '@typespec/compiler': ^1.2.0 + '@azure-tools/typespec-azure-core': ^0.59.0 + '@azure-tools/typespec-azure-resource-manager': ^0.59.0 + '@azure-tools/typespec-client-generator-core': ^0.59.0 + '@typespec/compiler': ^1.3.0 dependencies: - '@azure-tools/typespec-azure-core': 0.58.0(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/rest@0.72.1) - '@azure-tools/typespec-azure-resource-manager': 0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/openapi@1.2.1)(@typespec/rest@0.72.1)(@typespec/versioning@0.72.1) - '@azure-tools/typespec-client-generator-core': 0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/openapi@1.2.1)(@typespec/rest@0.72.1)(@typespec/streams@0.72.1)(@typespec/versioning@0.72.1)(@typespec/xml@0.72.1) - '@typespec/compiler': 1.2.1(@types/node@20.14.15) + '@azure-tools/typespec-azure-core': 0.59.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/rest@0.73.0) + '@azure-tools/typespec-azure-resource-manager': 0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/openapi@1.3.0)(@typespec/rest@0.73.0)(@typespec/versioning@0.73.0) + '@azure-tools/typespec-client-generator-core': 0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/openapi@1.3.0)(@typespec/rest@0.73.0)(@typespec/streams@0.73.0)(@typespec/versioning@0.73.0)(@typespec/xml@0.73.0) + '@typespec/compiler': 1.3.0(@types/node@20.14.15) dev: false - /@azure-tools/typespec-client-generator-core@0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/openapi@1.2.1)(@typespec/rest@0.72.1)(@typespec/streams@0.72.1)(@typespec/versioning@0.72.1)(@typespec/xml@0.72.1): - resolution: {integrity: sha512-PK9WjPFXR14hrGyUwhstHuNVC4fkkQeNVHvvYhz3VaP6wh+iD7P3IOeIzzRJv/qSyv82t7BrVXdQAYir434ysw==} + /@azure-tools/typespec-client-generator-core@0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/openapi@1.3.0)(@typespec/rest@0.73.0)(@typespec/streams@0.73.0)(@typespec/versioning@0.73.0)(@typespec/xml@0.73.0): + resolution: {integrity: sha512-5+pVcOr7Uyq4IaZ3oLjLi8jnBuR+t/B8hQF4CZo+goe/uK+WkmDfw1TlY14G2ve7W7v8m9+Sk2nil6bN1uHWEQ==} engines: {node: '>=20.0.0'} peerDependencies: - '@azure-tools/typespec-azure-core': ^0.58.0 - '@typespec/compiler': ^1.2.0 - '@typespec/events': ^0.72.0 - '@typespec/http': ^1.2.0 - '@typespec/openapi': ^1.2.0 - '@typespec/rest': ^0.72.0 - '@typespec/sse': ^0.72.0 - '@typespec/streams': ^0.72.0 - '@typespec/versioning': ^0.72.0 - '@typespec/xml': ^0.72.0 - dependencies: - '@azure-tools/typespec-azure-core': 0.58.0(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/rest@0.72.1) - '@typespec/compiler': 1.2.1(@types/node@20.14.15) - '@typespec/http': 1.2.1(@typespec/compiler@1.2.1)(@typespec/streams@0.72.1) - '@typespec/openapi': 1.2.1(@typespec/compiler@1.2.1)(@typespec/http@1.2.1) - '@typespec/rest': 0.72.1(@typespec/compiler@1.2.1)(@typespec/http@1.2.1) - '@typespec/streams': 0.72.1(@typespec/compiler@1.2.1) - '@typespec/versioning': 0.72.1(@typespec/compiler@1.2.1) - '@typespec/xml': 0.72.1(@typespec/compiler@1.2.1) + '@azure-tools/typespec-azure-core': ^0.59.0 + '@typespec/compiler': ^1.3.0 + '@typespec/events': ^0.73.0 + '@typespec/http': ^1.3.0 + '@typespec/openapi': ^1.3.0 + '@typespec/rest': ^0.73.0 + '@typespec/sse': ^0.73.0 + '@typespec/streams': ^0.73.0 + '@typespec/versioning': ^0.73.0 + '@typespec/xml': ^0.73.0 + dependencies: + '@azure-tools/typespec-azure-core': 0.59.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/rest@0.73.0) + '@typespec/compiler': 1.3.0(@types/node@20.14.15) + '@typespec/http': 1.3.0(@typespec/compiler@1.3.0)(@typespec/streams@0.73.0) + '@typespec/openapi': 1.3.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0) + '@typespec/rest': 0.73.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0) + '@typespec/streams': 0.73.0(@typespec/compiler@1.3.0) + '@typespec/versioning': 0.73.0(@typespec/compiler@1.3.0) + '@typespec/xml': 0.73.0(@typespec/compiler@1.3.0) change-case: 5.4.4 pluralize: 8.0.0 yaml: 2.8.0 @@ -1225,8 +1225,8 @@ packages: eslint-visitor-keys: 3.4.3 dev: false - /@typespec/compiler@1.2.1(@types/node@20.14.15): - resolution: {integrity: sha512-lUdHCRBPtianNN6QKt0G9qyyuSu7azbqKcYNimNLYQwrEIDcgSfQAUnoja9s+gtzCQQRzfbUZ8WLBC2b9cC81Q==} + /@typespec/compiler@1.3.0(@types/node@20.14.15): + resolution: {integrity: sha512-OqpoNP3C2y8riA6C5RofPMvmj9jNiGyyhde0tM2ZE7IBOv7BBaTDqw4CJD22YnC8JEilRfPmvdVCViNrPHEjrA==} engines: {node: '>=20.0.0'} hasBin: true dependencies: @@ -1239,7 +1239,7 @@ packages: is-unicode-supported: 2.1.0 mustache: 4.2.0 picocolors: 1.1.1 - prettier: 3.5.3 + prettier: 3.6.2 semver: 7.7.1 tar: 7.4.3 temporal-polyfill: 0.3.0 @@ -1251,67 +1251,67 @@ packages: - '@types/node' dev: false - /@typespec/http@1.2.1(@typespec/compiler@1.2.1)(@typespec/streams@0.72.1): - resolution: {integrity: sha512-HEPHgVFO2oQL6uZCtpqnRYVZizfSu9BO6vAgdRl1FYJWD2G0f/A4/hK6LEgpyZP44k39M1xMSqVrll2KZ5zpnw==} + /@typespec/http@1.3.0(@typespec/compiler@1.3.0)(@typespec/streams@0.73.0): + resolution: {integrity: sha512-4W3KsmBHZGgECVbvyh7S7KQG06948XyVVzae+UbVDDxoUj/x4Ry0AXw3q4HmzB2BVhxw6JBrwBuVa5mxjVMzdw==} engines: {node: '>=20.0.0'} peerDependencies: - '@typespec/compiler': ^1.2.1 - '@typespec/streams': ^0.72.1 + '@typespec/compiler': ^1.3.0 + '@typespec/streams': ^0.73.0 peerDependenciesMeta: '@typespec/streams': optional: true dependencies: - '@typespec/compiler': 1.2.1(@types/node@20.14.15) - '@typespec/streams': 0.72.1(@typespec/compiler@1.2.1) + '@typespec/compiler': 1.3.0(@types/node@20.14.15) + '@typespec/streams': 0.73.0(@typespec/compiler@1.3.0) dev: false - /@typespec/openapi@1.2.1(@typespec/compiler@1.2.1)(@typespec/http@1.2.1): - resolution: {integrity: sha512-PSoM6c5M7epiFdFDPL4zIJKRPUgJepMtOtO1vVOSIFuz26DcFQpc8xzBy7LBsRneSfp8b6XbsiaNXNcBP/9A1w==} + /@typespec/openapi@1.3.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0): + resolution: {integrity: sha512-BSeshjCZQodVGyVHn7ytcUeIcUGjqbG2Ac0NLOQaaKnISVrhTWNcgo5aFTqxAa24ZL/EuhqlSauLyYce2EV9fw==} engines: {node: '>=20.0.0'} peerDependencies: - '@typespec/compiler': ^1.2.1 - '@typespec/http': ^1.2.1 + '@typespec/compiler': ^1.3.0 + '@typespec/http': ^1.3.0 dependencies: - '@typespec/compiler': 1.2.1(@types/node@20.14.15) - '@typespec/http': 1.2.1(@typespec/compiler@1.2.1)(@typespec/streams@0.72.1) + '@typespec/compiler': 1.3.0(@types/node@20.14.15) + '@typespec/http': 1.3.0(@typespec/compiler@1.3.0)(@typespec/streams@0.73.0) dev: false - /@typespec/rest@0.72.1(@typespec/compiler@1.2.1)(@typespec/http@1.2.1): - resolution: {integrity: sha512-w0C91JhrVos8mAdd3OVwrcS6aSjuKlw7LtoazHenAmou/zSACKZbH4g6ko1BY8fv5lgl+q7VZ3/52uEWHOTxpw==} + /@typespec/rest@0.73.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0): + resolution: {integrity: sha512-28hgFGvreBg34Xuguw+E++pQC/kbRxy1Bpx/9nU7x87Ly6ykns3lpx74gjY9ByE8VYKVbXtC7lzdnp19DRSjIQ==} engines: {node: '>=20.0.0'} peerDependencies: - '@typespec/compiler': ^1.2.1 - '@typespec/http': ^1.2.1 + '@typespec/compiler': ^1.3.0 + '@typespec/http': ^1.3.0 dependencies: - '@typespec/compiler': 1.2.1(@types/node@20.14.15) - '@typespec/http': 1.2.1(@typespec/compiler@1.2.1)(@typespec/streams@0.72.1) + '@typespec/compiler': 1.3.0(@types/node@20.14.15) + '@typespec/http': 1.3.0(@typespec/compiler@1.3.0)(@typespec/streams@0.73.0) dev: false - /@typespec/streams@0.72.1(@typespec/compiler@1.2.1): - resolution: {integrity: sha512-TJdFxpW9lgazOluDdT9N8Ojnb7T/hXMZOL094D2idBf33aeqJvSHZtWgY4po8hTsQLk8Y4m4WJJ70nT9DUEOdg==} + /@typespec/streams@0.73.0(@typespec/compiler@1.3.0): + resolution: {integrity: sha512-pL4xffHXEIhBQKPlB9L4AKuM0bn44WsGKjnz91wa6wBtP/CbsPrGQicof0Z7GPGdddtDi4G8PWGmJtVFw53V9g==} engines: {node: '>=20.0.0'} peerDependencies: - '@typespec/compiler': ^1.2.1 + '@typespec/compiler': ^1.3.0 dependencies: - '@typespec/compiler': 1.2.1(@types/node@20.14.15) + '@typespec/compiler': 1.3.0(@types/node@20.14.15) dev: false - /@typespec/versioning@0.72.1(@typespec/compiler@1.2.1): - resolution: {integrity: sha512-v1tBN2TcJilYpmb67v96YIVCGy8Su/c9hmuU6WABudWnYr26O4O+6gK2zx69RFxXORw+iw/LiDCU3XtFHbb7IQ==} + /@typespec/versioning@0.73.0(@typespec/compiler@1.3.0): + resolution: {integrity: sha512-cfFvzTsvsu4VpdwZcRULr3p/fawKZnjiJClQxlLcYW0dLs/5k5jh7l0YyPkYvgkOcncUrIB6hIu82tQhKrMDKQ==} engines: {node: '>=20.0.0'} peerDependencies: - '@typespec/compiler': ^1.2.1 + '@typespec/compiler': ^1.3.0 dependencies: - '@typespec/compiler': 1.2.1(@types/node@20.14.15) + '@typespec/compiler': 1.3.0(@types/node@20.14.15) dev: false - /@typespec/xml@0.72.1(@typespec/compiler@1.2.1): - resolution: {integrity: sha512-CmHXpwOojFT7cRI6ooB682OBIUVP9jMMx5bSoF9nrXg047Quaj7J0qPIwrG7d3O5lkogwPxqtPJPYaVq0+9gfg==} + /@typespec/xml@0.73.0(@typespec/compiler@1.3.0): + resolution: {integrity: sha512-vlMM8/L22O/PbI3ovj3qoww/3Z8wNwn7og4jzlGRM93jZBJvrOeDSwZo1Dc4rMJyU6KfjPkP3/l5TLbgW8x0zA==} engines: {node: '>=20.0.0'} peerDependencies: - '@typespec/compiler': ^1.2.1 + '@typespec/compiler': ^1.3.0 dependencies: - '@typespec/compiler': 1.2.1(@types/node@20.14.15) + '@typespec/compiler': 1.3.0(@types/node@20.14.15) dev: false /@vitest/expect@1.6.1: @@ -2728,8 +2728,8 @@ packages: hasBin: true dev: false - /prettier@3.5.3: - resolution: {integrity: sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==} + /prettier@3.6.2: + resolution: {integrity: sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==} engines: {node: '>=14'} hasBin: true dev: false @@ -3455,24 +3455,24 @@ packages: dev: false file:projects/emitter-test.tgz(@types/node@20.14.15): - resolution: {integrity: sha512-0Im9S9p12TgXnrZlfMK8aQ0/9szDrArGhV+hfZ7GCNh5T/oGbBS98xYvpksjg0wy2m7f6Vzlpuz6GhnawnhCDQ==, tarball: file:projects/emitter-test.tgz} + resolution: {integrity: sha512-CL29bIEtGogkKdBxEqcGWSBY2SgLFe/9xl9vNLQlKS4PXpZTMzlsMDjlPeagN6C0K0Y/U3skHhhg/3Hv80OMyA==, tarball: file:projects/emitter-test.tgz} id: file:projects/emitter-test.tgz name: '@rush-temp/emitter-test' version: 0.0.0 dependencies: - '@azure-tools/typespec-autorest': 0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@azure-tools/typespec-azure-resource-manager@0.58.0)(@azure-tools/typespec-client-generator-core@0.58.0)(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/openapi@1.2.1)(@typespec/rest@0.72.1)(@typespec/versioning@0.72.1) - '@azure-tools/typespec-azure-core': 0.58.0(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/rest@0.72.1) - '@azure-tools/typespec-azure-resource-manager': 0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/openapi@1.2.1)(@typespec/rest@0.72.1)(@typespec/versioning@0.72.1) - '@azure-tools/typespec-azure-rulesets': 0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@azure-tools/typespec-azure-resource-manager@0.58.0)(@azure-tools/typespec-client-generator-core@0.58.0)(@typespec/compiler@1.2.1) - '@azure-tools/typespec-client-generator-core': 0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/openapi@1.2.1)(@typespec/rest@0.72.1)(@typespec/streams@0.72.1)(@typespec/versioning@0.72.1)(@typespec/xml@0.72.1) + '@azure-tools/typespec-autorest': 0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@azure-tools/typespec-azure-resource-manager@0.59.0)(@azure-tools/typespec-client-generator-core@0.59.0)(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/openapi@1.3.0)(@typespec/rest@0.73.0)(@typespec/versioning@0.73.0) + '@azure-tools/typespec-azure-core': 0.59.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/rest@0.73.0) + '@azure-tools/typespec-azure-resource-manager': 0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/openapi@1.3.0)(@typespec/rest@0.73.0)(@typespec/versioning@0.73.0) + '@azure-tools/typespec-azure-rulesets': 0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@azure-tools/typespec-azure-resource-manager@0.59.0)(@azure-tools/typespec-client-generator-core@0.59.0)(@typespec/compiler@1.3.0) + '@azure-tools/typespec-client-generator-core': 0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/openapi@1.3.0)(@typespec/rest@0.73.0)(@typespec/streams@0.73.0)(@typespec/versioning@0.73.0)(@typespec/xml@0.73.0) '@azure-tools/typespec-liftr-base': 0.8.0 - '@typespec/compiler': 1.2.1(@types/node@20.14.15) - '@typespec/http': 1.2.1(@typespec/compiler@1.2.1)(@typespec/streams@0.72.1) - '@typespec/openapi': 1.2.1(@typespec/compiler@1.2.1)(@typespec/http@1.2.1) - '@typespec/rest': 0.72.1(@typespec/compiler@1.2.1)(@typespec/http@1.2.1) - '@typespec/streams': 0.72.1(@typespec/compiler@1.2.1) - '@typespec/versioning': 0.72.1(@typespec/compiler@1.2.1) - '@typespec/xml': 0.72.1(@typespec/compiler@1.2.1) + '@typespec/compiler': 1.3.0(@types/node@20.14.15) + '@typespec/http': 1.3.0(@typespec/compiler@1.3.0)(@typespec/streams@0.73.0) + '@typespec/openapi': 1.3.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0) + '@typespec/rest': 0.73.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0) + '@typespec/streams': 0.73.0(@typespec/compiler@1.3.0) + '@typespec/versioning': 0.73.0(@typespec/compiler@1.3.0) + '@typespec/xml': 0.73.0(@typespec/compiler@1.3.0) transitivePeerDependencies: - '@types/node' - '@typespec/events' @@ -3513,7 +3513,7 @@ packages: dev: false file:projects/typespec-powershell.tgz: - resolution: {integrity: sha512-rL/J1FaxmtT/EuV9PiHJ0BMGNx/vNw1Bjds9rOcDy4aTIkHQlzolPNuvhY1HFBdUASGFVhrMe4uWhTRMyaMQzQ==, tarball: file:projects/typespec-powershell.tgz} + resolution: {integrity: sha512-iKN5CelTfSpOWo1MiDccOMEV1V51Y+uuJxQHR1aqqxAoMK7/6EpSiWgBnB27dY1ppgb+3Zq2csno22ELq0CIBw==, tarball: file:projects/typespec-powershell.tgz} name: '@rush-temp/typespec-powershell' version: 0.0.0 dependencies: @@ -3526,10 +3526,10 @@ packages: '@azure-tools/codemodel-v3': 3.1.266 '@azure-tools/linq': 3.1.263 '@azure-tools/tasks': 3.0.255 - '@azure-tools/typespec-azure-core': 0.58.0(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/rest@0.72.1) - '@azure-tools/typespec-azure-resource-manager': 0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/openapi@1.2.1)(@typespec/rest@0.72.1)(@typespec/versioning@0.72.1) - '@azure-tools/typespec-azure-rulesets': 0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@azure-tools/typespec-azure-resource-manager@0.58.0)(@azure-tools/typespec-client-generator-core@0.58.0)(@typespec/compiler@1.2.1) - '@azure-tools/typespec-client-generator-core': 0.58.0(@azure-tools/typespec-azure-core@0.58.0)(@typespec/compiler@1.2.1)(@typespec/http@1.2.1)(@typespec/openapi@1.2.1)(@typespec/rest@0.72.1)(@typespec/streams@0.72.1)(@typespec/versioning@0.72.1)(@typespec/xml@0.72.1) + '@azure-tools/typespec-azure-core': 0.59.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/rest@0.73.0) + '@azure-tools/typespec-azure-resource-manager': 0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/openapi@1.3.0)(@typespec/rest@0.73.0)(@typespec/versioning@0.73.0) + '@azure-tools/typespec-azure-rulesets': 0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@azure-tools/typespec-azure-resource-manager@0.59.0)(@azure-tools/typespec-client-generator-core@0.59.0)(@typespec/compiler@1.3.0) + '@azure-tools/typespec-client-generator-core': 0.59.0(@azure-tools/typespec-azure-core@0.59.0)(@typespec/compiler@1.3.0)(@typespec/http@1.3.0)(@typespec/openapi@1.3.0)(@typespec/rest@0.73.0)(@typespec/streams@0.73.0)(@typespec/versioning@0.73.0)(@typespec/xml@0.73.0) '@testdeck/mocha': 0.3.3 '@types/js-yaml': 3.12.1 '@types/mocha': 5.2.5 @@ -3537,13 +3537,13 @@ packages: '@types/xmlbuilder': 0.0.34 '@typescript-eslint/eslint-plugin': 5.62.0(@typescript-eslint/parser@5.62.0)(eslint@8.12.0)(typescript@5.1.6) '@typescript-eslint/parser': 5.62.0(eslint@8.12.0)(typescript@5.1.6) - '@typespec/compiler': 1.2.1(@types/node@20.14.15) - '@typespec/http': 1.2.1(@typespec/compiler@1.2.1)(@typespec/streams@0.72.1) - '@typespec/openapi': 1.2.1(@typespec/compiler@1.2.1)(@typespec/http@1.2.1) - '@typespec/rest': 0.72.1(@typespec/compiler@1.2.1)(@typespec/http@1.2.1) - '@typespec/streams': 0.72.1(@typespec/compiler@1.2.1) - '@typespec/versioning': 0.72.1(@typespec/compiler@1.2.1) - '@typespec/xml': 0.72.1(@typespec/compiler@1.2.1) + '@typespec/compiler': 1.3.0(@types/node@20.14.15) + '@typespec/http': 1.3.0(@typespec/compiler@1.3.0)(@typespec/streams@0.73.0) + '@typespec/openapi': 1.3.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0) + '@typespec/rest': 0.73.0(@typespec/compiler@1.3.0)(@typespec/http@1.3.0) + '@typespec/streams': 0.73.0(@typespec/compiler@1.3.0) + '@typespec/versioning': 0.73.0(@typespec/compiler@1.3.0) + '@typespec/xml': 0.73.0(@typespec/compiler@1.3.0) ejs: 3.1.10 eslint: 8.12.0 js-yaml: 3.13.1 diff --git a/packages/typespec-powershell/package.json b/packages/typespec-powershell/package.json index 4a5efa14d24..a4f55c2972e 100644 --- a/packages/typespec-powershell/package.json +++ b/packages/typespec-powershell/package.json @@ -44,17 +44,17 @@ "vitest": "1.6.1" }, "peerDependencies": { - "@azure-tools/typespec-azure-core": ">=0.58.0 <1.0.0", - "@azure-tools/typespec-client-generator-core": ">=0.58.0 <1.0.0", - "@typespec/compiler": ">=1.2.1 <2.0.0", - "@typespec/http": ">=1.2.1 <2.0.0", + "@azure-tools/typespec-azure-core": ">=0.59.0 <1.0.0", + "@azure-tools/typespec-client-generator-core": ">=0.59.0 <1.0.0", + "@typespec/compiler": ">=1.3.0 <2.0.0", + "@typespec/http": ">=1.3.0 <2.0.0", "@typespec/streams": ">=0.72.1 <1.0.0", "@typespec/xml": ">=0.72.1 <1.0.0", "@typespec/rest": ">=0.72.1 <1.0.0", "@typespec/versioning": ">=0.72.1 <1.0.0", - "@typespec/openapi": ">=1.2.1 <2.0.0", - "@azure-tools/typespec-azure-resource-manager": ">=0.58.0 <1.0.0", - "@azure-tools/typespec-azure-rulesets": ">=0.58.0 <1.0.0" + "@typespec/openapi": ">=1.3.0 <2.0.0", + "@azure-tools/typespec-azure-resource-manager": ">=0.59.0 <1.0.0", + "@azure-tools/typespec-azure-rulesets": ">=0.59.0 <1.0.0" }, "scripts": { "build": "tsc", diff --git a/packages/typespec-powershell/src/convertor/convertor.ts b/packages/typespec-powershell/src/convertor/convertor.ts index c5d8669be55..408c926b20f 100644 --- a/packages/typespec-powershell/src/convertor/convertor.ts +++ b/packages/typespec-powershell/src/convertor/convertor.ts @@ -15,8 +15,7 @@ import { camelCase, deconstruct, pascalCase, serialize } from "@azure-tools/code import { PSOptions } from "../types/interfaces.js"; import { Request, ImplementationLocation, OperationGroup, Operation, Parameter, Schema, Protocol, Response, HttpHeader } from "@autorest/codemodel"; import { stat } from "fs"; -import { extractPagedMetadataNested } from "../utils/operationUtil.js"; -import { parseNextLinkName } from "../utils/operationUtil.js"; +import { extractPageDetails } from "../utils/operationUtil.js"; import { getLroMetadata } from "@azure-tools/typespec-azure-core"; import { getOperationId } from "@typespec/openapi"; import { listOperations } from "../utils/clientUtils.js"; @@ -264,14 +263,13 @@ function addOperation(psContext: SdkContext, op: HttpOperation, operationGroup: function addExtensions(psContext: SdkContext, op: HttpOperation, newOperation: Operation, model: PwshModel) { // Add extensions for pageable - const paged = extractPagedMetadataNested(psContext.program, op.responses[0].type as Model); - if (paged) { + const pagedDetail = extractPageDetails(psContext.program, op); + if (pagedDetail) { newOperation.extensions = newOperation.extensions || {}; - //ToDo: add value if it is specified by xiaogang newOperation.extensions['x-ms-pageable'] = newOperation.extensions['x-ms-pageable'] || {}; - newOperation.extensions['x-ms-pageable']['nextLinkName'] = parseNextLinkName(paged) ?? "nextLink"; + newOperation.extensions['x-ms-pageable']['nextLinkName'] = pagedDetail.nextLinkNames[0] ?? "nextLink"; newOperation.language.default.paging = newOperation.language.default.paging || {}; - newOperation.language.default.paging.nextLinkName = parseNextLinkName(paged) ?? "nextLink"; + newOperation.language.default.paging.nextLinkName = pagedDetail.nextLinkNames[0] ?? "nextLink"; } // Add extensions for long running operation const lro = getLroMetadata(psContext.program, op.operation); diff --git a/packages/typespec-powershell/src/utils/modelUtils.ts b/packages/typespec-powershell/src/utils/modelUtils.ts index 0a45a2d47a7..aaca20e21a4 100644 --- a/packages/typespec-powershell/src/utils/modelUtils.ts +++ b/packages/typespec-powershell/src/utils/modelUtils.ts @@ -60,7 +60,7 @@ import { createMetadataInfo, Visibility } from "@typespec/http"; -import { getPagedResult, isFixed, getUnionAsEnum } from "@azure-tools/typespec-azure-core"; +import { getPagedResult, getUnionAsEnum } from "@azure-tools/typespec-azure-core"; import { extractPagedMetadataNested } from "./operationUtil.js"; import { pascalCase, deconstruct } from "@azure-tools/codegen"; import { diff --git a/packages/typespec-powershell/src/utils/operationUtil.ts b/packages/typespec-powershell/src/utils/operationUtil.ts index 2c6c6ac730c..7563a1ec17f 100644 --- a/packages/typespec-powershell/src/utils/operationUtil.ts +++ b/packages/typespec-powershell/src/utils/operationUtil.ts @@ -12,7 +12,9 @@ // } from "@azure-tools/rlc-common"; import { ignoreDiagnostics, + isList, Model, + ModelProperty, Operation, Program, Type @@ -37,6 +39,7 @@ import { SdkContext } from "@azure-tools/typespec-client-generator-core"; import { listOperations } from "./clientUtils.js"; +import { $ } from "@typespec/compiler/typekit"; // import { // OperationLroDetail, // OPERATION_LRO_LOW_PRIORITY, @@ -324,13 +327,49 @@ export function hasPollingOperations( } export function isPagingOperation(program: Program, operation: HttpOperation) { - for (const response of operation.responses) { - const paged = extractPagedMetadataNested(program, response.type as Model); - if (paged) { - return true; + return extractPageDetails(program, operation) !== undefined; +} + +function mapFirstSegmentForResultSegments( + resultSegments: ModelProperty[] | undefined, + responses: HttpOperationResponse[] +): ModelProperty[] | undefined { + const pagingBodyType = responses.find((r) => r.statusCodes === 200) + ?.responses[0]?.body; + if (!pagingBodyType || pagingBodyType.bodyKind !== "single") return undefined; + const bodyType = pagingBodyType.type; + + if (resultSegments === undefined || bodyType === undefined) return undefined; + // TCGC use Http response type as the return type + // For implicit body response, we need to locate the first segment in the response type + // Several cases: + // 1. `op test(): {items, nextLink}` + // 2. `op test(): {items, nextLink} & {a, b, c}` + // 3. `op test(): {@bodyRoot body: {items, nextLink}}` + + if (resultSegments.length > 0 && bodyType && bodyType.kind === "Model") { + for (let i = 0; i < resultSegments.length; i++) { + const segment = resultSegments[i]; + for (const property of bodyType.properties ?? []) { + if ( + property && + segment && + findRootSourceProperty(property[1]) === + findRootSourceProperty(segment) + ) { + return [property[1], ...resultSegments.slice(i + 1)]; + } + } } } - return false; + return resultSegments; +} + +function findRootSourceProperty(property: ModelProperty): ModelProperty { + while (property.sourceProperty) { + property = property.sourceProperty; + } + return property; } export function hasPagingOperations( @@ -525,3 +564,60 @@ export function parseItemName(paged: PagedResultMetadata): string | undefined { // TODO: support the nested item names return (paged.itemsSegments ?? [])[0]; } + +export interface PageDetails { + nextLinkNames: string[]; + itemNames: string[]; +} + +export function extractPageDetails( + program: Program, + operation: HttpOperation +): PageDetails | undefined { + if (isList(program, operation.operation)) { + // If the operation is a list, we don't need to extract paging details. + const metadata = $(program).operation.getPagingMetadata( + operation.operation + ); + if (metadata === undefined) { + // would fallback to default paging metadata + return undefined; + } + const nextLinkPath = mapFirstSegmentForResultSegments( + metadata?.output.nextLink?.path, + operation.responses + ); + const itemNamePath = mapFirstSegmentForResultSegments( + metadata?.output.pageItems?.path, + operation.responses + ); + if ( + (nextLinkPath && nextLinkPath?.length > 1) || + (itemNamePath && itemNamePath?.length > 1) + ) { + return undefined; + } + const nextLinkNames = + nextLinkPath?.map((prop) => prop.name).join(".") ?? "nextLink"; + const itemNames = + itemNamePath?.map((prop) => prop.name).join(".") ?? "value"; + return { + nextLinkNames: [nextLinkNames], + itemNames: [itemNames] + }; + } else { + // TODO: remember to remove this once Azure Paging is removed. + for (const response of operation.responses) { + const paged = extractPagedMetadataNested(program, response.type as Model); + if (paged) { + const nextLinkName = parseNextLinkName(paged) ?? "nextLink"; + const itemName = parseItemName(paged) ?? "value"; + return { + nextLinkNames: [nextLinkName], + itemNames: [itemName] + }; + } + } + } + return undefined; +} diff --git a/tests-upgrade/tests-emitter/Microsoft.DevOpsInfrastructure.Management/main.tsp b/tests-upgrade/tests-emitter/Microsoft.DevOpsInfrastructure.Management/main.tsp index a61e479ea6d..9f40a1341e7 100644 --- a/tests-upgrade/tests-emitter/Microsoft.DevOpsInfrastructure.Management/main.tsp +++ b/tests-upgrade/tests-emitter/Microsoft.DevOpsInfrastructure.Management/main.tsp @@ -710,6 +710,7 @@ interface SubscriptionUsages { @get @armResourceList(Location) @doc("List Quota resources by subscription ID") + @list usages( ...SubscriptionIdParameter, ...Azure.ResourceManager.Foundations.DefaultProviderNamespace, diff --git a/tests-upgrade/tests-emitter/Sphere.Management/catalog.tsp b/tests-upgrade/tests-emitter/Sphere.Management/catalog.tsp index 4b0da842fcf..6874212d063 100644 --- a/tests-upgrade/tests-emitter/Sphere.Management/catalog.tsp +++ b/tests-upgrade/tests-emitter/Sphere.Management/catalog.tsp @@ -70,6 +70,7 @@ interface Catalogs { /** * Lists deployments for catalog. */ + @list listDeployments is ArmResourceActionSync< Catalog, void, @@ -86,6 +87,7 @@ interface Catalogs { /** * List the device groups for the catalog. */ + @list listDeviceGroups is ArmResourceActionSync< Catalog, ListDeviceGroupsRequest, @@ -102,6 +104,7 @@ interface Catalogs { /** * Lists device insights for catalog. */ + @list listDeviceInsights is ArmResourceActionSync< Catalog, void, @@ -118,6 +121,7 @@ interface Catalogs { /** * Lists devices for catalog. */ + @list listDevices is ArmResourceActionSync< Catalog, void, diff --git a/tests-upgrade/tests-emitter/Sphere.Management/product.tsp b/tests-upgrade/tests-emitter/Sphere.Management/product.tsp index 2e23dc2f542..9292ea69616 100644 --- a/tests-upgrade/tests-emitter/Sphere.Management/product.tsp +++ b/tests-upgrade/tests-emitter/Sphere.Management/product.tsp @@ -70,6 +70,7 @@ interface Products { /** * Generates default device groups for the product. '.default' and '.unassigned' are system defined values and cannot be used for product name. */ + @list generateDefaultDeviceGroups is ArmResourceActionSync< Product, void, diff --git a/tests-upgrade/tests-emitter/package.json b/tests-upgrade/tests-emitter/package.json index 523d6dcadc8..991441ff754 100644 --- a/tests-upgrade/tests-emitter/package.json +++ b/tests-upgrade/tests-emitter/package.json @@ -3,18 +3,18 @@ "version": "0.1.0", "type": "module", "dependencies": { - "@typespec/compiler": "1.2.1", - "@azure-tools/typespec-autorest": "0.58.0", - "@azure-tools/typespec-azure-core": "0.58.0", - "@azure-tools/typespec-azure-resource-manager": "0.58.0", - "@azure-tools/typespec-client-generator-core": "0.58.0", - "@azure-tools/typespec-azure-rulesets": "0.58.0", - "@typespec/http": "1.2.1", - "@typespec/openapi": "1.2.1", - "@typespec/rest": "0.72.1", - "@typespec/streams": "0.72.1", - "@typespec/versioning": "0.72.1", - "@typespec/xml": "0.72.1", + "@typespec/compiler": "1.3.0", + "@azure-tools/typespec-autorest": "0.59.0", + "@azure-tools/typespec-azure-core": "0.59.0", + "@azure-tools/typespec-azure-resource-manager": "0.59.0", + "@azure-tools/typespec-client-generator-core": "0.59.0", + "@azure-tools/typespec-azure-rulesets": "0.59.0", + "@typespec/http": "1.3.0", + "@typespec/openapi": "1.3.0", + "@typespec/rest": "0.73.0", + "@typespec/streams": "0.73.0", + "@typespec/versioning": "0.73.0", + "@typespec/xml": "0.73.0", "@azure-tools/typespec-liftr-base": "0.8.0" }, "scripts": {