From 093e98620a616a31ce5d43857d9b3a758c36fc72 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Thu, 12 Dec 2024 17:20:33 +0800 Subject: [PATCH] http-client-java, map typespec.rest.resource model to sdk base namespace (#5349) Also update package name to json classes. https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/clientcore/core/src/main/java/io/clientcore/core/serialization/json --- .../emitter/src/code-model-builder.ts | 46 +++++++++++-------- .../model/clientmodel/ExternalPackage.java | 2 +- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/packages/http-client-java/emitter/src/code-model-builder.ts b/packages/http-client-java/emitter/src/code-model-builder.ts index 279be70a54..b1d967337a 100644 --- a/packages/http-client-java/emitter/src/code-model-builder.ts +++ b/packages/http-client-java/emitter/src/code-model-builder.ts @@ -2537,25 +2537,33 @@ export class CodeModelBuilder { // clientNamespace from TCGC const clientNamespace: string | undefined = type?.clientNamespace; - if (this.isBranded() && type) { - // special handling for namespace of model that cannot be mapped to azure-core - if (type.crossLanguageDefinitionId === "TypeSpec.Http.File") { - // TypeSpec.Http.File - return this.baseJavaNamespace; - } else if (type.crossLanguageDefinitionId === "Azure.Core.Foundations.OperationState") { - // Azure.Core.OperationState - return this.baseJavaNamespace; - } else if ( - type.crossLanguageDefinitionId === "Azure.Core.ResourceOperationStatus" || - type.crossLanguageDefinitionId === "Azure.Core.Foundations.OperationStatus" - ) { - // Azure.Core.ResourceOperationStatus<> - // Azure.Core.Foundations.OperationStatus<> - // usually this model will not be generated, but javadoc of protocol method requires it be in SDK namespace - return this.baseJavaNamespace; - } else if (type.crossLanguageDefinitionId.startsWith("Azure.ResourceManager.")) { - // models in Azure.ResourceManager - return this.baseJavaNamespace; + if (type) { + if (this.isBranded()) { + // special handling for namespace of model that cannot be mapped to azure-core + if (type.crossLanguageDefinitionId === "TypeSpec.Http.File") { + // TypeSpec.Http.File + return this.baseJavaNamespace; + } else if (type.crossLanguageDefinitionId === "Azure.Core.Foundations.OperationState") { + // Azure.Core.OperationState + return this.baseJavaNamespace; + } else if ( + type.crossLanguageDefinitionId === "Azure.Core.ResourceOperationStatus" || + type.crossLanguageDefinitionId === "Azure.Core.Foundations.OperationStatus" + ) { + // Azure.Core.ResourceOperationStatus<> + // Azure.Core.Foundations.OperationStatus<> + // usually this model will not be generated, but javadoc of protocol method requires it be in SDK namespace + return this.baseJavaNamespace; + } else if (type.crossLanguageDefinitionId.startsWith("Azure.ResourceManager.")) { + // models in Azure.ResourceManager + return this.baseJavaNamespace; + } + } else { + // special handling for namespace of model in TypeSpec.Rest.Resource + if (type.crossLanguageDefinitionId.startsWith("TypeSpec.Rest.Resource.")) { + // models in TypeSpec.Rest.Resource + return this.baseJavaNamespace; + } } } diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ExternalPackage.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ExternalPackage.java index 278c615f90..d8e1f15566 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ExternalPackage.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ExternalPackage.java @@ -8,7 +8,7 @@ public class ExternalPackage { public static final String CLIENTCORE_PACKAGE_NAME = "io.clientcore.core"; - public static final String CLIENTCORE_JSON_PACKAGE_NAME = "io.clientcore.core.json"; + public static final String CLIENTCORE_JSON_PACKAGE_NAME = "io.clientcore.core.serialization.json"; public static final String AZURE_CORE_PACKAGE_NAME = "com.azure.core"; public static final String AZURE_JSON_PACKAGE_NAME = "com.azure.json";