diff --git a/fluentgen/src/main/java/com/azure/autorest/fluent/mapper/FluentMapper.java b/fluentgen/src/main/java/com/azure/autorest/fluent/mapper/FluentMapper.java index 1e1d89facd..3f227e0d01 100644 --- a/fluentgen/src/main/java/com/azure/autorest/fluent/mapper/FluentMapper.java +++ b/fluentgen/src/main/java/com/azure/autorest/fluent/mapper/FluentMapper.java @@ -26,6 +26,7 @@ import com.azure.autorest.fluent.util.Utils; import com.azure.autorest.mapper.Mappers; import com.azure.autorest.model.clientmodel.Client; +import com.azure.autorest.model.clientmodel.ClientModels; import com.azure.autorest.model.clientmodel.ModuleInfo; import org.slf4j.Logger; @@ -123,7 +124,10 @@ public FluentClient map(CodeModel codeModel, Client client) { FluentClient basicMap(CodeModel codeModel, Client client) { FluentClient fluentClient = new FluentClient(client); - fluentClient.setModuleInfo(moduleInfo()); + final String implementationModelsPackage = JavaSettings.getInstance().getImplementationSubpackage() + "." + JavaSettings.getInstance().getModelsSubpackage(); + final boolean hasImplementationModels = ClientModels.getInstance().getModels().stream() + .anyMatch(m -> m.getPackage().endsWith(implementationModelsPackage)); + fluentClient.setModuleInfo(getModuleInfo(hasImplementationModels)); FluentStatic.setFluentClient(fluentClient); @@ -153,7 +157,7 @@ FluentClient basicMap(CodeModel codeModel, Client client) { return fluentClient; } - private static ModuleInfo moduleInfo() { + private static ModuleInfo getModuleInfo(boolean hasImplementationModels) { JavaSettings settings = JavaSettings.getInstance(); ModuleInfo moduleInfo = new ModuleInfo(settings.getPackage()); @@ -170,6 +174,9 @@ private static ModuleInfo moduleInfo() { List openModules = moduleInfo.getOpenModules(); openModules.add(new ModuleInfo.OpenModule(settings.getPackage(settings.getFluentModelsSubpackage()), openToModules)); openModules.add(new ModuleInfo.OpenModule(settings.getPackage(settings.getModelsSubpackage()), openToModules)); + if (hasImplementationModels) { + openModules.add(new ModuleInfo.OpenModule(settings.getPackage(settings.getImplementationSubpackage(), settings.getModelsSubpackage()), openToModules)); + } return moduleInfo; } diff --git a/javagen/src/main/java/com/azure/autorest/mapper/ObjectMapper.java b/javagen/src/main/java/com/azure/autorest/mapper/ObjectMapper.java index c53cf923e3..943a39eea0 100644 --- a/javagen/src/main/java/com/azure/autorest/mapper/ObjectMapper.java +++ b/javagen/src/main/java/com/azure/autorest/mapper/ObjectMapper.java @@ -55,11 +55,15 @@ private ClassType createClassType(ObjectSchema compositeType) { } else if (settings.isFluent() && compositeType.isFlattenedSchema()) { // put class of flattened type to implementation package classPackage = settings.getPackage(settings.getFluentModelsSubpackage()); - } else if (settings.isDataPlaneClient() && (isPageModel(compositeType) || isInternalModel(compositeType))) { + } else if (settings.isDataPlaneClient() && isInternalModel(compositeType)) { + // internal type is not exposed to user + classPackage = settings.getPackage(settings.getImplementationSubpackage(), settings.getModelsSubpackage()); + } else if (isPageModel(compositeType)) { // put class of Page<> type to implementation package - // For TypeSpec, these are not generated to class + // for DPG from TypeSpec, these are not generated to class + + // this would not affect mgmt from Swagger, as the "usage" from m4 does not have this information. - // same for internal type, which is not exposed to user classPackage = settings.getPackage(settings.getImplementationSubpackage(), settings.getModelsSubpackage()); } else { classPackage = settings.getPackage(settings.getModelsSubpackage()); diff --git a/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/ChildResourcesInterfacesClientImpl.java b/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/ChildResourcesInterfacesClientImpl.java index 653144cad1..89893f5975 100644 --- a/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/ChildResourcesInterfacesClientImpl.java +++ b/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/ChildResourcesInterfacesClientImpl.java @@ -35,7 +35,7 @@ import com.azure.core.util.polling.SyncPoller; import com.cadl.armresourceprovider.fluent.ChildResourcesInterfacesClient; import com.cadl.armresourceprovider.fluent.models.ChildResourceInner; -import com.cadl.armresourceprovider.models.ChildResourceListResult; +import com.cadl.armresourceprovider.implementation.models.ChildResourceListResult; import com.cadl.armresourceprovider.models.ChildResourceUpdate; import java.nio.ByteBuffer; import reactor.core.publisher.Flux; diff --git a/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/OperationsClientImpl.java b/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/OperationsClientImpl.java index 12d43bc83f..20cb8374f6 100644 --- a/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/OperationsClientImpl.java +++ b/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/OperationsClientImpl.java @@ -27,7 +27,7 @@ import com.azure.core.util.FluxUtil; import com.cadl.armresourceprovider.fluent.OperationsClient; import com.cadl.armresourceprovider.fluent.models.OperationInner; -import com.cadl.armresourceprovider.models.PagedOperation; +import com.cadl.armresourceprovider.implementation.models.PagedOperation; import reactor.core.publisher.Mono; /** diff --git a/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/TopLevelArmResourceInterfacesClientImpl.java b/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/TopLevelArmResourceInterfacesClientImpl.java index 9e74504679..80fb111599 100644 --- a/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/TopLevelArmResourceInterfacesClientImpl.java +++ b/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/TopLevelArmResourceInterfacesClientImpl.java @@ -34,7 +34,7 @@ import com.azure.core.util.polling.SyncPoller; import com.cadl.armresourceprovider.fluent.TopLevelArmResourceInterfacesClient; import com.cadl.armresourceprovider.fluent.models.TopLevelArmResourceInner; -import com.cadl.armresourceprovider.models.TopLevelArmResourceListResult; +import com.cadl.armresourceprovider.implementation.models.TopLevelArmResourceListResult; import com.cadl.armresourceprovider.models.TopLevelArmResourceUpdate; import java.nio.ByteBuffer; import reactor.core.publisher.Flux; diff --git a/typespec-tests/src/main/java/com/cadl/armresourceprovider/models/ChildResourceListResult.java b/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/models/ChildResourceListResult.java similarity index 97% rename from typespec-tests/src/main/java/com/cadl/armresourceprovider/models/ChildResourceListResult.java rename to typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/models/ChildResourceListResult.java index 41c366b2e2..32b207be3b 100644 --- a/typespec-tests/src/main/java/com/cadl/armresourceprovider/models/ChildResourceListResult.java +++ b/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/models/ChildResourceListResult.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) TypeSpec Code Generator. -package com.cadl.armresourceprovider.models; +package com.cadl.armresourceprovider.implementation.models; import com.azure.core.annotation.Fluent; import com.azure.core.util.logging.ClientLogger; diff --git a/typespec-tests/src/main/java/com/cadl/armresourceprovider/models/PagedOperation.java b/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/models/PagedOperation.java similarity index 97% rename from typespec-tests/src/main/java/com/cadl/armresourceprovider/models/PagedOperation.java rename to typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/models/PagedOperation.java index ef27dc1180..74f0cb5643 100644 --- a/typespec-tests/src/main/java/com/cadl/armresourceprovider/models/PagedOperation.java +++ b/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/models/PagedOperation.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) TypeSpec Code Generator. -package com.cadl.armresourceprovider.models; +package com.cadl.armresourceprovider.implementation.models; import com.azure.core.annotation.Fluent; import com.azure.core.util.logging.ClientLogger; diff --git a/typespec-tests/src/main/java/com/cadl/armresourceprovider/models/TopLevelArmResourceListResult.java b/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/models/TopLevelArmResourceListResult.java similarity index 97% rename from typespec-tests/src/main/java/com/cadl/armresourceprovider/models/TopLevelArmResourceListResult.java rename to typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/models/TopLevelArmResourceListResult.java index 984b94e217..20dfd2402d 100644 --- a/typespec-tests/src/main/java/com/cadl/armresourceprovider/models/TopLevelArmResourceListResult.java +++ b/typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/models/TopLevelArmResourceListResult.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) TypeSpec Code Generator. -package com.cadl.armresourceprovider.models; +package com.cadl.armresourceprovider.implementation.models; import com.azure.core.annotation.Fluent; import com.azure.core.util.logging.ClientLogger; diff --git a/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armresourceprovider-generated/reflect-config.json b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armresourceprovider-generated/reflect-config.json index 0a16be2b89..b0255c524d 100644 --- a/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armresourceprovider-generated/reflect-config.json +++ b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armresourceprovider-generated/reflect-config.json @@ -14,7 +14,7 @@ "allDeclaredFields" : true, "allDeclaredMethods" : true }, { - "name" : "com.cadl.armresourceprovider.models.ChildResourceListResult", + "name" : "com.cadl.armresourceprovider.implementation.models.ChildResourceListResult", "allDeclaredConstructors" : true, "allDeclaredFields" : true, "allDeclaredMethods" : true @@ -39,7 +39,7 @@ "allDeclaredFields" : true, "allDeclaredMethods" : true }, { - "name" : "com.cadl.armresourceprovider.models.TopLevelArmResourceListResult", + "name" : "com.cadl.armresourceprovider.implementation.models.TopLevelArmResourceListResult", "allDeclaredConstructors" : true, "allDeclaredFields" : true, "allDeclaredMethods" : true @@ -69,7 +69,7 @@ "allDeclaredFields" : true, "allDeclaredMethods" : true }, { - "name" : "com.cadl.armresourceprovider.models.PagedOperation", + "name" : "com.cadl.armresourceprovider.implementation.models.PagedOperation", "allDeclaredConstructors" : true, "allDeclaredFields" : true, "allDeclaredMethods" : true