diff --git a/sdk/servicebus/azure-resourcemanager-servicebus/customization/pom.xml b/sdk/servicebus/azure-resourcemanager-servicebus/customization/pom.xml new file mode 100644 index 000000000000..1e02a1fb33ff --- /dev/null +++ b/sdk/servicebus/azure-resourcemanager-servicebus/customization/pom.xml @@ -0,0 +1,17 @@ + + + + + com.azure + azure-code-customization-parent + 1.0.0-beta.1 + ../../../parents/azure-code-customization-parent + + + com.azure.resourcemanager + azure-resourcemanager-servicebus-customization + 1.0.0-beta.1 + 4.0.0 + \ No newline at end of file diff --git a/sdk/servicebus/azure-resourcemanager-servicebus/customization/src/main/java/ServiceBusCustomization.java b/sdk/servicebus/azure-resourcemanager-servicebus/customization/src/main/java/ServiceBusCustomization.java new file mode 100644 index 000000000000..21726e881831 --- /dev/null +++ b/sdk/servicebus/azure-resourcemanager-servicebus/customization/src/main/java/ServiceBusCustomization.java @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +import com.azure.autorest.customization.ClassCustomization; +import com.azure.autorest.customization.Customization; +import com.azure.autorest.customization.LibraryCustomization; +import com.azure.autorest.customization.PackageCustomization; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import org.slf4j.Logger; + +/** + * Code customization after code generation. + */ +public class ServiceBusCustomization extends Customization { + @Override + public void customize(LibraryCustomization customization, Logger logger) { + PackageCustomization fluentModelsPackage = customization.getPackage("com.azure.resourcemanager.servicebus.fluent.models"); + // change base class from `ProxyResource` to `Resource`, to avoid breaking changes and compilation errors + customizeResourceBaseClass(fluentModelsPackage.getClass("SBTopicInner")); + customizeResourceBaseClass(fluentModelsPackage.getClass("SBSubscriptionInner")); + customizeResourceBaseClass(fluentModelsPackage.getClass("SBQueueInner")); + customizeResourceBaseClass(fluentModelsPackage.getClass("SBAuthorizationRuleInner")); + } + + /** + * Customize the base class to be "com.azure.core.management.Resource". + * + * @param customization the customization for class + */ + private static void customizeResourceBaseClass(ClassCustomization customization) { + customization.customizeAst(ast -> { + ast.getClassByName(customization.getClassName()).ifPresent(clazz -> { + String resourceClassName = "com.azure.core.management.Resource"; + ast.addImport(resourceClassName); + clazz.getExtendedTypes().clear(); + clazz.addExtendedType(new ClassOrInterfaceType(null, "Resource")); + }); + }); + } +} \ No newline at end of file