From 95268e17df0d1728e1db71fed63e9a248d2c0df3 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Thu, 25 Jan 2024 12:50:00 +0800 Subject: [PATCH] mgmt, support flattenProperty (#2529) --- typespec-extension/changelog.md | 1 + typespec-extension/src/code-model-builder.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/typespec-extension/changelog.md b/typespec-extension/changelog.md index 4e2f06e5b7..96c6aab678 100644 --- a/typespec-extension/changelog.md +++ b/typespec-extension/changelog.md @@ -5,6 +5,7 @@ Compatible with compiler 0.52. - Supported `@clientName` from "@azure-tools/typespec-client-generator-core". +- Supported `@flattenProperty` from "@azure-tools/typespec-client-generator-core". ## 0.12.3 (2024-01-22) diff --git a/typespec-extension/src/code-model-builder.ts b/typespec-extension/src/code-model-builder.ts index 70b7218d2b..e35ea1ad93 100644 --- a/typespec-extension/src/code-model-builder.ts +++ b/typespec-extension/src/code-model-builder.ts @@ -72,6 +72,7 @@ import { SdkClient, getCrossLanguageDefinitionId, getClientNameOverride, + shouldFlattenProperty, } from "@azure-tools/typespec-client-generator-core"; import { fail } from "assert"; import { @@ -2277,14 +2278,17 @@ export class CodeModelBuilder { const schema = this.processSchema(prop, prop.name); let nullable = isNullableType(prop.type); - let extensions = undefined; + let extensions: Record | undefined = undefined; if (this.isSecret(prop)) { - extensions = { - "x-ms-secret": true, - }; + extensions = extensions ?? {}; + extensions["x-ms-secret"] = true; // if the property does not return in response, it had to be nullable nullable = true; } + if (shouldFlattenProperty(this.sdkContext, prop)) { + extensions = extensions ?? {}; + extensions["x-ms-client-flatten"] = true; + } return new Property(this.getName(prop), this.getDoc(prop), schema, { summary: this.getSummary(prop),