From 1e9855f1b4457a39d0f53946ff9b51d62c85dc9f Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Tue, 20 Feb 2024 16:09:22 -0500 Subject: [PATCH 1/5] Remove pass discriminator to children setting --- Generate.ps1 | 8 +++---- .../extension/base/plugin/JavaSettings.java | 9 -------- .../azure/autorest/mapper/ModelMapper.java | 6 ------ .../autorest/template/ModelTemplate.java | 15 +++++-------- .../StreamSerializationModelTemplate.java | 3 +-- readme.md | 1 - .../models/MetricAlertCriteria.java | 21 ++++++++++++++++++- ...tSingleResourceMultipleMetricCriteria.java | 6 +++++- .../models/MetricAlertCriteria.java | 18 ++++++++++++++++ ...tSingleResourceMultipleMetricCriteria.java | 18 ---------------- 10 files changed, 53 insertions(+), 52 deletions(-) diff --git a/Generate.ps1 b/Generate.ps1 index 6e8377425f..baaf0c1cbb 100644 --- a/Generate.ps1 +++ b/Generate.ps1 @@ -85,9 +85,9 @@ $job = @( "$VANILLA_ARGUMENTS --input-file=$SWAGGER_PATH/body-boolean.json --namespace=fixtures.bodyboolean --client-logger", "$VANILLA_ARGUMENTS --input-file=$SWAGGER_PATH/body-boolean.quirks.json --namespace=fixtures.bodyboolean.quirks", "$VANILLA_ARGUMENTS --input-file=$SWAGGER_PATH/body-complex.json --namespace=fixtures.bodycomplex --required-fields-as-ctor-args --client-logger --output-model-immutable --generate-tests", - "$VANILLA_ARGUMENTS --input-file=$SWAGGER_PATH/body-complex.json --namespace=fixtures.streamstyleserialization --enable-sync-stack --stream-style-serialization --client-logger --pass-discriminator-to-child-deserialization", - "$VANILLA_ARGUMENTS --input-file=$SWAGGER_PATH/body-complex.json --namespace=fixtures.streamstyleserializationimmutableoutput --enable-sync-stack --output-model-immutable --stream-style-serialization --client-logger --pass-discriminator-to-child-deserialization", - "$VANILLA_ARGUMENTS --input-file=$SWAGGER_PATH/body-complex.json --namespace=fixtures.streamstyleserializationctorargs --enable-sync-stack --stream-style-serialization --required-fields-as-ctor-args --client-logger --pass-discriminator-to-child-deserialization", + "$VANILLA_ARGUMENTS --input-file=$SWAGGER_PATH/body-complex.json --namespace=fixtures.streamstyleserialization --enable-sync-stack --stream-style-serialization --client-logger", + "$VANILLA_ARGUMENTS --input-file=$SWAGGER_PATH/body-complex.json --namespace=fixtures.streamstyleserializationimmutableoutput --enable-sync-stack --output-model-immutable --stream-style-serialization --client-logger", + "$VANILLA_ARGUMENTS --input-file=$SWAGGER_PATH/body-complex.json --namespace=fixtures.streamstyleserializationctorargs --enable-sync-stack --stream-style-serialization --required-fields-as-ctor-args --client-logger", "$VANILLA_ARGUMENTS --input-file=$SWAGGER_PATH/body-file.json --namespace=fixtures.bodyfile", "$VANILLA_ARGUMENTS --input-file=$SWAGGER_PATH/body-string.json --namespace=fixtures.bodystring --generate-client-interfaces", "$VANILLA_ARGUMENTS --input-file=$SWAGGER_PATH/custom-baseUrl.json --namespace=fixtures.custombaseuri", @@ -139,7 +139,7 @@ $job = @( "$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/discriminator-flattening.json --namespace=fixtures.discriminatorflattening.clientflatten --modelerfour.flatten-models=false --client-flattened-annotation-target=NONE", "$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/client-default-value.json --namespace=fixtures.clientdefaultvalue --modelerfour.flatten-models=false", "$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/discriminator-flattening.json --namespace=fixtures.inheritance.donotpassdiscriminator --stream-style-serialization=false", - "$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/discriminator-flattening.json --namespace=fixtures.inheritance.passdiscriminator --pass-discriminator-to-child-deserialization=true --stream-style-serialization=false", + "$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/discriminator-flattening.json --namespace=fixtures.inheritance.passdiscriminator --stream-style-serialization=false", "$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/client-default-value.json --namespace=fixtures.annotatedgettersandsetters --annotate-getters-and-setters-for-serialization=true", "$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/xml-tag-with-attribute-and-value.json --namespace=fixtures.complexxmltag", "$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/xml-tag-with-attribute-and-value.json --namespace=fixtures.complexstreamstylexmlserialization --stream-style-serialization", diff --git a/extension-base/src/main/java/com/azure/autorest/extension/base/plugin/JavaSettings.java b/extension-base/src/main/java/com/azure/autorest/extension/base/plugin/JavaSettings.java index 05b9317b5f..233ba86126 100644 --- a/extension-base/src/main/java/com/azure/autorest/extension/base/plugin/JavaSettings.java +++ b/extension-base/src/main/java/com/azure/autorest/extension/base/plugin/JavaSettings.java @@ -151,7 +151,6 @@ public static JavaSettings getInstance() { getBooleanValue(host, "generate-tests", false), false, //getBooleanValue(host, "generate-send-request-method", false), getBooleanValue(host, "generate-models", false), - getBooleanValue(host, "pass-discriminator-to-child-deserialization", false), getBooleanValue(host, "annotate-getters-and-setters-for-serialization", false), getStringValue(host, "default-http-exception-type"), getBooleanValue(host, "use-default-http-status-code-to-exception-type-mapping", false), @@ -312,7 +311,6 @@ private JavaSettings(AutorestSettings autorestSettings, boolean generateTests, boolean generateSendRequestMethod, boolean generateModels, - boolean passDiscriminatorToChildDeserialization, boolean annotateGettersAndSettersForSerialization, String defaultHttpExceptionType, boolean useDefaultHttpStatusCodeToExceptionTypeMapping, @@ -404,7 +402,6 @@ private JavaSettings(AutorestSettings autorestSettings, this.generateTests = generateTests; this.generateSendRequestMethod = generateSendRequestMethod; this.generateModels = generateModels; - this.passDiscriminatorToChildDeserialization = passDiscriminatorToChildDeserialization; this.annotateGettersAndSettersForSerialization = annotateGettersAndSettersForSerialization; // Error HTTP status code exception type handling. @@ -997,12 +994,6 @@ public PollingDetails getPollingConfig(String operation) { return pollingConfig.get("default"); } - private final boolean passDiscriminatorToChildDeserialization; - - public boolean isDiscriminatorPassedToChildDeserialization() { - return passDiscriminatorToChildDeserialization; - } - private final boolean annotateGettersAndSettersForSerialization; /** diff --git a/javagen/src/main/java/com/azure/autorest/mapper/ModelMapper.java b/javagen/src/main/java/com/azure/autorest/mapper/ModelMapper.java index 36b42d1aca..c461d4e34f 100644 --- a/javagen/src/main/java/com/azure/autorest/mapper/ModelMapper.java +++ b/javagen/src/main/java/com/azure/autorest/mapper/ModelMapper.java @@ -449,12 +449,6 @@ private ParentSchemaInfo getParentSchemaInfo(ObjectSchema compositeType) { */ protected ClientModelProperty createDiscriminatorProperty(JavaSettings settings, boolean hasChildren, ObjectSchema compositeType, Function annotationArgumentsMapper, String serializedName) { - // Don't create a discriminator property for the model if the discriminator shouldn't be passed to subtype - // deserialization or the model type has children and stream-style serialization isn't being used. - if ((!settings.isDiscriminatorPassedToChildDeserialization() || hasChildren) - && !settings.isStreamStyleSerialization()) { - return null; - } ClientModelProperty discriminatorProperty = Mappers.getModelPropertyMapper() .map(SchemaUtil.getDiscriminatorProperty(compositeType)); diff --git a/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java b/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java index efc6c52b42..cfe644e588 100644 --- a/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java +++ b/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java @@ -103,7 +103,7 @@ public final void write(ClientModel model, JavaFile javaFile) { boolean treatAsXml = model.isUsedInXml(); // Handle adding annotations if the model is polymorphic. - handlePolymorphism(model, hasDerivedModels, settings.isDiscriminatorPassedToChildDeserialization(), javaFile); + handlePolymorphism(model, hasDerivedModels, javaFile); // Add class level annotations for serialization formats such as XML. addClassLevelAnnotations(model, javaFile, settings); @@ -420,12 +420,9 @@ protected List getParentSettersToOverride(ClientModel * * @param model The client model. * @param hasDerivedModels Whether this model has children types. - * @param isDiscriminatorPassedToChildDeserialization Whether the deserialization discriminator, such as - * {@code odata.type}, is passed to children types during deserialization. * @param javaFile The JavaFile being generated. */ - protected void handlePolymorphism(ClientModel model, boolean hasDerivedModels, - boolean isDiscriminatorPassedToChildDeserialization, JavaFile javaFile) { + protected void handlePolymorphism(ClientModel model, boolean hasDerivedModels, JavaFile javaFile) { // Model isn't polymorphic, no work to do here. if (!model.isPolymorphic()) { return; @@ -436,7 +433,7 @@ protected void handlePolymorphism(ClientModel model, boolean hasDerivedModels, // If the discriminator isn't being passed to child models or this model has derived, children, models // include the discriminator property using JsonTypeInfo.As.PROPERTY. Using this will serialize the // property using the property attribute of the annotation instead of looking for a @JsonProperty. - if (!isDiscriminatorPassedToChildDeserialization || hasDerivedModels) { + if (hasDerivedModels) { jsonTypeInfo.append("JsonTypeInfo.As.PROPERTY, property = \""); } else { // Otherwise, serialize the discriminator property with an existing property on the class. @@ -450,10 +447,8 @@ protected void handlePolymorphism(ClientModel model, boolean hasDerivedModels, jsonTypeInfo.append(", defaultImpl = ").append(model.getName()).append(".class"); } - // If the discriminator is passed to child models the discriminator property needs to be set to visible. - if (isDiscriminatorPassedToChildDeserialization) { - jsonTypeInfo.append(", visible = true"); - } + // Discriminator is passed to child models the discriminator property needs to be set to visible. + jsonTypeInfo.append(", visible = true"); javaFile.annotation(jsonTypeInfo.append(")").toString()); javaFile.annotation(String.format("JsonTypeName(\"%1$s\")", model.getSerializedName())); diff --git a/javagen/src/main/java/com/azure/autorest/template/StreamSerializationModelTemplate.java b/javagen/src/main/java/com/azure/autorest/template/StreamSerializationModelTemplate.java index fa2dd79dc9..5f8636a073 100644 --- a/javagen/src/main/java/com/azure/autorest/template/StreamSerializationModelTemplate.java +++ b/javagen/src/main/java/com/azure/autorest/template/StreamSerializationModelTemplate.java @@ -93,8 +93,7 @@ protected void addSerializationImports(Set imports, ClientModel model, J } @Override - protected void handlePolymorphism(ClientModel model, boolean hasDerivedModels, - boolean isDiscriminatorPassedToChildDeserialization, JavaFile javaFile) { + protected void handlePolymorphism(ClientModel model, boolean hasDerivedModels, JavaFile javaFile) { // no-op as stream-style serialization doesn't need to add anything for polymorphic types. } diff --git a/readme.md b/readme.md index 2cc6b06c84..0b04a2c5b2 100644 --- a/readme.md +++ b/readme.md @@ -86,7 +86,6 @@ Settings can be provided on the command line through `--name:value` or in a READ |`--polling`|Configures how to generate long running operations. See [Polling Configuration](#polling-configuration) to see more details on how to use this flag.| |`--service-name`|Service name used in Client class and other documentations. If not provided, service name is deduced from `title` configure (from swagger or readme).| |`--partial-update`|Indicates whether to support partial update for `Client`/`AsyncClient` classes and `ClientBuilder` class.| -|`--pass-discriminator-to-child-deserialization`|Indicates whether the discriminator property is passed to subclass deserialization. Default is false.| |`--default-http-exception-type`|The fully-qualified class name that should be used as the default HTTP exception type. The class must extend from `HttpResponseException`.| |`--use-default-http-status-code-to-exception-type-mapping`|Indicates whether a default HTTP status code to exception mapping should be used if one isn't provided.| |`--http-status-code-to-exception-type-mapping`|The HTTP status code to exception mapping that should be used. All exception types must be fully-qualified and extend from `HttpResponseException`.| diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertCriteria.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertCriteria.java index bc35a57aad..f537199873 100644 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertCriteria.java @@ -9,7 +9,9 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeId; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeName; import java.util.HashMap; @@ -23,7 +25,8 @@ use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "odata\\.type", - defaultImpl = MetricAlertCriteria.class) + defaultImpl = MetricAlertCriteria.class, + visible = true) @JsonTypeName("MetricAlertCriteria") @JsonSubTypes({ @JsonSubTypes.Type( @@ -34,6 +37,13 @@ public class MetricAlertCriteria { private static final Pattern KEY_ESCAPER = Pattern.compile("\\.");; + /* + * specifies the type of the alert criteria. + */ + @JsonTypeId + @JsonProperty(value = "odata\\.type", required = true) + private static final Odatatype odataType; + /* * The rule criteria that defines the conditions of the alert rule. */ @@ -46,6 +56,15 @@ public class MetricAlertCriteria { public MetricAlertCriteria() { } + /** + * Get the odataType property: specifies the type of the alert criteria. + * + * @return the odataType value. + */ + public Odatatype getOdataType() { + return ODATA_TYPE; + } + /** * Get the additionalProperties property: The rule criteria that defines the conditions of the alert rule. * diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java index 619724ba4f..aead407ac0 100644 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java @@ -14,7 +14,11 @@ /** * Specifies the metric alert criteria for a single resource that has multiple metric criteria. */ -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "odata\\.type") +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXISTING_PROPERTY, + property = "odata\\.type", + visible = true) @JsonTypeName("Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria") @JsonFlatten @Fluent diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java index 5ce32f49fd..b51c7be5f6 100644 --- a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java @@ -9,7 +9,9 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeId; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeName; import java.util.HashMap; @@ -35,6 +37,13 @@ public class MetricAlertCriteria { private static final Pattern KEY_ESCAPER = Pattern.compile("\\.");; + /* + * specifies the type of the alert criteria. + */ + @JsonTypeId + @JsonProperty(value = "odata\\.type", required = true) + private static final Odatatype odataType; + /* * The rule criteria that defines the conditions of the alert rule. */ @@ -47,6 +56,15 @@ public class MetricAlertCriteria { public MetricAlertCriteria() { } + /** + * Get the odataType property: specifies the type of the alert criteria. + * + * @return the odataType value. + */ + public Odatatype getOdataType() { + return ODATA_TYPE; + } + /** * Get the additionalProperties property: The rule criteria that defines the conditions of the alert rule. * diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java index 589799262d..3964ab4f76 100644 --- a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java @@ -7,7 +7,6 @@ import com.azure.core.annotation.Fluent; import com.azure.core.annotation.JsonFlatten; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonTypeId; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeName; import java.util.List; @@ -24,14 +23,6 @@ @JsonFlatten @Fluent public class MetricAlertSingleResourceMultipleMetricCriteria extends MetricAlertCriteria { - /* - * specifies the type of the alert criteria. - */ - @JsonTypeId - @JsonProperty(value = "odata\\.type", required = true) - private static final Odatatype ODATA_TYPE - = Odatatype.MICROSOFT_AZURE_MONITOR_SINGLE_RESOURCE_MULTIPLE_METRIC_CRITERIA; - /* * The list of metric criteria for this 'all of' operation. */ @@ -44,15 +35,6 @@ public class MetricAlertSingleResourceMultipleMetricCriteria extends MetricAlert public MetricAlertSingleResourceMultipleMetricCriteria() { } - /** - * Get the odataType property: specifies the type of the alert criteria. - * - * @return the odataType value. - */ - public Odatatype getOdataType() { - return ODATA_TYPE; - } - /** * Get the allOf property: The list of metric criteria for this 'all of' operation. * From a6b6514fb2e2a7738209b8ef69483f9ebe50524e Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Thu, 22 Feb 2024 11:44:01 -0500 Subject: [PATCH 2/5] Small update to maintain discriminator and hide getter --- .../autorest/template/ModelTemplate.java | 25 ++++++++----------- .../models/MetricAlertCriteria.java | 13 ++++++---- ...tSingleResourceMultipleMetricCriteria.java | 1 + .../models/MetricAlertCriteria.java | 13 ++++++---- ...tSingleResourceMultipleMetricCriteria.java | 1 + 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java b/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java index cfe644e588..617b4e44b8 100644 --- a/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java +++ b/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java @@ -169,7 +169,8 @@ public final void write(ClientModel model, JavaFile javaFile) { ? JavaVisibility.Private : JavaVisibility.Public; - if (!property.isPolymorphicDiscriminator() || modelDefinesProperty(model, property)) { + if (!property.isPolymorphicDiscriminator() + || (modelDefinesProperty(model, property) && settings.isStreamStyleSerialization())) { // Only the super most parent model should have the polymorphic discriminator getter. // The child models should use the parent's getter. generateGetterJavadoc(classBlock, model, property); @@ -200,8 +201,9 @@ public final void write(ClientModel model, JavaFile javaFile) { methodBlock -> addSetterMethod(propertyWireType, propertyClientType, property, treatAsXml, methodBlock, settings, ClientModelUtil.isJsonMergePatchModel(model) && settings.isStreamStyleSerialization())); } else { - // If stream-style serialization is being generated, some additional setters may need to be added - // to support read-only properties that aren't included in the constructor. + // If stream-style serialization is being generated or the property is the polymorphic + // discriminator, some additional setters may need to be added to support read-only properties that + // aren't included in the constructor. // Jackson handles this by reflectively setting the value in the parent model, but stream-style // serialization doesn't perform reflective cracking like Jackson Databind does, so it needs a way // to access the readonly property (aka one without a public setter method). @@ -213,7 +215,8 @@ public final void write(ClientModel model, JavaFile javaFile) { boolean notIncludedInConstructor = !ClientModelUtil.includePropertyInConstructor(property, settings); boolean definedByModel = modelDefinesProperty(model, property); - if (streamStyle && hasDerivedTypes && notIncludedInConstructor && definedByModel) { + if (hasDerivedTypes && notIncludedInConstructor && definedByModel + && (settings.isStreamStyleSerialization() || property.isPolymorphicDiscriminator())) { generateSetterJavadoc(classBlock, model, property); classBlock.method(JavaVisibility.PackagePrivate, null, model.getName() + " " + property.getSetterName() + "(" + propertyWireType + " " @@ -610,9 +613,7 @@ private void addProperties(ClientModel model, JavaClass classBlock, JavaSettings addGeneratedAnnotation(classBlock); addFieldAnnotations(model, property, classBlock, settings); - if (property.isPolymorphicDiscriminator() && !settings.isStreamStyleSerialization()) { - classBlock.privateStaticFinalVariable(fieldSignature); - } else if (ClientModelUtil.includePropertyInConstructor(property, settings)) { + if (ClientModelUtil.includePropertyInConstructor(property, settings)) { classBlock.privateFinalMemberVariable(fieldSignature); } else { classBlock.privateMemberVariable(fieldSignature); @@ -824,11 +825,9 @@ private void addModelConstructor(ClientModel model, JavaVisibility constructorVi constructor.line("super(" + superProperties + ");"); } - // If there is a polymorphic discriminator and stream-style serialization is being used, add a line to - // initialize the discriminator. + // If there is a polymorphic discriminator , add a line to initialize the discriminator. ClientModelProperty polymorphicProperty = model.getPolymorphicDiscriminator(); - if (polymorphicProperty != null && !polymorphicProperty.isRequired() - && settings.isStreamStyleSerialization()) { + if (polymorphicProperty != null && !polymorphicProperty.isRequired()) { String discriminatorValue = polymorphicProperty.getDefaultValue() != null ? polymorphicProperty.getDefaultValue() : polymorphicProperty.getClientType().defaultValueExpression(model.getSerializedName()); @@ -949,9 +948,7 @@ private static void addGetterMethod(IType propertyWireType, IType propertyClient boolean treatAsXml, JavaBlock methodBlock, JavaSettings settings) { String sourceTypeName = propertyWireType.toString(); String targetTypeName = propertyClientType.toString(); - String expression = (property.isPolymorphicDiscriminator() && !settings.isStreamStyleSerialization()) - ? CodeNamer.getEnumMemberName(property.getName()) - : "this." + property.getName(); + String expression = "this." + property.getName(); if (propertyWireType.equals(ArrayType.BYTE_ARRAY)) { expression = TemplateHelper.getByteCloneExpression(expression); } diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertCriteria.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertCriteria.java index f537199873..264935d5f9 100644 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertCriteria.java @@ -42,7 +42,7 @@ public class MetricAlertCriteria { */ @JsonTypeId @JsonProperty(value = "odata\\.type", required = true) - private static final Odatatype odataType; + private Odatatype odataType; /* * The rule criteria that defines the conditions of the alert rule. @@ -54,15 +54,18 @@ public class MetricAlertCriteria { * Creates an instance of MetricAlertCriteria class. */ public MetricAlertCriteria() { + this.odataType = Odatatype.fromString("MetricAlertCriteria"); } /** - * Get the odataType property: specifies the type of the alert criteria. + * Set the odataType property: specifies the type of the alert criteria. * - * @return the odataType value. + * @param odataType the odataType value to set. + * @return the MetricAlertCriteria object itself. */ - public Odatatype getOdataType() { - return ODATA_TYPE; + MetricAlertCriteria setOdataType(Odatatype odataType) { + this.odataType = odataType; + return this; } /** diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java index aead407ac0..7d2b217f04 100644 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java @@ -33,6 +33,7 @@ public class MetricAlertSingleResourceMultipleMetricCriteria extends MetricAlert * Creates an instance of MetricAlertSingleResourceMultipleMetricCriteria class. */ public MetricAlertSingleResourceMultipleMetricCriteria() { + setOdataType(Odatatype.MICROSOFT_AZURE_MONITOR_SINGLE_RESOURCE_MULTIPLE_METRIC_CRITERIA); } /** diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java index b51c7be5f6..dbb451f5f4 100644 --- a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java @@ -42,7 +42,7 @@ public class MetricAlertCriteria { */ @JsonTypeId @JsonProperty(value = "odata\\.type", required = true) - private static final Odatatype odataType; + private Odatatype odataType; /* * The rule criteria that defines the conditions of the alert rule. @@ -54,15 +54,18 @@ public class MetricAlertCriteria { * Creates an instance of MetricAlertCriteria class. */ public MetricAlertCriteria() { + this.odataType = Odatatype.fromString("MetricAlertCriteria"); } /** - * Get the odataType property: specifies the type of the alert criteria. + * Set the odataType property: specifies the type of the alert criteria. * - * @return the odataType value. + * @param odataType the odataType value to set. + * @return the MetricAlertCriteria object itself. */ - public Odatatype getOdataType() { - return ODATA_TYPE; + MetricAlertCriteria setOdataType(Odatatype odataType) { + this.odataType = odataType; + return this; } /** diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java index 3964ab4f76..e2a5c27ffe 100644 --- a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java @@ -33,6 +33,7 @@ public class MetricAlertSingleResourceMultipleMetricCriteria extends MetricAlert * Creates an instance of MetricAlertSingleResourceMultipleMetricCriteria class. */ public MetricAlertSingleResourceMultipleMetricCriteria() { + setOdataType(Odatatype.MICROSOFT_AZURE_MONITOR_SINGLE_RESOURCE_MULTIPLE_METRIC_CRITERIA); } /** From 8aa0af71ea18d09975a3c160f477677accc77520 Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Thu, 22 Feb 2024 17:37:59 -0500 Subject: [PATCH 3/5] Add back getter --- .../java/com/azure/autorest/template/ModelTemplate.java | 3 +-- .../models/MetricAlertCriteria.java | 9 +++++++++ .../passdiscriminator/models/MetricAlertCriteria.java | 9 +++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java b/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java index 617b4e44b8..8f15a554e7 100644 --- a/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java +++ b/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java @@ -169,8 +169,7 @@ public final void write(ClientModel model, JavaFile javaFile) { ? JavaVisibility.Private : JavaVisibility.Public; - if (!property.isPolymorphicDiscriminator() - || (modelDefinesProperty(model, property) && settings.isStreamStyleSerialization())) { + if (!property.isPolymorphicDiscriminator() || modelDefinesProperty(model, property)) { // Only the super most parent model should have the polymorphic discriminator getter. // The child models should use the parent's getter. generateGetterJavadoc(classBlock, model, property); diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertCriteria.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertCriteria.java index 264935d5f9..181ad9c4a8 100644 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertCriteria.java @@ -57,6 +57,15 @@ public MetricAlertCriteria() { this.odataType = Odatatype.fromString("MetricAlertCriteria"); } + /** + * Get the odataType property: specifies the type of the alert criteria. + * + * @return the odataType value. + */ + public Odatatype getOdataType() { + return this.odataType; + } + /** * Set the odataType property: specifies the type of the alert criteria. * diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java index dbb451f5f4..14efdc3e46 100644 --- a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java @@ -57,6 +57,15 @@ public MetricAlertCriteria() { this.odataType = Odatatype.fromString("MetricAlertCriteria"); } + /** + * Get the odataType property: specifies the type of the alert criteria. + * + * @return the odataType value. + */ + public Odatatype getOdataType() { + return this.odataType; + } + /** * Set the odataType property: specifies the type of the alert criteria. * From 7da39d8a8bb371b79f3da65a72a745d8c19d1008 Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Fri, 23 Feb 2024 10:05:36 -0500 Subject: [PATCH 4/5] Update Jackson polymorphic annotations --- Generate.ps1 | 1 - .../autorest/template/ModelTemplate.java | 40 +-- .../donotpassdiscriminator/MetricAlerts.java | 150 ---------- .../MonitorManagementClient.java | 107 ------- .../MonitorManagementClientBuilder.java | 274 ------------------ .../models/ApplicationPackageReference.java | 95 ------ .../models/BackendAddressPool.java | 56 ---- .../models/LoadBalancer.java | 60 ---- .../models/MetricAlertCriteria.java | 116 -------- .../models/MetricAlertResource.java | 61 ---- ...tSingleResourceMultipleMetricCriteria.java | 68 ----- .../models/Odatatype.java | 61 ---- .../models/VirtualMachineScaleSet.java | 59 ---- ...alMachineScaleSetNetworkConfiguration.java | 84 ------ .../VirtualMachineScaleSetNetworkProfile.java | 59 ---- .../VirtualMachineScaleSetVMProfile.java | 59 ---- .../models/package-info.java | 9 - .../donotpassdiscriminator/package-info.java | 9 - .../models/MetricAlertCriteria.java | 1 - ...tSingleResourceMultipleMetricCriteria.java | 2 +- 20 files changed, 14 insertions(+), 1357 deletions(-) delete mode 100644 vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/MetricAlerts.java delete mode 100644 vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/MonitorManagementClient.java delete mode 100644 vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/MonitorManagementClientBuilder.java delete mode 100644 vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/ApplicationPackageReference.java delete mode 100644 vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/BackendAddressPool.java delete mode 100644 vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/LoadBalancer.java delete mode 100644 vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertCriteria.java delete mode 100644 vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertResource.java delete mode 100644 vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java delete mode 100644 vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/Odatatype.java delete mode 100644 vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/VirtualMachineScaleSet.java delete mode 100644 vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/VirtualMachineScaleSetNetworkConfiguration.java delete mode 100644 vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/VirtualMachineScaleSetNetworkProfile.java delete mode 100644 vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/VirtualMachineScaleSetVMProfile.java delete mode 100644 vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/package-info.java delete mode 100644 vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/package-info.java diff --git a/Generate.ps1 b/Generate.ps1 index baaf0c1cbb..cca0295567 100644 --- a/Generate.ps1 +++ b/Generate.ps1 @@ -138,7 +138,6 @@ $job = @( "$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/discriminator-flattening.json --namespace=fixtures.discriminatorflattening.noflatten --modelerfour.flatten-models=false", "$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/discriminator-flattening.json --namespace=fixtures.discriminatorflattening.clientflatten --modelerfour.flatten-models=false --client-flattened-annotation-target=NONE", "$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/client-default-value.json --namespace=fixtures.clientdefaultvalue --modelerfour.flatten-models=false", - "$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/discriminator-flattening.json --namespace=fixtures.inheritance.donotpassdiscriminator --stream-style-serialization=false", "$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/discriminator-flattening.json --namespace=fixtures.inheritance.passdiscriminator --stream-style-serialization=false", "$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/client-default-value.json --namespace=fixtures.annotatedgettersandsetters --annotate-getters-and-setters-for-serialization=true", "$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/xml-tag-with-attribute-and-value.json --namespace=fixtures.complexxmltag", diff --git a/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java b/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java index dce0841a35..914366fd24 100644 --- a/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java +++ b/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java @@ -430,37 +430,23 @@ protected void handlePolymorphism(ClientModel model, boolean hasDerivedModels, J return; } - StringBuilder jsonTypeInfo = new StringBuilder("JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = "); - - // If the discriminator isn't being passed to child models or this model has derived, children, models - // include the discriminator property using JsonTypeInfo.As.PROPERTY. Using this will serialize the - // property using the property attribute of the annotation instead of looking for a @JsonProperty. - if (hasDerivedModels) { - jsonTypeInfo.append("JsonTypeInfo.As.PROPERTY, property = \""); - } else { - // Otherwise, serialize the discriminator property with an existing property on the class. - jsonTypeInfo.append("JsonTypeInfo.As.EXISTING_PROPERTY, property = \""); - } - - jsonTypeInfo.append(model.getPolymorphicDiscriminatorName()).append("\""); - - // If the class has derived models add itself as a default implementation. - if (hasDerivedModels) { - jsonTypeInfo.append(", defaultImpl = ").append(model.getName()).append(".class"); - } - - // Discriminator is passed to child models the discriminator property needs to be set to visible. - jsonTypeInfo.append(", visible = true"); - - javaFile.annotation(jsonTypeInfo.append(")").toString()); - javaFile.annotation(String.format("JsonTypeName(\"%1$s\")", model.getSerializedName())); + // After removing the concept of passing discriminator to children models and always doing it, there is no need + // to set the 'include' property of the JsonTypeInfo annotation. We use 'JsonTypeInfo.As.PROPERTY' as the value, + // which is the default value, so it doesn't need to be declared. + // And to support unknown subtypes, we always set a default implementation to the class being generated. + // And the discriminator is passed to child models, so the discriminator property needs to be set to visible. + String jsonTypeInfo = "JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = \"" + + model.getPolymorphicDiscriminatorName() + "\", defaultImpl = " + model.getName() + + ".class, visible = true)"; + + javaFile.annotation(jsonTypeInfo); + javaFile.annotation("JsonTypeName(\"" + model.getSerializedName() + "\")"); if (hasDerivedModels) { javaFile.line("@JsonSubTypes({"); javaFile.indent(() -> { - Function getDerivedTypeAnnotation = (ClientModel derivedType) -> - String.format("@JsonSubTypes.Type(name = \"%1$s\", value = %2$s.class)", - derivedType.getSerializedName(), derivedType.getName()); + Function getDerivedTypeAnnotation = derivedType -> "@JsonSubTypes.Type(name = \"" + + derivedType.getSerializedName() + "\", value = " + derivedType.getName() + ".class)"; for (int i = 0; i != model.getDerivedModels().size() - 1; i++) { ClientModel derivedModel = model.getDerivedModels().get(i); diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/MetricAlerts.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/MetricAlerts.java deleted file mode 100644 index 9fc08ac5c2..0000000000 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/MetricAlerts.java +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package fixtures.inheritance.donotpassdiscriminator; - -import com.azure.core.annotation.ExpectedResponses; -import com.azure.core.annotation.Get; -import com.azure.core.annotation.HeaderParam; -import com.azure.core.annotation.Host; -import com.azure.core.annotation.HostParam; -import com.azure.core.annotation.ReturnType; -import com.azure.core.annotation.ServiceInterface; -import com.azure.core.annotation.ServiceMethod; -import com.azure.core.annotation.UnexpectedResponseExceptionType; -import com.azure.core.exception.HttpResponseException; -import com.azure.core.http.rest.Response; -import com.azure.core.http.rest.RestProxy; -import com.azure.core.util.Context; -import com.azure.core.util.FluxUtil; -import fixtures.inheritance.donotpassdiscriminator.models.MetricAlertResource; -import reactor.core.publisher.Mono; - -/** - * An instance of this class provides access to all the operations defined in MetricAlerts. - */ -public final class MetricAlerts { - /** - * The proxy service used to perform REST calls. - */ - private final MetricAlertsService service; - - /** - * The service client containing this operation class. - */ - private final MonitorManagementClient client; - - /** - * Initializes an instance of MetricAlerts. - * - * @param client the instance of the service client containing this operation class. - */ - MetricAlerts(MonitorManagementClient client) { - this.service - = RestProxy.create(MetricAlertsService.class, client.getHttpPipeline(), client.getSerializerAdapter()); - this.client = client; - } - - /** - * The interface defining all the services for MonitorManagementClientMetricAlerts to be used by the proxy service - * to perform REST calls. - */ - @Host("{$host}") - @ServiceInterface(name = "MonitorManagementCli") - public interface MetricAlertsService { - @Get("/providers/Microsoft.Insights/metricAlerts") - @ExpectedResponses({ 200 }) - @UnexpectedResponseExceptionType(HttpResponseException.class) - Mono> get(@HostParam("$host") String host, @HeaderParam("Accept") String accept, - Context context); - } - - /** - * Retrieve an alert rule definition. - * - * @throws HttpResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the metric alert resource along with {@link Response} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getWithResponseAsync() { - if (this.client.getHost() == null) { - return Mono - .error(new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null.")); - } - final String accept = "application/json"; - return FluxUtil.withContext(context -> service.get(this.client.getHost(), accept, context)); - } - - /** - * Retrieve an alert rule definition. - * - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws HttpResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the metric alert resource along with {@link Response} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getWithResponseAsync(Context context) { - if (this.client.getHost() == null) { - return Mono - .error(new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null.")); - } - final String accept = "application/json"; - return service.get(this.client.getHost(), accept, context); - } - - /** - * Retrieve an alert rule definition. - * - * @throws HttpResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the metric alert resource on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getAsync() { - return getWithResponseAsync().flatMap(res -> Mono.justOrEmpty(res.getValue())); - } - - /** - * Retrieve an alert rule definition. - * - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws HttpResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the metric alert resource on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getAsync(Context context) { - return getWithResponseAsync(context).flatMap(res -> Mono.justOrEmpty(res.getValue())); - } - - /** - * Retrieve an alert rule definition. - * - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws HttpResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the metric alert resource along with {@link Response}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Response getWithResponse(Context context) { - return getWithResponseAsync(context).block(); - } - - /** - * Retrieve an alert rule definition. - * - * @throws HttpResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the metric alert resource. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public MetricAlertResource get() { - return getWithResponse(Context.NONE).getValue(); - } -} diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/MonitorManagementClient.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/MonitorManagementClient.java deleted file mode 100644 index 524f981712..0000000000 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/MonitorManagementClient.java +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package fixtures.inheritance.donotpassdiscriminator; - -import com.azure.core.http.HttpPipeline; -import com.azure.core.http.HttpPipelineBuilder; -import com.azure.core.http.policy.RetryPolicy; -import com.azure.core.http.policy.UserAgentPolicy; -import com.azure.core.util.serializer.JacksonAdapter; -import com.azure.core.util.serializer.SerializerAdapter; - -/** - * Initializes a new instance of the MonitorManagementClient type. - */ -public final class MonitorManagementClient { - /** - * server parameter. - */ - private final String host; - - /** - * Gets server parameter. - * - * @return the host value. - */ - public String getHost() { - return this.host; - } - - /** - * The HTTP pipeline to send requests through. - */ - private final HttpPipeline httpPipeline; - - /** - * Gets The HTTP pipeline to send requests through. - * - * @return the httpPipeline value. - */ - public HttpPipeline getHttpPipeline() { - return this.httpPipeline; - } - - /** - * The serializer to serialize an object into a string. - */ - private final SerializerAdapter serializerAdapter; - - /** - * Gets The serializer to serialize an object into a string. - * - * @return the serializerAdapter value. - */ - public SerializerAdapter getSerializerAdapter() { - return this.serializerAdapter; - } - - /** - * The MetricAlerts object to access its operations. - */ - private final MetricAlerts metricAlerts; - - /** - * Gets the MetricAlerts object to access its operations. - * - * @return the MetricAlerts object. - */ - public MetricAlerts getMetricAlerts() { - return this.metricAlerts; - } - - /** - * Initializes an instance of MonitorManagementClient client. - * - * @param host server parameter. - */ - MonitorManagementClient(String host) { - this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(), - JacksonAdapter.createDefaultSerializerAdapter(), host); - } - - /** - * Initializes an instance of MonitorManagementClient client. - * - * @param httpPipeline The HTTP pipeline to send requests through. - * @param host server parameter. - */ - MonitorManagementClient(HttpPipeline httpPipeline, String host) { - this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), host); - } - - /** - * Initializes an instance of MonitorManagementClient client. - * - * @param httpPipeline The HTTP pipeline to send requests through. - * @param serializerAdapter The serializer to serialize an object into a string. - * @param host server parameter. - */ - MonitorManagementClient(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String host) { - this.httpPipeline = httpPipeline; - this.serializerAdapter = serializerAdapter; - this.host = host; - this.metricAlerts = new MetricAlerts(this); - } -} diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/MonitorManagementClientBuilder.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/MonitorManagementClientBuilder.java deleted file mode 100644 index 1acbadfb68..0000000000 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/MonitorManagementClientBuilder.java +++ /dev/null @@ -1,274 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package fixtures.inheritance.donotpassdiscriminator; - -import com.azure.core.annotation.Generated; -import com.azure.core.annotation.ServiceClientBuilder; -import com.azure.core.client.traits.ConfigurationTrait; -import com.azure.core.client.traits.HttpTrait; -import com.azure.core.http.HttpClient; -import com.azure.core.http.HttpHeaderName; -import com.azure.core.http.HttpHeaders; -import com.azure.core.http.HttpPipeline; -import com.azure.core.http.HttpPipelineBuilder; -import com.azure.core.http.HttpPipelinePosition; -import com.azure.core.http.policy.AddDatePolicy; -import com.azure.core.http.policy.AddHeadersFromContextPolicy; -import com.azure.core.http.policy.AddHeadersPolicy; -import com.azure.core.http.policy.HttpLoggingPolicy; -import com.azure.core.http.policy.HttpLogOptions; -import com.azure.core.http.policy.HttpPipelinePolicy; -import com.azure.core.http.policy.HttpPolicyProviders; -import com.azure.core.http.policy.RequestIdPolicy; -import com.azure.core.http.policy.RetryOptions; -import com.azure.core.http.policy.RetryPolicy; -import com.azure.core.http.policy.UserAgentPolicy; -import com.azure.core.util.ClientOptions; -import com.azure.core.util.Configuration; -import com.azure.core.util.CoreUtils; -import com.azure.core.util.builder.ClientBuilderUtil; -import com.azure.core.util.serializer.JacksonAdapter; -import com.azure.core.util.serializer.SerializerAdapter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * A builder for creating a new instance of the MonitorManagementClient type. - */ -@ServiceClientBuilder(serviceClients = { MonitorManagementClient.class }) -public final class MonitorManagementClientBuilder - implements HttpTrait, ConfigurationTrait { - @Generated - private static final String SDK_NAME = "name"; - - @Generated - private static final String SDK_VERSION = "version"; - - @Generated - private static final Map PROPERTIES = new HashMap<>(); - - @Generated - private final List pipelinePolicies; - - /** - * Create an instance of the MonitorManagementClientBuilder. - */ - @Generated - public MonitorManagementClientBuilder() { - this.pipelinePolicies = new ArrayList<>(); - } - - /* - * The HTTP pipeline to send requests through. - */ - @Generated - private HttpPipeline pipeline; - - /** - * {@inheritDoc}. - */ - @Generated - @Override - public MonitorManagementClientBuilder pipeline(HttpPipeline pipeline) { - this.pipeline = pipeline; - return this; - } - - /* - * The HTTP client used to send the request. - */ - @Generated - private HttpClient httpClient; - - /** - * {@inheritDoc}. - */ - @Generated - @Override - public MonitorManagementClientBuilder httpClient(HttpClient httpClient) { - this.httpClient = httpClient; - return this; - } - - /* - * The logging configuration for HTTP requests and responses. - */ - @Generated - private HttpLogOptions httpLogOptions; - - /** - * {@inheritDoc}. - */ - @Generated - @Override - public MonitorManagementClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { - this.httpLogOptions = httpLogOptions; - return this; - } - - /* - * The client options such as application ID and custom headers to set on a request. - */ - @Generated - private ClientOptions clientOptions; - - /** - * {@inheritDoc}. - */ - @Generated - @Override - public MonitorManagementClientBuilder clientOptions(ClientOptions clientOptions) { - this.clientOptions = clientOptions; - return this; - } - - /* - * The retry options to configure retry policy for failed requests. - */ - @Generated - private RetryOptions retryOptions; - - /** - * {@inheritDoc}. - */ - @Generated - @Override - public MonitorManagementClientBuilder retryOptions(RetryOptions retryOptions) { - this.retryOptions = retryOptions; - return this; - } - - /** - * {@inheritDoc}. - */ - @Generated - @Override - public MonitorManagementClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { - Objects.requireNonNull(customPolicy, "'customPolicy' cannot be null."); - pipelinePolicies.add(customPolicy); - return this; - } - - /* - * The configuration store that is used during construction of the service client. - */ - @Generated - private Configuration configuration; - - /** - * {@inheritDoc}. - */ - @Generated - @Override - public MonitorManagementClientBuilder configuration(Configuration configuration) { - this.configuration = configuration; - return this; - } - - /* - * server parameter - */ - @Generated - private String host; - - /** - * Sets server parameter. - * - * @param host the host value. - * @return the MonitorManagementClientBuilder. - */ - @Generated - public MonitorManagementClientBuilder host(String host) { - this.host = host; - return this; - } - - /* - * The serializer to serialize an object into a string - */ - @Generated - private SerializerAdapter serializerAdapter; - - /** - * Sets The serializer to serialize an object into a string. - * - * @param serializerAdapter the serializerAdapter value. - * @return the MonitorManagementClientBuilder. - */ - @Generated - public MonitorManagementClientBuilder serializerAdapter(SerializerAdapter serializerAdapter) { - this.serializerAdapter = serializerAdapter; - return this; - } - - /* - * The retry policy that will attempt to retry failed requests, if applicable. - */ - @Generated - private RetryPolicy retryPolicy; - - /** - * Sets The retry policy that will attempt to retry failed requests, if applicable. - * - * @param retryPolicy the retryPolicy value. - * @return the MonitorManagementClientBuilder. - */ - @Generated - public MonitorManagementClientBuilder retryPolicy(RetryPolicy retryPolicy) { - this.retryPolicy = retryPolicy; - return this; - } - - /** - * Builds an instance of MonitorManagementClient with the provided parameters. - * - * @return an instance of MonitorManagementClient. - */ - @Generated - public MonitorManagementClient buildClient() { - HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); - String localHost = (host != null) ? host : "https://management.azure.com"; - SerializerAdapter localSerializerAdapter - = (serializerAdapter != null) ? serializerAdapter : JacksonAdapter.createDefaultSerializerAdapter(); - MonitorManagementClient client = new MonitorManagementClient(localPipeline, localSerializerAdapter, localHost); - return client; - } - - @Generated - private HttpPipeline createHttpPipeline() { - Configuration buildConfiguration - = (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; - HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions; - ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions; - List policies = new ArrayList<>(); - String clientName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName"); - String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); - String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions); - policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); - policies.add(new RequestIdPolicy()); - policies.add(new AddHeadersFromContextPolicy()); - HttpHeaders headers = new HttpHeaders(); - localClientOptions.getHeaders() - .forEach(header -> headers.set(HttpHeaderName.fromString(header.getName()), header.getValue())); - if (headers.getSize() > 0) { - policies.add(new AddHeadersPolicy(headers)); - } - this.pipelinePolicies.stream().filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) - .forEach(p -> policies.add(p)); - HttpPolicyProviders.addBeforeRetryPolicies(policies); - policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); - policies.add(new AddDatePolicy()); - this.pipelinePolicies.stream().filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) - .forEach(p -> policies.add(p)); - HttpPolicyProviders.addAfterRetryPolicies(policies); - policies.add(new HttpLoggingPolicy(localHttpLogOptions)); - HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])) - .httpClient(httpClient).clientOptions(localClientOptions).build(); - return httpPipeline; - } -} diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/ApplicationPackageReference.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/ApplicationPackageReference.java deleted file mode 100644 index cbcac9e5da..0000000000 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/ApplicationPackageReference.java +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package fixtures.inheritance.donotpassdiscriminator.models; - -import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Link to an application package inside the batch account. - */ -@Fluent -public final class ApplicationPackageReference { - /* - * The ID of the application package to install. This must be inside the same batch account as the pool. This can - * either be a reference to a specific version or the default version if one exists. - */ - @JsonProperty(value = "id", required = true) - private String id; - - /* - * The version of the application to deploy. If omitted, the default version is deployed. - * - * If this is omitted, and no default version is specified for this application, the request fails with the error - * code InvalidApplicationPackageReferences. If you are calling the REST API directly, the HTTP status code is 409. - */ - @JsonProperty(value = "version") - private String version; - - /** - * Creates an instance of ApplicationPackageReference class. - */ - public ApplicationPackageReference() { - } - - /** - * Get the id property: The ID of the application package to install. This must be inside the same batch account as - * the pool. This can either be a reference to a specific version or the default version if one exists. - * - * @return the id value. - */ - public String getId() { - return this.id; - } - - /** - * Set the id property: The ID of the application package to install. This must be inside the same batch account as - * the pool. This can either be a reference to a specific version or the default version if one exists. - * - * @param id the id value to set. - * @return the ApplicationPackageReference object itself. - */ - public ApplicationPackageReference setId(String id) { - this.id = id; - return this; - } - - /** - * Get the version property: The version of the application to deploy. If omitted, the default version is deployed. - * - * If this is omitted, and no default version is specified for this application, the request fails with the error - * code InvalidApplicationPackageReferences. If you are calling the REST API directly, the HTTP status code is 409. - * - * @return the version value. - */ - public String getVersion() { - return this.version; - } - - /** - * Set the version property: The version of the application to deploy. If omitted, the default version is deployed. - * - * If this is omitted, and no default version is specified for this application, the request fails with the error - * code InvalidApplicationPackageReferences. If you are calling the REST API directly, the HTTP status code is 409. - * - * @param version the version value to set. - * @return the ApplicationPackageReference object itself. - */ - public ApplicationPackageReference setVersion(String version) { - this.version = version; - return this; - } - - /** - * Validates the instance. - * - * @throws IllegalArgumentException thrown if the instance is not valid. - */ - public void validate() { - if (getId() == null) { - throw new IllegalArgumentException("Missing required property id in model ApplicationPackageReference"); - } - } -} diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/BackendAddressPool.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/BackendAddressPool.java deleted file mode 100644 index 0848028c0c..0000000000 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/BackendAddressPool.java +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package fixtures.inheritance.donotpassdiscriminator.models; - -import com.azure.core.annotation.Fluent; -import com.azure.core.annotation.JsonFlatten; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Pool of backend IP addresses. - */ -@JsonFlatten -@Fluent -public class BackendAddressPool { - /* - * The location of the backend address pool. - */ - @JsonProperty(value = "properties.location") - private String location; - - /** - * Creates an instance of BackendAddressPool class. - */ - public BackendAddressPool() { - } - - /** - * Get the location property: The location of the backend address pool. - * - * @return the location value. - */ - public String getLocation() { - return this.location; - } - - /** - * Set the location property: The location of the backend address pool. - * - * @param location the location value to set. - * @return the BackendAddressPool object itself. - */ - public BackendAddressPool setLocation(String location) { - this.location = location; - return this; - } - - /** - * Validates the instance. - * - * @throws IllegalArgumentException thrown if the instance is not valid. - */ - public void validate() { - } -} diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/LoadBalancer.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/LoadBalancer.java deleted file mode 100644 index ac7895ea1a..0000000000 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/LoadBalancer.java +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package fixtures.inheritance.donotpassdiscriminator.models; - -import com.azure.core.annotation.Fluent; -import com.azure.core.annotation.JsonFlatten; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; - -/** - * LoadBalancer resource. - */ -@JsonFlatten -@Fluent -public class LoadBalancer { - /* - * Collection of backend address pools used by a load balancer. - */ - @JsonProperty(value = "properties.backendAddressPools") - private List backendAddressPools; - - /** - * Creates an instance of LoadBalancer class. - */ - public LoadBalancer() { - } - - /** - * Get the backendAddressPools property: Collection of backend address pools used by a load balancer. - * - * @return the backendAddressPools value. - */ - public List getBackendAddressPools() { - return this.backendAddressPools; - } - - /** - * Set the backendAddressPools property: Collection of backend address pools used by a load balancer. - * - * @param backendAddressPools the backendAddressPools value to set. - * @return the LoadBalancer object itself. - */ - public LoadBalancer setBackendAddressPools(List backendAddressPools) { - this.backendAddressPools = backendAddressPools; - return this; - } - - /** - * Validates the instance. - * - * @throws IllegalArgumentException thrown if the instance is not valid. - */ - public void validate() { - if (getBackendAddressPools() != null) { - getBackendAddressPools().forEach(e -> e.validate()); - } - } -} diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertCriteria.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertCriteria.java deleted file mode 100644 index 181ad9c4a8..0000000000 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertCriteria.java +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package fixtures.inheritance.donotpassdiscriminator.models; - -import com.azure.core.annotation.Fluent; -import com.azure.core.annotation.JsonFlatten; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeId; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.annotation.JsonTypeName; -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Pattern; - -/** - * The rule criteria that defines the conditions of the alert rule. - */ -@JsonTypeInfo( - use = JsonTypeInfo.Id.NAME, - include = JsonTypeInfo.As.PROPERTY, - property = "odata\\.type", - defaultImpl = MetricAlertCriteria.class, - visible = true) -@JsonTypeName("MetricAlertCriteria") -@JsonSubTypes({ - @JsonSubTypes.Type( - name = "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria", - value = MetricAlertSingleResourceMultipleMetricCriteria.class) }) -@JsonFlatten -@Fluent -public class MetricAlertCriteria { - private static final Pattern KEY_ESCAPER = Pattern.compile("\\.");; - - /* - * specifies the type of the alert criteria. - */ - @JsonTypeId - @JsonProperty(value = "odata\\.type", required = true) - private Odatatype odataType; - - /* - * The rule criteria that defines the conditions of the alert rule. - */ - @JsonIgnore - private Map additionalProperties; - - /** - * Creates an instance of MetricAlertCriteria class. - */ - public MetricAlertCriteria() { - this.odataType = Odatatype.fromString("MetricAlertCriteria"); - } - - /** - * Get the odataType property: specifies the type of the alert criteria. - * - * @return the odataType value. - */ - public Odatatype getOdataType() { - return this.odataType; - } - - /** - * Set the odataType property: specifies the type of the alert criteria. - * - * @param odataType the odataType value to set. - * @return the MetricAlertCriteria object itself. - */ - MetricAlertCriteria setOdataType(Odatatype odataType) { - this.odataType = odataType; - return this; - } - - /** - * Get the additionalProperties property: The rule criteria that defines the conditions of the alert rule. - * - * @return the additionalProperties value. - */ - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - /** - * Set the additionalProperties property: The rule criteria that defines the conditions of the alert rule. - * - * @param additionalProperties the additionalProperties value to set. - * @return the MetricAlertCriteria object itself. - */ - public MetricAlertCriteria setAdditionalProperties(Map additionalProperties) { - this.additionalProperties = additionalProperties; - return this; - } - - @JsonAnySetter - void setAdditionalProperties(String key, Object value) { - if (additionalProperties == null) { - additionalProperties = new HashMap<>(); - } - additionalProperties.put(KEY_ESCAPER.matcher(key).replaceAll("."), value); - } - - /** - * Validates the instance. - * - * @throws IllegalArgumentException thrown if the instance is not valid. - */ - public void validate() { - } -} diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertResource.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertResource.java deleted file mode 100644 index 64f798a6b1..0000000000 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertResource.java +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package fixtures.inheritance.donotpassdiscriminator.models; - -import com.azure.core.annotation.Fluent; -import com.azure.core.annotation.JsonFlatten; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * The metric alert resource. - */ -@JsonFlatten -@Fluent -public class MetricAlertResource { - /* - * defines the specific alert criteria information. - */ - @JsonProperty(value = "properties.criteria", required = true) - private MetricAlertCriteria criteria; - - /** - * Creates an instance of MetricAlertResource class. - */ - public MetricAlertResource() { - } - - /** - * Get the criteria property: defines the specific alert criteria information. - * - * @return the criteria value. - */ - public MetricAlertCriteria getCriteria() { - return this.criteria; - } - - /** - * Set the criteria property: defines the specific alert criteria information. - * - * @param criteria the criteria value to set. - * @return the MetricAlertResource object itself. - */ - public MetricAlertResource setCriteria(MetricAlertCriteria criteria) { - this.criteria = criteria; - return this; - } - - /** - * Validates the instance. - * - * @throws IllegalArgumentException thrown if the instance is not valid. - */ - public void validate() { - if (getCriteria() == null) { - throw new IllegalArgumentException("Missing required property criteria in model MetricAlertResource"); - } else { - getCriteria().validate(); - } - } -} diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java deleted file mode 100644 index 7d2b217f04..0000000000 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package fixtures.inheritance.donotpassdiscriminator.models; - -import com.azure.core.annotation.Fluent; -import com.azure.core.annotation.JsonFlatten; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.annotation.JsonTypeName; -import java.util.List; - -/** - * Specifies the metric alert criteria for a single resource that has multiple metric criteria. - */ -@JsonTypeInfo( - use = JsonTypeInfo.Id.NAME, - include = JsonTypeInfo.As.EXISTING_PROPERTY, - property = "odata\\.type", - visible = true) -@JsonTypeName("Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria") -@JsonFlatten -@Fluent -public class MetricAlertSingleResourceMultipleMetricCriteria extends MetricAlertCriteria { - /* - * The list of metric criteria for this 'all of' operation. - */ - @JsonProperty(value = "allOf") - private List allOf; - - /** - * Creates an instance of MetricAlertSingleResourceMultipleMetricCriteria class. - */ - public MetricAlertSingleResourceMultipleMetricCriteria() { - setOdataType(Odatatype.MICROSOFT_AZURE_MONITOR_SINGLE_RESOURCE_MULTIPLE_METRIC_CRITERIA); - } - - /** - * Get the allOf property: The list of metric criteria for this 'all of' operation. - * - * @return the allOf value. - */ - public List getAllOf() { - return this.allOf; - } - - /** - * Set the allOf property: The list of metric criteria for this 'all of' operation. - * - * @param allOf the allOf value to set. - * @return the MetricAlertSingleResourceMultipleMetricCriteria object itself. - */ - public MetricAlertSingleResourceMultipleMetricCriteria setAllOf(List allOf) { - this.allOf = allOf; - return this; - } - - /** - * Validates the instance. - * - * @throws IllegalArgumentException thrown if the instance is not valid. - */ - @Override - public void validate() { - super.validate(); - } -} diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/Odatatype.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/Odatatype.java deleted file mode 100644 index 6d0d004004..0000000000 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/Odatatype.java +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package fixtures.inheritance.donotpassdiscriminator.models; - -import com.azure.core.util.ExpandableStringEnum; -import com.fasterxml.jackson.annotation.JsonCreator; -import java.util.Collection; - -/** - * specifies the type of the alert criteria. - */ -public final class Odatatype extends ExpandableStringEnum { - /** - * Static value Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria for Odatatype. - */ - public static final Odatatype MICROSOFT_AZURE_MONITOR_SINGLE_RESOURCE_MULTIPLE_METRIC_CRITERIA - = fromString("Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria"); - - /** - * Static value Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria for Odatatype. - */ - public static final Odatatype MICROSOFT_AZURE_MONITOR_MULTIPLE_RESOURCE_MULTIPLE_METRIC_CRITERIA - = fromString("Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria"); - - /** - * Static value Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria for Odatatype. - */ - public static final Odatatype MICROSOFT_AZURE_MONITOR_WEBTEST_LOCATION_AVAILABILITY_CRITERIA - = fromString("Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria"); - - /** - * Creates a new instance of Odatatype value. - * - * @deprecated Use the {@link #fromString(String)} factory method. - */ - @Deprecated - public Odatatype() { - } - - /** - * Creates or finds a Odatatype from its string representation. - * - * @param name a name to look for. - * @return the corresponding Odatatype. - */ - @JsonCreator - public static Odatatype fromString(String name) { - return fromString(name, Odatatype.class); - } - - /** - * Gets known Odatatype values. - * - * @return known Odatatype values. - */ - public static Collection values() { - return values(Odatatype.class); - } -} diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/VirtualMachineScaleSet.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/VirtualMachineScaleSet.java deleted file mode 100644 index 4cde9b8e5d..0000000000 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/VirtualMachineScaleSet.java +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package fixtures.inheritance.donotpassdiscriminator.models; - -import com.azure.core.annotation.Fluent; -import com.azure.core.annotation.JsonFlatten; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Describes a Virtual Machine Scale Set. - */ -@JsonFlatten -@Fluent -public class VirtualMachineScaleSet { - /* - * The virtual machine profile. - */ - @JsonProperty(value = "properties.virtualMachineProfile") - private VirtualMachineScaleSetVMProfile virtualMachineProfile; - - /** - * Creates an instance of VirtualMachineScaleSet class. - */ - public VirtualMachineScaleSet() { - } - - /** - * Get the virtualMachineProfile property: The virtual machine profile. - * - * @return the virtualMachineProfile value. - */ - public VirtualMachineScaleSetVMProfile getVirtualMachineProfile() { - return this.virtualMachineProfile; - } - - /** - * Set the virtualMachineProfile property: The virtual machine profile. - * - * @param virtualMachineProfile the virtualMachineProfile value to set. - * @return the VirtualMachineScaleSet object itself. - */ - public VirtualMachineScaleSet setVirtualMachineProfile(VirtualMachineScaleSetVMProfile virtualMachineProfile) { - this.virtualMachineProfile = virtualMachineProfile; - return this; - } - - /** - * Validates the instance. - * - * @throws IllegalArgumentException thrown if the instance is not valid. - */ - public void validate() { - if (getVirtualMachineProfile() != null) { - getVirtualMachineProfile().validate(); - } - } -} diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/VirtualMachineScaleSetNetworkConfiguration.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/VirtualMachineScaleSetNetworkConfiguration.java deleted file mode 100644 index 0768ab706f..0000000000 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/VirtualMachineScaleSetNetworkConfiguration.java +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package fixtures.inheritance.donotpassdiscriminator.models; - -import com.azure.core.annotation.Fluent; -import com.azure.core.annotation.JsonFlatten; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Describes a virtual machine scale set network profile's network configurations. - */ -@JsonFlatten -@Fluent -public class VirtualMachineScaleSetNetworkConfiguration { - /* - * The network configuration name. - */ - @JsonProperty(value = "name") - private String name; - - /* - * Specifies the primary network interface in case the virtual machine has more than 1 network interface. - */ - @JsonProperty(value = "properties.primary") - private Boolean primary; - - /** - * Creates an instance of VirtualMachineScaleSetNetworkConfiguration class. - */ - public VirtualMachineScaleSetNetworkConfiguration() { - } - - /** - * Get the name property: The network configuration name. - * - * @return the name value. - */ - public String getName() { - return this.name; - } - - /** - * Set the name property: The network configuration name. - * - * @param name the name value to set. - * @return the VirtualMachineScaleSetNetworkConfiguration object itself. - */ - public VirtualMachineScaleSetNetworkConfiguration setName(String name) { - this.name = name; - return this; - } - - /** - * Get the primary property: Specifies the primary network interface in case the virtual machine has more than 1 - * network interface. - * - * @return the primary value. - */ - public Boolean isPrimary() { - return this.primary; - } - - /** - * Set the primary property: Specifies the primary network interface in case the virtual machine has more than 1 - * network interface. - * - * @param primary the primary value to set. - * @return the VirtualMachineScaleSetNetworkConfiguration object itself. - */ - public VirtualMachineScaleSetNetworkConfiguration setPrimary(Boolean primary) { - this.primary = primary; - return this; - } - - /** - * Validates the instance. - * - * @throws IllegalArgumentException thrown if the instance is not valid. - */ - public void validate() { - } -} diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/VirtualMachineScaleSetNetworkProfile.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/VirtualMachineScaleSetNetworkProfile.java deleted file mode 100644 index b7991d1d23..0000000000 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/VirtualMachineScaleSetNetworkProfile.java +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package fixtures.inheritance.donotpassdiscriminator.models; - -import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; - -/** - * Describes a virtual machine scale set network profile. - */ -@Fluent -public final class VirtualMachineScaleSetNetworkProfile { - /* - * The list of network configurations. - */ - @JsonProperty(value = "networkInterfaceConfigurations") - private List networkInterfaceConfigurations; - - /** - * Creates an instance of VirtualMachineScaleSetNetworkProfile class. - */ - public VirtualMachineScaleSetNetworkProfile() { - } - - /** - * Get the networkInterfaceConfigurations property: The list of network configurations. - * - * @return the networkInterfaceConfigurations value. - */ - public List getNetworkInterfaceConfigurations() { - return this.networkInterfaceConfigurations; - } - - /** - * Set the networkInterfaceConfigurations property: The list of network configurations. - * - * @param networkInterfaceConfigurations the networkInterfaceConfigurations value to set. - * @return the VirtualMachineScaleSetNetworkProfile object itself. - */ - public VirtualMachineScaleSetNetworkProfile setNetworkInterfaceConfigurations( - List networkInterfaceConfigurations) { - this.networkInterfaceConfigurations = networkInterfaceConfigurations; - return this; - } - - /** - * Validates the instance. - * - * @throws IllegalArgumentException thrown if the instance is not valid. - */ - public void validate() { - if (getNetworkInterfaceConfigurations() != null) { - getNetworkInterfaceConfigurations().forEach(e -> e.validate()); - } - } -} diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/VirtualMachineScaleSetVMProfile.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/VirtualMachineScaleSetVMProfile.java deleted file mode 100644 index 35898f6dc2..0000000000 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/VirtualMachineScaleSetVMProfile.java +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package fixtures.inheritance.donotpassdiscriminator.models; - -import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Describes a virtual machine scale set virtual machine profile. - */ -@Fluent -public final class VirtualMachineScaleSetVMProfile { - /* - * Specifies properties of the network interfaces of the virtual machines in the scale set. - */ - @JsonProperty(value = "networkProfile") - private VirtualMachineScaleSetNetworkProfile networkProfile; - - /** - * Creates an instance of VirtualMachineScaleSetVMProfile class. - */ - public VirtualMachineScaleSetVMProfile() { - } - - /** - * Get the networkProfile property: Specifies properties of the network interfaces of the virtual machines in the - * scale set. - * - * @return the networkProfile value. - */ - public VirtualMachineScaleSetNetworkProfile getNetworkProfile() { - return this.networkProfile; - } - - /** - * Set the networkProfile property: Specifies properties of the network interfaces of the virtual machines in the - * scale set. - * - * @param networkProfile the networkProfile value to set. - * @return the VirtualMachineScaleSetVMProfile object itself. - */ - public VirtualMachineScaleSetVMProfile setNetworkProfile(VirtualMachineScaleSetNetworkProfile networkProfile) { - this.networkProfile = networkProfile; - return this; - } - - /** - * Validates the instance. - * - * @throws IllegalArgumentException thrown if the instance is not valid. - */ - public void validate() { - if (getNetworkProfile() != null) { - getNetworkProfile().validate(); - } - } -} diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/package-info.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/package-info.java deleted file mode 100644 index e23cfb8952..0000000000 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/models/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -/** - * Package containing the data models for MonitorManagementClient. - * Azure Monitor client to create/update/delete metric based alerts. - */ -package fixtures.inheritance.donotpassdiscriminator.models; diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/package-info.java b/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/package-info.java deleted file mode 100644 index 7cc0a5841b..0000000000 --- a/vanilla-tests/src/main/java/fixtures/inheritance/donotpassdiscriminator/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -/** - * Package containing the classes for MonitorManagementClient. - * Azure Monitor client to create/update/delete metric based alerts. - */ -package fixtures.inheritance.donotpassdiscriminator; diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java index 14efdc3e46..d44bd694de 100644 --- a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java @@ -23,7 +23,6 @@ */ @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, - include = JsonTypeInfo.As.PROPERTY, property = "odata\\.type", defaultImpl = MetricAlertCriteria.class, visible = true) diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java index e2a5c27ffe..d3055ce29c 100644 --- a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java @@ -16,8 +16,8 @@ */ @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, - include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "odata\\.type", + defaultImpl = MetricAlertSingleResourceMultipleMetricCriteria.class, visible = true) @JsonTypeName("Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria") @JsonFlatten From 42a52a9b13724b6a6c9756e7c35ec90945938176 Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:28:28 -0500 Subject: [PATCH 5/5] Delete tests for code generation that doesn't exist anymore --- ...ValidateDiscriminatorIsNotPassedTests.java | 32 ------------------- 1 file changed, 32 deletions(-) delete mode 100644 vanilla-tests/src/test/java/fixtures/inheritance/donotpassdiscriminator/ValidateDiscriminatorIsNotPassedTests.java diff --git a/vanilla-tests/src/test/java/fixtures/inheritance/donotpassdiscriminator/ValidateDiscriminatorIsNotPassedTests.java b/vanilla-tests/src/test/java/fixtures/inheritance/donotpassdiscriminator/ValidateDiscriminatorIsNotPassedTests.java deleted file mode 100644 index 9f19eb2e2a..0000000000 --- a/vanilla-tests/src/test/java/fixtures/inheritance/donotpassdiscriminator/ValidateDiscriminatorIsNotPassedTests.java +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package fixtures.inheritance.donotpassdiscriminator; - -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import fixtures.inheritance.donotpassdiscriminator.models.MetricAlertCriteria; -import fixtures.inheritance.donotpassdiscriminator.models.MetricAlertSingleResourceMultipleMetricCriteria; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; - -public class ValidateDiscriminatorIsNotPassedTests { - @Test - public void superClassDoesNotPassDiscriminator() { - JsonTypeInfo jsonTypeInfo = MetricAlertCriteria.class.getAnnotation(JsonTypeInfo.class); - assertNotNull(jsonTypeInfo); - assertFalse(jsonTypeInfo.visible()); - assertEquals(JsonTypeInfo.As.PROPERTY, jsonTypeInfo.include()); - } - - @Test - public void subClassDoesNotAcceptDiscriminator() { - JsonTypeInfo jsonTypeInfo = MetricAlertSingleResourceMultipleMetricCriteria.class - .getAnnotation(JsonTypeInfo.class); - assertNotNull(jsonTypeInfo); - assertFalse(jsonTypeInfo.visible()); - assertEquals(JsonTypeInfo.As.PROPERTY, jsonTypeInfo.include()); - } -}