diff --git a/.chronus/changes/enable-java-arm-resource-identifier-test-2026-08-17-11-23-00.md b/.chronus/changes/enable-java-arm-resource-identifier-test-2026-08-17-11-23-00.md new file mode 100644 index 0000000000..6390de117e --- /dev/null +++ b/.chronus/changes/enable-java-arm-resource-identifier-test-2026-08-17-11-23-00.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - "@azure-tools/typespec-java" +--- + +Re-enable the ARM resource identifier emitter test. diff --git a/.chronus/changes/fix-typespec-java-remove-model-2026-08-17.md b/.chronus/changes/fix-typespec-java-remove-model-2026-08-17.md new file mode 100644 index 0000000000..f2c45c5ddd --- /dev/null +++ b/.chronus/changes/fix-typespec-java-remove-model-2026-08-17.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-java" +--- + +Sync core to microsoft/typespec commit `1a1583554b`. Fix management generation to omit models and enums configured with `remove-model` (core [#11698](https://github.com/microsoft/typespec/pull/11698)). diff --git a/packages/typespec-java/CHANGELOG.md b/packages/typespec-java/CHANGELOG.md index 76122839a4..415a478e10 100644 --- a/packages/typespec-java/CHANGELOG.md +++ b/packages/typespec-java/CHANGELOG.md @@ -1,10 +1,23 @@ # Change Log - @azure-tools/typespec-java +## 0.46.0 + +### Features + +- Sync core to microsoft/typespec commit `27b39b71b`. Support removing models from management clients with the `remove-model` emitter option (core [#11658](https://github.com/microsoft/typespec/pull/11658)). + +### Bug Fixes + +- Fix Fluent Premium samples to use the correct service client for resource metadata suffixes (core [#11633](https://github.com/microsoft/typespec/pull/11633)). +- Preserve existing properties files for applicable libraries during SDK integration (core [#11635](https://github.com/microsoft/typespec/pull/11635)). +- Document response headers in protocol API Javadocs (core [#11610](https://github.com/microsoft/typespec/pull/11610)). + + ## 0.45.13 ### Features -- [#5138](https://github.com/Azure/typespec-azure/pull/5138) Sync core to microsoft/typespec commit `2e1649b83`. Includes support for nested property paths and XML payloads in Azure pageable responses (core [#11504](https://github.com/microsoft/typespec/pull/11504)). +- Sync core to microsoft/typespec commit `2e1649b83`. Includes support for nested property paths and XML payloads in Azure pageable responses (core [#11504](https://github.com/microsoft/typespec/pull/11504)). ## 0.45.12 diff --git a/packages/typespec-java/core-commit.json b/packages/typespec-java/core-commit.json index aac7d0b42c..92a3c43c89 100644 --- a/packages/typespec-java/core-commit.json +++ b/packages/typespec-java/core-commit.json @@ -1 +1 @@ -{ "sha": "fbd68c68652b13a5c2a0c6e2375f06fdcb09d370" } +{ "sha": "1a1583554b6b3b9b98155002f10e696d1c1ffa85" } diff --git a/packages/typespec-java/core.test.patch b/packages/typespec-java/core.test.patch index 70d7865529..a068d96d2d 100644 --- a/packages/typespec-java/core.test.patch +++ b/packages/typespec-java/core.test.patch @@ -16,17 +16,3 @@ index f002da96..fae8d01b 100644 } public static byte[] getJpgBytes() { -diff --git a/src/test/java/azure/resourcemanager/commonproperties/CommonPropertiesTests.java b/src/test/java/azure/resourcemanager/commonproperties/CommonPropertiesTests.java ---- a/src/test/java/azure/resourcemanager/commonproperties/CommonPropertiesTests.java -+++ b/src/test/java/azure/resourcemanager/commonproperties/CommonPropertiesTests.java -@@ -18,5 +18,6 @@ import com.azure.core.management.exception.ManagementException; - import java.util.HashMap; - import java.util.Map; - import org.junit.jupiter.api.Assertions; -+import org.junit.jupiter.api.Disabled; - import org.junit.jupiter.api.Test; - import org.utils.ArmUtils; -@@ -98,2 +99,3 @@ public class CommonPropertiesTests { - @Test -+ @Disabled("Requires an unreleased azure-http-specs ARM resource identifier feature") - public void testArmResourceIdentifiers() { diff --git a/packages/typespec-java/emitter-tests/spector.config.yaml b/packages/typespec-java/emitter-tests/spector.config.yaml index d2ba4d4003..d99af6ebcb 100644 --- a/packages/typespec-java/emitter-tests/spector.config.yaml +++ b/packages/typespec-java/emitter-tests/spector.config.yaml @@ -54,6 +54,7 @@ specs: azure/resource-manager/operation-templates: { options: { generate-tests: false } } azure/resource-manager/resources: { options: { generate-tests: false } } azure/resource-manager/service-group: { options: { generate-tests: false } } + azure/resource-manager/service-group-extension: true azure/special-headers/client-request-id: true azure/special-headers/conditional-request: true azure/versioning/previewVersion: true diff --git a/packages/typespec-java/emitter-tests/src/test/java/azure/clientgenerator/core/apiversion/clientapiversions/ClientApiVersionsTests.java b/packages/typespec-java/emitter-tests/src/test/java/azure/clientgenerator/core/apiversion/clientapiversions/ClientApiVersionsTests.java new file mode 100644 index 0000000000..0cc909ce40 --- /dev/null +++ b/packages/typespec-java/emitter-tests/src/test/java/azure/clientgenerator/core/apiversion/clientapiversions/ClientApiVersionsTests.java @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package azure.clientgenerator.core.apiversion.clientapiversions; + +import org.junit.jupiter.api.Test; + +public class ClientApiVersionsTests { + + @Test + public void sendExtendedClientApiVersion() { + ClientApiVersionsClient client + = new ClientApiVersionsClientBuilder().serviceVersion(ClientApiVersionsServiceVersion.V2022_10_01) + .buildClient(); + + client.sendApiVersion(); + } +} diff --git a/packages/typespec-java/emitter-tests/src/test/java/azure/resourcemanager/commonproperties/CommonPropertiesTests.java b/packages/typespec-java/emitter-tests/src/test/java/azure/resourcemanager/commonproperties/CommonPropertiesTests.java index c3427b10b1..7174a21b6e 100644 --- a/packages/typespec-java/emitter-tests/src/test/java/azure/resourcemanager/commonproperties/CommonPropertiesTests.java +++ b/packages/typespec-java/emitter-tests/src/test/java/azure/resourcemanager/commonproperties/CommonPropertiesTests.java @@ -18,7 +18,6 @@ import java.util.HashMap; import java.util.Map; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.utils.ArmUtils; @@ -97,7 +96,6 @@ public void testError() { } @Test - @Disabled("Requires an unreleased azure-http-specs ARM resource identifier feature") public void testArmResourceIdentifiers() { final String subscriptionId = "00000000-0000-0000-0000-000000000000"; final String resourceGroup = "test-rg"; @@ -105,6 +103,9 @@ public void testArmResourceIdentifiers() { + "/providers/Microsoft.Network/virtualNetworks/myVnet"; final String armIdWithAllScopes = "/subscriptions/" + subscriptionId + "/resourceGroups/" + resourceGroup + "/providers/Microsoft.Compute/virtualMachines/myVm"; + final String armIdWithGroupScope + = "/providers/Microsoft.Management/serviceGroups/test-sg/providers/Microsoft.Authorization/roleDefinitions/" + + "00000000-0000-0000-0000-000000000000"; // Create ArmResourceIdentifierResource resource = manager.armResourceIdentifiers() @@ -114,7 +115,8 @@ public void testArmResourceIdentifiers() { .withProperties(new ArmResourceIdentifierResourceProperties().withSimpleArmId(simpleArmId) .withArmIdWithType(simpleArmId) .withArmIdWithTypeAndScope(simpleArmId) - .withArmIdWithAllScopes(armIdWithAllScopes)) + .withArmIdWithAllScopes(armIdWithAllScopes) + .withArmIdWithGroupScope(armIdWithGroupScope)) .create(); Assertions.assertNotNull(resource); Assertions.assertEquals("armId", resource.name()); @@ -124,6 +126,7 @@ public void testArmResourceIdentifiers() { Assertions.assertEquals(simpleArmId, resource.properties().armIdWithType()); Assertions.assertEquals(simpleArmId, resource.properties().armIdWithTypeAndScope()); Assertions.assertEquals(armIdWithAllScopes, resource.properties().armIdWithAllScopes()); + Assertions.assertEquals(armIdWithGroupScope, resource.properties().armIdWithGroupScope()); // Get resource = manager.armResourceIdentifiers().getByResourceGroup(resourceGroup, "armId"); @@ -132,6 +135,9 @@ public void testArmResourceIdentifiers() { Assertions.assertNotNull(resource.properties()); Assertions.assertEquals(ResourceProvisioningState.SUCCEEDED, resource.properties().provisioningState()); Assertions.assertEquals(simpleArmId, resource.properties().simpleArmId()); + Assertions.assertEquals(simpleArmId, resource.properties().armIdWithType()); + Assertions.assertEquals(simpleArmId, resource.properties().armIdWithTypeAndScope()); Assertions.assertEquals(armIdWithAllScopes, resource.properties().armIdWithAllScopes()); + Assertions.assertEquals(armIdWithGroupScope, resource.properties().armIdWithGroupScope()); } } diff --git a/packages/typespec-java/emitter-tests/src/test/java/azure/resourcemanager/operationtemplates/OperationTests.java b/packages/typespec-java/emitter-tests/src/test/java/azure/resourcemanager/operationtemplates/OperationTests.java index dbc75280f6..60fed46cb9 100644 --- a/packages/typespec-java/emitter-tests/src/test/java/azure/resourcemanager/operationtemplates/OperationTests.java +++ b/packages/typespec-java/emitter-tests/src/test/java/azure/resourcemanager/operationtemplates/OperationTests.java @@ -3,6 +3,7 @@ package azure.resourcemanager.operationtemplates; +import azure.resourcemanager.operationtemplates.fluent.models.ConfigurationInner; import azure.resourcemanager.operationtemplates.fluent.models.WidgetInner; import azure.resourcemanager.operationtemplates.models.ActionRequest; import azure.resourcemanager.operationtemplates.models.ActionResult; @@ -12,8 +13,14 @@ import azure.resourcemanager.operationtemplates.models.CheckNameAvailabilityReason; import azure.resourcemanager.operationtemplates.models.CheckNameAvailabilityRequest; import azure.resourcemanager.operationtemplates.models.CheckNameAvailabilityResponse; +import azure.resourcemanager.operationtemplates.models.Collection; +import azure.resourcemanager.operationtemplates.models.Configuration; +import azure.resourcemanager.operationtemplates.models.ConfigurationProperties; +import azure.resourcemanager.operationtemplates.models.DiagnosticInfo; import azure.resourcemanager.operationtemplates.models.ExportRequest; import azure.resourcemanager.operationtemplates.models.ExportResult; +import azure.resourcemanager.operationtemplates.models.LogStatusRequest; +import azure.resourcemanager.operationtemplates.models.MonitoredResource; import azure.resourcemanager.operationtemplates.models.Operation; import azure.resourcemanager.operationtemplates.models.OperationDisplay; import azure.resourcemanager.operationtemplates.models.Order; @@ -167,6 +174,64 @@ public void testExportArray() { Assertions.assertEquals("order2,product2,2", result2.content()); } + @Test + public void testLegacyRoutedGet() { + DiagnosticInfo diagnostic = manager.legacies().routedGet("test-rg", "default", "memory"); + + Assertions.assertEquals("memory", diagnostic.name()); + Assertions.assertEquals("healthy", diagnostic.status()); + } + + @Test + public void testLegacyCreateWithBody() { + Configuration configuration = manager.legacies() + .define("default") + .withRegion(Region.US_EAST) + .withExistingResourceGroup("test-rg") + .withProperties(new ConfigurationProperties().withConfigValue("custom-value")) + .create(); + + Assertions.assertEquals("default", configuration.name()); + Assertions.assertEquals("eastus", configuration.location()); + Assertions.assertEquals("custom-value", configuration.properties().configValue()); + Assertions.assertEquals("Succeeded", configuration.properties().provisioningState()); + } + + @Test + public void testLegacyCreateWithoutBody() { + ConfigurationInner configuration + = manager.serviceClient().getLegacies().createOrReplaceOptionalBody("test-rg", "default"); + + Assertions.assertEquals("default", configuration.name()); + Assertions.assertEquals("eastus", configuration.location()); + Assertions.assertEquals("default-value", configuration.properties().configValue()); + Assertions.assertEquals("Succeeded", configuration.properties().provisioningState()); + } + + @Test + public void testPostActionPaging() { + List resources = manager.pagings() + .postActionPaging("test-rg", "monitor1", new LogStatusRequest().withFilter("status eq 'active'"), + Context.NONE) + .stream() + .collect(Collectors.toList()); + + Assertions.assertTrue(resources.get(0).id().endsWith("/virtualMachines/vm1")); + Assertions.assertTrue(resources.get(0).sendingMetrics()); + } + + @Test + public void testMarkAsPageable() { + List collections + = manager.pagings().markAsPageable("test-rg", "monitor1").stream().collect(Collectors.toList()); + + Assertions.assertEquals(2, collections.size()); + Assertions.assertEquals("collection1", collections.get(0).name()); + Assertions.assertEquals("Test Collection", collections.get(0).properties().displayName()); + Assertions.assertEquals("collection2", collections.get(1).name()); + Assertions.assertEquals("Another Collection", collections.get(1).properties().displayName()); + } + // for LRO operations, we need to override default poll interval private static OperationTemplatesManager buildManager() { try { diff --git a/packages/typespec-java/emitter-tests/src/test/java/azure/resourcemanager/servicegroupextension/ServiceGroupExtensionTests.java b/packages/typespec-java/emitter-tests/src/test/java/azure/resourcemanager/servicegroupextension/ServiceGroupExtensionTests.java new file mode 100644 index 0000000000..8b0f1b0d33 --- /dev/null +++ b/packages/typespec-java/emitter-tests/src/test/java/azure/resourcemanager/servicegroupextension/ServiceGroupExtensionTests.java @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package azure.resourcemanager.servicegroupextension; + +import azure.resourcemanager.servicegroupextension.fluent.models.ServiceGroupExtensionResourceInner; +import azure.resourcemanager.servicegroupextension.models.ProvisioningState; +import azure.resourcemanager.servicegroupextension.models.ServiceGroupExtensionResource; +import azure.resourcemanager.servicegroupextension.models.ServiceGroupExtensionResourceProperties; +import java.util.List; +import java.util.stream.Collectors; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.utils.ArmUtils; + +public class ServiceGroupExtensionTests { + + private static final String SERVICE_GROUP_ID = "test-sg"; + private static final String RESOURCE_NAME = "resource"; + private static final String RESOURCE_TYPE = "Microsoft.ServiceGroupExtension/serviceGroupExtensionResources"; + + private final ServiceGroupExtensionManager manager + = ServiceGroupExtensionManager.authenticate(ArmUtils.createTestHttpPipeline(), ArmUtils.getAzureProfile()); + + @Test + public void testGet() { + assertResource(manager.serviceGroupExtensionResources().get(SERVICE_GROUP_ID, RESOURCE_NAME), "valid"); + } + + @Test + public void testCreateOrUpdate() { + ServiceGroupExtensionResource resource = manager.serviceGroupExtensionResources() + .createOrUpdate(SERVICE_GROUP_ID, RESOURCE_NAME, createResource("valid")); + + assertResource(resource, "valid"); + } + + @Test + public void testUpdate() { + ServiceGroupExtensionResource resource = manager.serviceGroupExtensionResources() + .update(SERVICE_GROUP_ID, RESOURCE_NAME, createResource("valid2")); + + assertResource(resource, "valid2"); + } + + @Test + public void testDelete() { + manager.serviceGroupExtensionResources().deleteByResourceGroup(SERVICE_GROUP_ID, RESOURCE_NAME); + } + + @Test + public void testListByServiceGroup() { + List resources = manager.serviceGroupExtensionResources() + .listByServiceGroup(SERVICE_GROUP_ID) + .stream() + .collect(Collectors.toList()); + + Assertions.assertEquals(1, resources.size()); + assertResource(resources.get(0), "valid"); + } + + private static ServiceGroupExtensionResourceInner createResource(String description) { + return new ServiceGroupExtensionResourceInner() + .withProperties(new ServiceGroupExtensionResourceProperties().withDescription(description)); + } + + private static void assertResource(ServiceGroupExtensionResource resource, String description) { + Assertions.assertNotNull(resource); + Assertions.assertEquals(RESOURCE_NAME, resource.name()); + Assertions.assertEquals(RESOURCE_TYPE, resource.type()); + Assertions.assertNotNull(resource.properties()); + Assertions.assertEquals(description, resource.properties().description()); + Assertions.assertEquals(ProvisioningState.SUCCEEDED, resource.properties().provisioningState()); + } +} diff --git a/packages/typespec-java/eng/scripts/generate.ts b/packages/typespec-java/eng/scripts/generate.ts index 845285264e..a10183f5e0 100644 --- a/packages/typespec-java/eng/scripts/generate.ts +++ b/packages/typespec-java/eng/scripts/generate.ts @@ -110,7 +110,7 @@ async function compile(typeSpecFile: string, options: string[], timeout: number) const command = `pnpm ${arguments_.join(" ")}`; const start = performance.now(); const result = await execa("pnpm", arguments_, { - cwd: emitterTestsRoot, + cwd: packageRoot, reject: false, timeout, }); diff --git a/packages/typespec-java/package.json b/packages/typespec-java/package.json index 7a1dc5c77e..544c5275ef 100644 --- a/packages/typespec-java/package.json +++ b/packages/typespec-java/package.json @@ -1,6 +1,6 @@ { "name": "@azure-tools/typespec-java", - "version": "0.45.13", + "version": "0.46.0", "description": "TypeSpec library for emitting Java client from the TypeSpec REST protocol binding", "keywords": [ "TypeSpec" diff --git a/packages/typespec-java/src/options.ts b/packages/typespec-java/src/options.ts index 4148a540e3..e95c822cbb 100644 --- a/packages/typespec-java/src/options.ts +++ b/packages/typespec-java/src/options.ts @@ -174,6 +174,13 @@ export const EmitterOptionsSchema: JSONSchemaType = { // items: { type: "string" }, // nullable: true, // }, + // "remove-model": { + // type: ["string", "array"], + // description: + // "Do not generate the model classes. Format should be in array form. This option is for management-plane SDK.", + // items: { type: "string" }, + // nullable: true, + // }, // "preserve-model": { // type: ["string", "array"], // description: