diff --git a/.chronus/changes/azhang_RemoveAzureResource-2024-6-3-12-45-15.md b/.chronus/changes/azhang_RemoveAzureResource-2024-6-3-12-45-15.md new file mode 100644 index 0000000000..e1855108c4 --- /dev/null +++ b/.chronus/changes/azhang_RemoveAzureResource-2024-6-3-12-45-15.md @@ -0,0 +1,8 @@ +--- +changeKind: feature +packages: + - "@azure-tools/typespec-autorest" + - "@azure-tools/typespec-azure-resource-manager" +--- + +Removed direct reference to OpenAPI extension `x-ms-azure-resource` in ARM library and replaced with `@Azure.ResourceManager.Private.azureResourceBase` decorator. It is only used internally on base resource types. `autorest` emitter has been updated to check the decorator and still emit `x-ms-azure-resource` extension in swagger. diff --git a/packages/samples/common-types/src/types.tsp b/packages/samples/common-types/src/types.tsp index 853ab46349..a5f7a68350 100644 --- a/packages/samples/common-types/src/types.tsp +++ b/packages/samples/common-types/src/types.tsp @@ -20,3 +20,6 @@ op registerParams( ): void; @@extension(ErrorDetail.details, "x-ms-identifiers", ["message", "target"]); + +@@extension(Resource, "x-ms-azure-resource", true); +@@extension(ResourceModelWithAllowedPropertySet, "x-ms-azure-resource", true); diff --git a/packages/typespec-autorest/src/openapi.ts b/packages/typespec-autorest/src/openapi.ts index df257b3d38..52c1d06557 100644 --- a/packages/typespec-autorest/src/openapi.ts +++ b/packages/typespec-autorest/src/openapi.ts @@ -13,6 +13,7 @@ import { import { getArmCommonTypeOpenAPIRef, isArmCommonType, + isAzureResource, } from "@azure-tools/typespec-azure-resource-manager"; import { shouldFlattenProperty } from "@azure-tools/typespec-client-generator-core"; import { @@ -1854,6 +1855,9 @@ export async function getOpenAPIForService( function attachExtensions(type: Type, emitObject: any) { // Attach any OpenAPI extensions const extensions = getExtensions(program, type); + if (isAzureResource(program, type as Model)) { + emitObject["x-ms-azure-resource"] = true; + } if (getAsEmbeddingVector(program, type as Model) !== undefined) { emitObject["x-ms-embedding-vector"] = true; } diff --git a/packages/typespec-autorest/test/arm/resources.test.ts b/packages/typespec-autorest/test/arm/resources.test.ts index e71ade9be9..78783de801 100644 --- a/packages/typespec-autorest/test/arm/resources.test.ts +++ b/packages/typespec-autorest/test/arm/resources.test.ts @@ -307,3 +307,18 @@ it("emits a scalar string with decorator parameter for resource", async () => { type: "string", }); }); + +it("emits x-ms-azure-resource for resource with @azureResourceBase", async () => { + const openApi = await openApiFor(` + @armProviderNamespace + @useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1) + namespace Microsoft.Contoso; + + @doc("Widget resource") + @Azure.ResourceManager.Private.azureResourceBase + model Widget { + name: string; + } +`); + ok(openApi.definitions.Widget["x-ms-azure-resource"]); +}); diff --git a/packages/typespec-azure-resource-manager/CHANGELOG.md b/packages/typespec-azure-resource-manager/CHANGELOG.md index fa32d04822..35e4ac2d81 100644 --- a/packages/typespec-azure-resource-manager/CHANGELOG.md +++ b/packages/typespec-azure-resource-manager/CHANGELOG.md @@ -19,14 +19,12 @@ - [#811](https://github.com/Azure/typespec-azure/pull/811) Remove dependency on `typespec-autorest` emitter - [#432](https://github.com/Azure/typespec-azure/pull/432) Add support for values - ## 0.42.1 ### Bug Fixes - [#868](https://github.com/Azure/typespec-azure/pull/868) Changing back `ManagedServiceIdentity.userAssignedIdentities` back to `Record