diff --git a/packages/azure-http-specs/CHANGELOG.md b/packages/azure-http-specs/CHANGELOG.md index 37f60cd9ac..90d151acb4 100644 --- a/packages/azure-http-specs/CHANGELOG.md +++ b/packages/azure-http-specs/CHANGELOG.md @@ -1,5 +1,12 @@ # @azure-tools/azure-http-specs +## 0.1.0-alpha.36 + +### Bug Fixes + +- [#3770](https://github.com/Azure/typespec-azure/pull/3770) Fix missing api-version in nextLink of lropaging test scenario. + + ## 0.1.0-alpha.35 ### Features diff --git a/packages/azure-http-specs/package.json b/packages/azure-http-specs/package.json index a5073a24ee..cff6101fda 100644 --- a/packages/azure-http-specs/package.json +++ b/packages/azure-http-specs/package.json @@ -1,6 +1,6 @@ { "name": "@azure-tools/azure-http-specs", - "version": "0.1.0-alpha.35", + "version": "0.1.0-alpha.36", "description": "Azure Spec scenarios and mock apis", "main": "dist/index.js", "type": "module", diff --git a/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts index fa2bfcd250..4a623cc3fb 100644 --- a/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts +++ b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts @@ -722,7 +722,7 @@ Scenarios.Azure_ResourceManager_OperationTemplates_LroPaging_postPagingLro = pas if (postPagingLroPollCount > 0) { const response = { ...validProductListResult, - nextLink: `${req.baseUrl}/subscriptions/${SUBSCRIPTION_ID_EXPECTED}/providers/Azure.ResourceManager.OperationTemplates/locations/eastus/operations/lro_paging_post_location/nextPage`, + nextLink: `${req.baseUrl}/subscriptions/${SUBSCRIPTION_ID_EXPECTED}/providers/Azure.ResourceManager.OperationTemplates/locations/eastus/operations/lro_paging_post_location/nextPage?api-version=2023-12-01-preview`, }; return { status: 200, diff --git a/packages/typespec-client-generator-core/CHANGELOG.md b/packages/typespec-client-generator-core/CHANGELOG.md index f119b3f1e3..a0b74cd156 100644 --- a/packages/typespec-client-generator-core/CHANGELOG.md +++ b/packages/typespec-client-generator-core/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log - @azure-tools/typespec-client-generator-core +## 0.64.1 + +### Bug Fixes + +- [#3767](https://github.com/Azure/typespec-azure/pull/3767) Fix enum type exclusion in protocol methods when `@convenientAPI(false)`. +- [#3768](https://github.com/Azure/typespec-azure/pull/3768) Refine diagnostic for LRO and paging metadata generation. + + ## 0.64.0 ### Features diff --git a/packages/typespec-client-generator-core/package.json b/packages/typespec-client-generator-core/package.json index a4114085d9..b19a40281a 100644 --- a/packages/typespec-client-generator-core/package.json +++ b/packages/typespec-client-generator-core/package.json @@ -1,6 +1,6 @@ { "name": "@azure-tools/typespec-client-generator-core", - "version": "0.64.0", + "version": "0.64.1", "author": "Microsoft Corporation", "description": "TypeSpec Data Plane Generation library", "homepage": "https://azure.github.io/typespec-azure", diff --git a/packages/typespec-client-generator-core/src/methods.ts b/packages/typespec-client-generator-core/src/methods.ts index a9e0421417..9f9b490996 100644 --- a/packages/typespec-client-generator-core/src/methods.ts +++ b/packages/typespec-client-generator-core/src/methods.ts @@ -268,7 +268,7 @@ function getSdkPagingServiceMethod { } }); }); + +describe("@convenientAPI(false) with enum parameters", () => { + it("enum in query parameter should have Input usage even with convenientAPI(false)", async () => { + await runner.compile(` + @service + namespace TestService { + enum IncludeEnum { + file_search_call_results: "file_search_call.results", + web_search_call_results: "web_search_call.results", + } + + model ItemResult { + id: string; + content: string; + } + + @route("/conversations/{conversation_id}/items/{item_id}") + @convenientAPI(false) + op getConversationItem( + @path conversation_id: string, + @path item_id: string, + @query(#{explode: true}) include?: IncludeEnum[], + ): ItemResult; + } + `); + + const sdkPackage = runner.context.sdkPackage; + ok(sdkPackage.enums); + const includeEnum = sdkPackage.enums.find((e) => e.name === "IncludeEnum"); + ok(includeEnum, "IncludeEnum should be in the enums list"); + ok( + includeEnum.usage & UsageFlags.Input, + "IncludeEnum should have Input usage even with convenientAPI(false)", + ); + }); + + it("enum in header parameter should have Input usage even with convenientAPI(false)", async () => { + await runner.compile(` + @service + namespace TestService { + enum StatusEnum { + active: "active", + inactive: "inactive", + } + + model Response { + data: string; + } + + @route("/data") + @convenientAPI(false) + op getData( + @header status: StatusEnum, + ): Response; + } + `); + + const sdkPackage = runner.context.sdkPackage; + ok(sdkPackage.enums); + const statusEnum = sdkPackage.enums.find((e) => e.name === "StatusEnum"); + ok(statusEnum, "StatusEnum should be in the enums list"); + ok( + statusEnum.usage & UsageFlags.Input, + "StatusEnum should have Input usage even with convenientAPI(false)", + ); + }); + + it("enum in path parameter should have Input usage even with convenientAPI(false)", async () => { + await runner.compile(` + @service + namespace TestService { + enum ResourceType { + users: "users", + groups: "groups", + } + + model Resource { + id: string; + } + + @route("/resources/{type}/{id}") + @convenientAPI(false) + op getResource( + @path type: ResourceType, + @path id: string, + ): Resource; + } + `); + + const sdkPackage = runner.context.sdkPackage; + ok(sdkPackage.enums); + const resourceType = sdkPackage.enums.find((e) => e.name === "ResourceType"); + ok(resourceType, "ResourceType should be in the enums list"); + ok( + resourceType.usage & UsageFlags.Input, + "ResourceType should have Input usage even with convenientAPI(false)", + ); + }); +}); diff --git a/packages/typespec-client-generator-core/test/methods/lro.test.ts b/packages/typespec-client-generator-core/test/methods/lro.test.ts index 5f0c9be4de..055c322910 100644 --- a/packages/typespec-client-generator-core/test/methods/lro.test.ts +++ b/packages/typespec-client-generator-core/test/methods/lro.test.ts @@ -1235,3 +1235,71 @@ describe("getLroMetadata", () => { ); }); }); + +it("versioned LRO with customization", async () => { + const runnerWithCore = await createSdkTestRunner({ + librariesToAdd: [AzureCoreTestLibrary], + autoUsings: ["Azure.Core", "Azure.Core.Traits"], + emitterName: "@azure-tools/typespec-java", + }); + await runnerWithCore.compileWithCustomization( + ` + @service + @versioned(Versions) + namespace TestService; + + enum Versions { + v1, + v2, + } + + alias TestOperations = ResourceOperations; + + @resource("id") + model TestResult { + @key + id: string; + + @lroStatus + status: JobStatus; + } + + @lroStatus + union JobStatus { + string, + NotStarted: "notStarted", + Running: "running", + + @lroSucceeded + Succeeded: "succeeded", + + @lroFailed + Failed: "failed", + + Canceled: "canceled", + } + + @get + op get is TestOperations.ResourceRead; + + @pollingOperation(get) + op create is TestOperations.LongRunningResourceCreateOrReplace; + `, + ` + @client({ + service: TestService, + }) + namespace TestClient; + + op test is TestService.create; + `, + ); + strictEqual(runnerWithCore.context.diagnostics.length, 0); + const client = runnerWithCore.context.sdkPackage.clients[0]; + strictEqual(client.methods.length, 1); + const method = client.methods[0]; + strictEqual(method.name, "test"); + strictEqual(method.kind, "lro"); + const lroMetadata = method.lroMetadata; + ok(lroMetadata); +});