diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/ChoiceMapper.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/ChoiceMapper.java index 361813a75e..5433e6f68b 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/ChoiceMapper.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/ChoiceMapper.java @@ -4,6 +4,7 @@ package com.microsoft.typespec.http.client.generator.core.mapper; import com.microsoft.typespec.http.client.generator.core.extension.model.codemodel.ChoiceSchema; +import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClassType; import com.microsoft.typespec.http.client.generator.core.model.clientmodel.EnumType; import com.microsoft.typespec.http.client.generator.core.model.clientmodel.IType; import java.util.Map; @@ -45,7 +46,17 @@ public IType map(ChoiceSchema enumType) { return choiceType; } + protected boolean useCodeModelNameForEnumMember() { + return true; + } + private IType createChoiceType(ChoiceSchema enumType) { - return MapperUtils.createEnumType(enumType, true, true); + IType elementType = Mappers.getSchemaMapper().map(enumType.getChoiceType()); + boolean isStringEnum = elementType == ClassType.STRING; + if (isStringEnum) { + return MapperUtils.createEnumType(enumType, true, useCodeModelNameForEnumMember()); + } else { + return MapperUtils.createEnumType(enumType, true, useCodeModelNameForEnumMember(), "getValue", "fromValue"); + } } } diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/MapperUtils.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/MapperUtils.java index 9e64454f57..b625e2fc58 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/MapperUtils.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/MapperUtils.java @@ -29,7 +29,7 @@ public final class MapperUtils { /** * Create enum client type from code model. - * + * * @param enumType code model schema for enum * @param expandable whether it's expandable enum * @param useCodeModelNameForEnumMember whether to use code model enum member name for client enum member name @@ -37,6 +37,21 @@ public final class MapperUtils { */ public static IType createEnumType(ChoiceSchema enumType, boolean expandable, boolean useCodeModelNameForEnumMember) { + return createEnumType(enumType, expandable, useCodeModelNameForEnumMember, null, null); + } + + /** + * Create enum client type from code model. + * + * @param enumType code model schema for enum + * @param expandable whether it's expandable enum + * @param useCodeModelNameForEnumMember whether to use code model enum member name for client enum member name + * @param serializationMethodName method name for serialization + * @param deserializationMethodName method name for deserialization + * @return enum client type + */ + public static IType createEnumType(ChoiceSchema enumType, boolean expandable, boolean useCodeModelNameForEnumMember, + String serializationMethodName, String deserializationMethodName) { JavaSettings settings = JavaSettings.getInstance(); String enumTypeName = enumType.getLanguage().getJava().getName(); @@ -98,6 +113,8 @@ public static IType createEnumType(ChoiceSchema enumType, boolean expandable, new ImplementationDetails.Builder().usages(SchemaUtil.mapSchemaContext(enumType.getUsage())) .build()) .crossLanguageDefinitionId(enumType.getCrossLanguageDefinitionId()) + .fromMethodName(deserializationMethodName) + .toMethodName(serializationMethodName) .build(); } } diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/SchemaMapper.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/SchemaMapper.java index c2f9407517..bfcbbd498f 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/SchemaMapper.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/SchemaMapper.java @@ -49,10 +49,10 @@ public IType map(Schema value) { private IType createSchemaType(Schema value) { if (value instanceof PrimitiveSchema) { return Mappers.getPrimitiveMapper().map((PrimitiveSchema) value); - } else if (value instanceof ChoiceSchema) { - return Mappers.getChoiceMapper().map((ChoiceSchema) value); } else if (value instanceof SealedChoiceSchema) { return Mappers.getSealedChoiceMapper().map((SealedChoiceSchema) value); + } else if (value instanceof ChoiceSchema) { + return Mappers.getChoiceMapper().map((ChoiceSchema) value); } else if (value instanceof ArraySchema) { return Mappers.getArrayMapper().map((ArraySchema) value); } else if (value instanceof DictionarySchema) { diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/SealedChoiceMapper.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/SealedChoiceMapper.java index 522f86a6b4..63a5342a9d 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/SealedChoiceMapper.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/SealedChoiceMapper.java @@ -36,7 +36,11 @@ public IType map(SealedChoiceSchema enumType) { return sealedChoiceType; } + protected boolean useCodeModelNameForEnumMember() { + return true; + } + private IType createSealedChoiceType(SealedChoiceSchema enumType) { - return MapperUtils.createEnumType(enumType, false, true); + return MapperUtils.createEnumType(enumType, false, useCodeModelNameForEnumMember()); } } diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ClassType.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ClassType.java index 2cb51374f6..f4f3982f1d 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ClassType.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ClassType.java @@ -45,6 +45,7 @@ import com.azure.core.util.Context; import com.azure.core.util.CoreUtils; import com.azure.core.util.DateTimeRfc1123; +import com.azure.core.util.ExpandableEnum; import com.azure.core.util.ExpandableStringEnum; import com.azure.core.util.logging.ClientLogger; import com.azure.core.util.logging.LogLevel; @@ -178,6 +179,7 @@ private static ClassType.Builder getClassTypeBuilder(Class classKey) { public static final ClassType RESPONSE = getClassTypeBuilder(Response.class).build(); public static final ClassType SIMPLE_RESPONSE = getClassTypeBuilder(SimpleResponse.class).build(); public static final ClassType EXPANDABLE_STRING_ENUM = getClassTypeBuilder(ExpandableStringEnum.class).build(); + public static final ClassType EXPANDABLE_ENUM = getClassTypeBuilder(ExpandableEnum.class).build(); public static final ClassType HTTP_PIPELINE_BUILDER = getClassTypeBuilder(HttpPipelineBuilder.class).build(); public static final ClassType KEY_CREDENTIAL_POLICY = getClassTypeBuilder(KeyCredentialPolicy.class).build(); public static final ClassType KEY_CREDENTIAL_TRAIT = getClassTypeBuilder(KeyCredentialTrait.class).build(); diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/EnumType.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/EnumType.java index 8b764f6b53..b4728d0413 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/EnumType.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/EnumType.java @@ -3,6 +3,7 @@ package com.microsoft.typespec.http.client.generator.core.model.clientmodel; +import com.azure.core.util.CoreUtils; import com.microsoft.typespec.http.client.generator.core.util.CodeNamer; import java.util.List; import java.util.Set; @@ -34,18 +35,22 @@ public class EnumType implements IType { private final ImplementationDetails implementationDetails; private String crossLanguageDefinitionId; + private final String fromMethodName; + private final String toMethodName; /** * Create a new Enum with the provided properties. - * + * * @param name The name of the new Enum. * @param description The description of the Enum. * @param expandable Whether this will be an ExpandableStringEnum type. * @param values The values of the Enum. + * @param fromMethodName The method name used to convert JSON to the enum type. + * @param toMethodName The method name used to convert the enum type to JSON. */ private EnumType(String packageKeyword, String name, String description, boolean expandable, List values, IType elementType, ImplementationDetails implementationDetails, - String crossLanguageDefinitionId) { + String crossLanguageDefinitionId, String fromMethodName, String toMethodName) { this.name = name; this.packageName = packageKeyword; this.description = description; @@ -54,6 +59,8 @@ private EnumType(String packageKeyword, String name, String description, boolean this.elementType = elementType; this.implementationDetails = implementationDetails; this.crossLanguageDefinitionId = crossLanguageDefinitionId; + this.fromMethodName = fromMethodName; + this.toMethodName = toMethodName; } public String getCrossLanguageDefinitionId() { @@ -132,7 +139,9 @@ public final String defaultValueExpression(String sourceExpression) { * @return The method name used to convert JSON to the enum type. */ public final String getFromMethodName() { - return "from" + CodeNamer.toPascalCase(elementType.getClientType().toString()); + return CoreUtils.isNullOrEmpty(fromMethodName) + ? "from" + CodeNamer.toPascalCase(elementType.getClientType().toString()) + : fromMethodName; } /** @@ -141,7 +150,9 @@ public final String getFromMethodName() { * @return The method name used to convert the enum type to JSON. */ public final String getToMethodName() { - return "to" + CodeNamer.toPascalCase(elementType.getClientType().toString()); + return CoreUtils.isNullOrEmpty(toMethodName) + ? "to" + CodeNamer.toPascalCase(elementType.getClientType().toString()) + : toMethodName; } @Override @@ -229,6 +240,8 @@ public static class Builder { private ImplementationDetails implementationDetails; private String crossLanguageDefinitionId; + private String fromMethodName; + private String toMethodName; /** * Sets the name of the Enum. @@ -314,12 +327,22 @@ public Builder crossLanguageDefinitionId(String crossLanguageDefinitionId) { return this; } + public Builder fromMethodName(String fromMethodName) { + this.fromMethodName = fromMethodName; + return this; + } + + public Builder toMethodName(String toMethodName) { + this.toMethodName = toMethodName; + return this; + } + /** * @return an immutable EnumType instance with the configurations on this builder. */ public EnumType build() { return new EnumType(packageName, name, description, expandable, values, elementType, implementationDetails, - crossLanguageDefinitionId); + crossLanguageDefinitionId, fromMethodName, toMethodName); } } } diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/EnumTemplate.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/EnumTemplate.java index 859067bf12..d7fbac8ba4 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/EnumTemplate.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/EnumTemplate.java @@ -39,7 +39,7 @@ public final void write(EnumType enumType, JavaFile javaFile) { if (enumType.getExpandable()) { if (settings.isBranded()) { - writeExpandableStringEnum(enumType, javaFile, settings); + writeBrandedExpandableEnum(enumType, javaFile, settings); } else { writeExpandableStringEnumInterface(enumType, javaFile, settings); } @@ -48,6 +48,119 @@ public final void write(EnumType enumType, JavaFile javaFile) { } } + /** + * Extension point for expandable enum implementation of branded flavor. + * + * @param enumType enumType to write implementation + * @param javaFile javaFile to write into + * @param settings {@link JavaSettings} instance + */ + protected void writeBrandedExpandableEnum(EnumType enumType, JavaFile javaFile, JavaSettings settings) { + if (enumType.getElementType() == ClassType.STRING) { + writeExpandableStringEnum(enumType, javaFile, settings); + } else { + Set imports = new HashSet<>(); + imports.add("java.util.Collection"); + imports.add("java.lang.IllegalArgumentException"); + imports.add("java.util.Map"); + imports.add("java.util.concurrent.ConcurrentHashMap"); + imports.add("java.util.ArrayList"); + imports.add("java.util.Objects"); + imports.add(ClassType.EXPANDABLE_ENUM.getFullName()); + if (!settings.isStreamStyleSerialization()) { + imports.add("com.fasterxml.jackson.annotation.JsonCreator"); + } + + addGeneratedImport(imports); + + javaFile.declareImport(imports); + javaFile.javadocComment(comment -> comment.description(enumType.getDescription())); + + String enumName = enumType.getName(); + IType elementType = enumType.getElementType(); + String typeName = elementType.getClientType().asNullable().toString(); + String pascalTypeName = CodeNamer.toPascalCase(typeName); + String declaration = enumName + " implements ExpandableEnum<" + pascalTypeName + ">"; + javaFile.publicFinalClass(declaration, classBlock -> { + classBlock.privateStaticFinalVariable( + String.format("Map<%1$s, %2$s> VALUES = new ConcurrentHashMap<>()", pascalTypeName, enumName)); + + for (ClientEnumValue enumValue : enumType.getValues()) { + String value = enumValue.getValue(); + classBlock.javadocComment(CoreUtils.isNullOrEmpty(enumValue.getDescription()) + ? "Static value " + value + " for " + enumName + "." + : enumValue.getDescription()); + addGeneratedAnnotation(classBlock); + classBlock.publicStaticFinalVariable(String.format("%1$s %2$s = fromValue(%3$s)", enumName, + enumValue.getName(), elementType.defaultValueExpression(value))); + } + + classBlock.variable(pascalTypeName + " value", JavaVisibility.Private, JavaModifier.Final); + classBlock.privateConstructor(enumName + "(" + pascalTypeName + " value)", ctor -> { + ctor.line("this.value = value;"); + }); + + // fromValue(typeName) + classBlock.javadocComment(comment -> { + comment.description("Creates or finds a " + enumName); + comment.param("value", "a value to look for"); + comment.methodReturns("the corresponding " + enumName); + }); + + addGeneratedAnnotation(classBlock); + if (!settings.isStreamStyleSerialization()) { + classBlock.annotation("JsonCreator"); + } + + classBlock.publicStaticMethod(String.format("%1$s fromValue(%2$s value)", enumName, pascalTypeName), + function -> { + function.line("Objects.requireNonNull(value, \"'value' cannot be null.\");"); + function.line(enumName + " member = VALUES.get(value);"); + function.ifBlock("member != null", ifAction -> ifAction.line("return member;")); + function.methodReturn("VALUES.computeIfAbsent(value, key -> new " + enumName + "(key))"); + }); + + // values + classBlock.javadocComment(comment -> { + comment.description("Gets known " + enumName + " values."); + comment.methodReturns("Known " + enumName + " values."); + }); + addGeneratedAnnotation(classBlock); + classBlock.publicStaticMethod(String.format("Collection<%s> values()", enumName), + function -> function.methodReturn("new ArrayList<>(VALUES.values())")); + + // getValue + classBlock.javadocComment(comment -> { + comment.description("Gets the value of the " + enumName + " instance."); + comment.methodReturns("the value of the " + enumName + " instance."); + }); + + addGeneratedAnnotation(classBlock); + classBlock.annotation("Override"); + classBlock.publicMethod(pascalTypeName + " getValue()", + function -> function.methodReturn("this.value")); + + // toString + addGeneratedAnnotation(classBlock); + classBlock.annotation("Override"); + classBlock.method(JavaVisibility.Public, null, "String toString()", + function -> function.methodReturn("Objects.toString(this.value)")); + + // equals + addGeneratedAnnotation(classBlock); + classBlock.annotation("Override"); + classBlock.method(JavaVisibility.Public, null, "boolean equals(Object obj)", + function -> function.methodReturn("Objects.equals(this.value, obj)")); + + // hashcode + addGeneratedAnnotation(classBlock); + classBlock.annotation("Override"); + classBlock.method(JavaVisibility.Public, null, "int hashCode()", + function -> function.methodReturn("Objects.hashCode(this.value)")); + }); + } + } + private void writeExpandableStringEnumInterface(EnumType enumType, JavaFile javaFile, JavaSettings settings) { Set imports = new HashSet<>(); imports.add("java.util.Collection"); diff --git a/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/mapper/FluentChoiceMapper.java b/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/mapper/FluentChoiceMapper.java index a9d4bf4359..7933acee1a 100644 --- a/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/mapper/FluentChoiceMapper.java +++ b/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/mapper/FluentChoiceMapper.java @@ -3,10 +3,7 @@ package com.microsoft.typespec.http.client.generator.mgmt.mapper; -import com.microsoft.typespec.http.client.generator.core.extension.model.codemodel.ChoiceSchema; import com.microsoft.typespec.http.client.generator.core.mapper.ChoiceMapper; -import com.microsoft.typespec.http.client.generator.core.mapper.MapperUtils; -import com.microsoft.typespec.http.client.generator.core.model.clientmodel.IType; public class FluentChoiceMapper extends ChoiceMapper { private static final FluentChoiceMapper INSTANCE = new FluentChoiceMapper(); @@ -19,7 +16,7 @@ public static FluentChoiceMapper getInstance() { } @Override - public IType map(ChoiceSchema enumType) { - return MapperUtils.createEnumType(enumType, true, false); + protected boolean useCodeModelNameForEnumMember() { + return false; } } diff --git a/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/mapper/FluentSealedChoiceMapper.java b/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/mapper/FluentSealedChoiceMapper.java index 3ba15239ed..412e981fd2 100644 --- a/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/mapper/FluentSealedChoiceMapper.java +++ b/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/mapper/FluentSealedChoiceMapper.java @@ -3,10 +3,7 @@ package com.microsoft.typespec.http.client.generator.mgmt.mapper; -import com.microsoft.typespec.http.client.generator.core.extension.model.codemodel.SealedChoiceSchema; -import com.microsoft.typespec.http.client.generator.core.mapper.MapperUtils; import com.microsoft.typespec.http.client.generator.core.mapper.SealedChoiceMapper; -import com.microsoft.typespec.http.client.generator.core.model.clientmodel.IType; public class FluentSealedChoiceMapper extends SealedChoiceMapper { private static final FluentSealedChoiceMapper INSTANCE = new FluentSealedChoiceMapper(); @@ -19,7 +16,7 @@ public static FluentSealedChoiceMapper getInstance() { } @Override - public IType map(SealedChoiceSchema enumType) { - return MapperUtils.createEnumType(enumType, false, false); + protected boolean useCodeModelNameForEnumMember() { + return false; } } diff --git a/packages/http-client-java/generator/http-client-generator-test/Generate.ps1 b/packages/http-client-java/generator/http-client-generator-test/Generate.ps1 index 8a2e843bf8..ddabe27356 100644 --- a/packages/http-client-java/generator/http-client-generator-test/Generate.ps1 +++ b/packages/http-client-java/generator/http-client-generator-test/Generate.ps1 @@ -113,28 +113,7 @@ $generateScript = { } } -Set-Location (Resolve-Path (Join-Path $PSScriptRoot '..' '..')) - -npm install -npm run build -npm pack - -Set-Location $PSScriptRoot - - -if (Test-Path node_modules) { - Remove-Item node_modules -Recurse -Force -} - -if (Test-Path package-lock.json) { - Remove-Item package-lock.json -} - -# delete output -if (Test-Path tsp-output) { - Remove-Item tsp-output -Recurse -Force -} -npm install +./Setup.ps1 New-Item -Path ./existingcode/src/main/java/com/cadl/ -ItemType Directory -Force | Out-Null diff --git a/packages/http-client-java/generator/http-client-generator-test/Setup.ps1 b/packages/http-client-java/generator/http-client-generator-test/Setup.ps1 new file mode 100644 index 0000000000..f72480dd10 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/Setup.ps1 @@ -0,0 +1,8 @@ +# re-build http-client-java +Set-Location (Resolve-Path (Join-Path $PSScriptRoot '..' '..')) + +./Setup.ps1 + +Set-Location $PSScriptRoot + +npm run clean && npm install diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/fluent/models/CustomTemplateResourceInner.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/fluent/models/CustomTemplateResourceInner.java index 5848e6a531..77bc1b99a8 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/fluent/models/CustomTemplateResourceInner.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/fluent/models/CustomTemplateResourceInner.java @@ -11,6 +11,7 @@ import com.cadl.armresourceprovider.models.Dog; import com.cadl.armresourceprovider.models.EmptyModel; import com.cadl.armresourceprovider.models.ManagedServiceIdentity; +import com.cadl.armresourceprovider.models.PriorityModel; import com.cadl.armresourceprovider.models.ProvisioningState; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Map; @@ -179,6 +180,29 @@ public CustomTemplateResourcePropertiesAnonymousEmptyModel anonymousEmptyModel() return this; } + /** + * Get the priority property: The priority property. + * + * @return the priority value. + */ + public PriorityModel priority() { + return this.innerProperties() == null ? null : this.innerProperties().priority(); + } + + /** + * Set the priority property: The priority property. + * + * @param priority the priority value to set. + * @return the CustomTemplateResourceInner object itself. + */ + public CustomTemplateResourceInner withPriority(PriorityModel priority) { + if (this.innerProperties() == null) { + this.innerProperties = new CustomTemplateResourceProperties(); + } + this.innerProperties().withPriority(priority); + return this; + } + /** * Validates the instance. * diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/fluent/models/CustomTemplateResourceProperties.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/fluent/models/CustomTemplateResourceProperties.java index f64a539f5b..80d38de157 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/fluent/models/CustomTemplateResourceProperties.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/fluent/models/CustomTemplateResourceProperties.java @@ -9,6 +9,7 @@ import com.cadl.armresourceprovider.models.CustomTemplateResourcePropertiesAnonymousEmptyModel; import com.cadl.armresourceprovider.models.Dog; import com.cadl.armresourceprovider.models.EmptyModel; +import com.cadl.armresourceprovider.models.PriorityModel; import com.cadl.armresourceprovider.models.ProvisioningState; import com.fasterxml.jackson.annotation.JsonProperty; @@ -41,6 +42,12 @@ public final class CustomTemplateResourceProperties { @JsonProperty(value = "anonymousEmptyModel", required = true) private CustomTemplateResourcePropertiesAnonymousEmptyModel anonymousEmptyModel; + /* + * The priority property. + */ + @JsonProperty(value = "priority", required = true) + private PriorityModel priority; + /** * Creates an instance of CustomTemplateResourceProperties class. */ @@ -117,6 +124,26 @@ public CustomTemplateResourcePropertiesAnonymousEmptyModel anonymousEmptyModel() return this; } + /** + * Get the priority property: The priority property. + * + * @return the priority value. + */ + public PriorityModel priority() { + return this.priority; + } + + /** + * Set the priority property: The priority property. + * + * @param priority the priority value to set. + * @return the CustomTemplateResourceProperties object itself. + */ + public CustomTemplateResourceProperties withPriority(PriorityModel priority) { + this.priority = priority; + return this; + } + /** * Validates the instance. * @@ -144,6 +171,11 @@ public void validate() { } else { anonymousEmptyModel().validate(); } + if (priority() == null) { + throw LOGGER.atError() + .log(new IllegalArgumentException( + "Missing required property priority in model CustomTemplateResourceProperties")); + } } private static final ClientLogger LOGGER = new ClientLogger(CustomTemplateResourceProperties.class); diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/implementation/CustomTemplateResourceImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/implementation/CustomTemplateResourceImpl.java index 7e155b1660..5a372fa11b 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/implementation/CustomTemplateResourceImpl.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/implementation/CustomTemplateResourceImpl.java @@ -14,6 +14,7 @@ import com.cadl.armresourceprovider.models.Dog; import com.cadl.armresourceprovider.models.EmptyModel; import com.cadl.armresourceprovider.models.ManagedServiceIdentity; +import com.cadl.armresourceprovider.models.PriorityModel; import com.cadl.armresourceprovider.models.ProvisioningState; import java.util.Collections; import java.util.Map; @@ -73,6 +74,10 @@ public CustomTemplateResourcePropertiesAnonymousEmptyModel anonymousEmptyModel() return this.innerModel().anonymousEmptyModel(); } + public PriorityModel priority() { + return this.innerModel().priority(); + } + public Region region() { return Region.fromName(this.regionName()); } @@ -201,6 +206,11 @@ public CustomTemplateResourceImpl withNamedEmptyModel(EmptyModel namedEmptyModel return this; } + public CustomTemplateResourceImpl withPriority(PriorityModel priority) { + this.innerModel().withPriority(priority); + return this; + } + public CustomTemplateResourceImpl withIfMatch(String ifMatch) { this.createIfMatch = ifMatch; return this; diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/models/CustomTemplateResource.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/models/CustomTemplateResource.java index 5414d91d9e..189c955ee1 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/models/CustomTemplateResource.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/models/CustomTemplateResource.java @@ -91,6 +91,13 @@ public interface CustomTemplateResource { */ CustomTemplateResourcePropertiesAnonymousEmptyModel anonymousEmptyModel(); + /** + * Gets the priority property: The priority property. + * + * @return the priority value. + */ + PriorityModel priority(); + /** * Gets the region of the resource. * @@ -176,7 +183,7 @@ interface WithResourceGroup { */ interface WithCreate extends DefinitionStages.WithTags, DefinitionStages.WithIdentity, DefinitionStages.WithDog, DefinitionStages.WithNamedEmptyModel, DefinitionStages.WithAnonymousEmptyModel, - DefinitionStages.WithIfMatch, DefinitionStages.WithIfNoneMatch { + DefinitionStages.WithPriority, DefinitionStages.WithIfMatch, DefinitionStages.WithIfNoneMatch { /** * Executes the create request. * @@ -258,6 +265,19 @@ interface WithAnonymousEmptyModel { WithCreate withAnonymousEmptyModel(CustomTemplateResourcePropertiesAnonymousEmptyModel anonymousEmptyModel); } + /** + * The stage of the CustomTemplateResource definition allowing to specify priority. + */ + interface WithPriority { + /** + * Specifies the priority property: The priority property.. + * + * @param priority The priority property. + * @return the next definition stage. + */ + WithCreate withPriority(PriorityModel priority); + } + /** * The stage of the CustomTemplateResource definition allowing to specify ifMatch. */ diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/models/PriorityModel.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/models/PriorityModel.java new file mode 100644 index 0000000000..3819610085 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/armresourceprovider/models/PriorityModel.java @@ -0,0 +1,86 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.cadl.armresourceprovider.models; + +import com.azure.core.util.ExpandableEnum; +import com.fasterxml.jackson.annotation.JsonCreator; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Defines values for PriorityModel. + */ +public final class PriorityModel implements ExpandableEnum { + private static final Map VALUES = new ConcurrentHashMap<>(); + + /** + * Static value 0 for PriorityModel. + */ + public static final PriorityModel HIGH = fromValue(0); + + /** + * Static value 1 for PriorityModel. + */ + public static final PriorityModel LOW = fromValue(1); + + private final Integer value; + + private PriorityModel(Integer value) { + this.value = value; + } + + /** + * Creates or finds a PriorityModel. + * + * @param value a value to look for. + * @return the corresponding PriorityModel. + */ + @JsonCreator + public static PriorityModel fromValue(Integer value) { + Objects.requireNonNull(value, "'value' cannot be null."); + PriorityModel member = VALUES.get(value); + if (member != null) { + return member; + } + return VALUES.computeIfAbsent(value, key -> new PriorityModel(key)); + } + + /** + * Gets known PriorityModel values. + * + * @return Known PriorityModel values. + */ + public static Collection values() { + return new ArrayList<>(VALUES.values()); + } + + /** + * Gets the value of the PriorityModel instance. + * + * @return the value of the PriorityModel instance. + */ + @Override + public Integer getValue() { + return this.value; + } + + @Override + public String toString() { + return Objects.toString(this.value); + } + + @Override + public boolean equals(Object obj) { + return Objects.equals(this.value, obj); + } + + @Override + public int hashCode() { + return Objects.hashCode(this.value); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/EnumServiceAsyncClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/EnumServiceAsyncClient.java index bb668e7c62..75ea8e4b90 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/EnumServiceAsyncClient.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/EnumServiceAsyncClient.java @@ -111,6 +111,8 @@ public Mono> getColorModelWithResponse(RequestOptions reque * colorValue: String(Red/Blue/Green) (Required) * colorModelValue: String(Red/Blue/Green) (Required) * unitValue: String(1/0.001/1000) (Optional) + * olympicRecord: String(9.58/19.3) (Optional) + * olympicRecordValue: String(9.58/19.3) (Optional) * } * } * @@ -146,6 +148,8 @@ public Mono> setColorModelWithResponse(String color, Reques * colorValue: String(Red/Blue/Green) (Required) * colorModelValue: String(Red/Blue/Green) (Required) * unitValue: String(1/0.001/1000) (Optional) + * olympicRecord: String(9.58/19.3) (Optional) + * olympicRecordValue: String(9.58/19.3) (Optional) * } * } * @@ -181,6 +185,8 @@ public Mono> setPriorityWithResponse(String priority, Reque * colorValue: String(Red/Blue/Green) (Required) * colorModelValue: String(Red/Blue/Green) (Required) * unitValue: String(1/0.001/1000) (Optional) + * olympicRecord: String(9.58/19.3) (Optional) + * olympicRecordValue: String(9.58/19.3) (Optional) * } * } * @@ -215,6 +221,8 @@ public Mono> getRunningOperationWithResponse(RequestOptions * colorValue: String(Red/Blue/Green) (Required) * colorModelValue: String(Red/Blue/Green) (Required) * unitValue: String(1/0.001/1000) (Optional) + * olympicRecord: String(9.58/19.3) (Optional) + * olympicRecordValue: String(9.58/19.3) (Optional) * } * } * diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/EnumServiceClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/EnumServiceClient.java index ee216bdba3..9c490aa2a8 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/EnumServiceClient.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/EnumServiceClient.java @@ -109,6 +109,8 @@ public Response getColorModelWithResponse(RequestOptions requestOpti * colorValue: String(Red/Blue/Green) (Required) * colorModelValue: String(Red/Blue/Green) (Required) * unitValue: String(1/0.001/1000) (Optional) + * olympicRecord: String(9.58/19.3) (Optional) + * olympicRecordValue: String(9.58/19.3) (Optional) * } * } * @@ -144,6 +146,8 @@ public Response setColorModelWithResponse(String color, RequestOptio * colorValue: String(Red/Blue/Green) (Required) * colorModelValue: String(Red/Blue/Green) (Required) * unitValue: String(1/0.001/1000) (Optional) + * olympicRecord: String(9.58/19.3) (Optional) + * olympicRecordValue: String(9.58/19.3) (Optional) * } * } * @@ -179,6 +183,8 @@ public Response setPriorityWithResponse(String priority, RequestOpti * colorValue: String(Red/Blue/Green) (Required) * colorModelValue: String(Red/Blue/Green) (Required) * unitValue: String(1/0.001/1000) (Optional) + * olympicRecord: String(9.58/19.3) (Optional) + * olympicRecordValue: String(9.58/19.3) (Optional) * } * } * @@ -213,6 +219,8 @@ public Response getRunningOperationWithResponse(RequestOptions reque * colorValue: String(Red/Blue/Green) (Required) * colorModelValue: String(Red/Blue/Green) (Required) * unitValue: String(1/0.001/1000) (Optional) + * olympicRecord: String(9.58/19.3) (Optional) + * olympicRecordValue: String(9.58/19.3) (Optional) * } * } * diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/implementation/EnumServiceClientImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/implementation/EnumServiceClientImpl.java index 9fbd78c78b..f6d0dd1b99 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/implementation/EnumServiceClientImpl.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/implementation/EnumServiceClientImpl.java @@ -535,6 +535,8 @@ public Response getColorModelWithResponse(RequestOptions requestOpti * colorValue: String(Red/Blue/Green) (Required) * colorModelValue: String(Red/Blue/Green) (Required) * unitValue: String(1/0.001/1000) (Optional) + * olympicRecord: String(9.58/19.3) (Optional) + * olympicRecordValue: String(9.58/19.3) (Optional) * } * } * @@ -571,6 +573,8 @@ public Mono> setColorModelWithResponseAsync(String color, R * colorValue: String(Red/Blue/Green) (Required) * colorModelValue: String(Red/Blue/Green) (Required) * unitValue: String(1/0.001/1000) (Optional) + * olympicRecord: String(9.58/19.3) (Optional) + * olympicRecordValue: String(9.58/19.3) (Optional) * } * } * @@ -606,6 +610,8 @@ public Response setColorModelWithResponse(String color, RequestOptio * colorValue: String(Red/Blue/Green) (Required) * colorModelValue: String(Red/Blue/Green) (Required) * unitValue: String(1/0.001/1000) (Optional) + * olympicRecord: String(9.58/19.3) (Optional) + * olympicRecordValue: String(9.58/19.3) (Optional) * } * } * @@ -642,6 +648,8 @@ public Mono> setPriorityWithResponseAsync(String priority, * colorValue: String(Red/Blue/Green) (Required) * colorModelValue: String(Red/Blue/Green) (Required) * unitValue: String(1/0.001/1000) (Optional) + * olympicRecord: String(9.58/19.3) (Optional) + * olympicRecordValue: String(9.58/19.3) (Optional) * } * } * @@ -677,6 +685,8 @@ public Response setPriorityWithResponse(String priority, RequestOpti * colorValue: String(Red/Blue/Green) (Required) * colorModelValue: String(Red/Blue/Green) (Required) * unitValue: String(1/0.001/1000) (Optional) + * olympicRecord: String(9.58/19.3) (Optional) + * olympicRecordValue: String(9.58/19.3) (Optional) * } * } * @@ -713,6 +723,8 @@ public Mono> getRunningOperationWithResponseAsync(RequestOp * colorValue: String(Red/Blue/Green) (Required) * colorModelValue: String(Red/Blue/Green) (Required) * unitValue: String(1/0.001/1000) (Optional) + * olympicRecord: String(9.58/19.3) (Optional) + * olympicRecordValue: String(9.58/19.3) (Optional) * } * } * @@ -748,6 +760,8 @@ public Response getRunningOperationWithResponse(RequestOptions reque * colorValue: String(Red/Blue/Green) (Required) * colorModelValue: String(Red/Blue/Green) (Required) * unitValue: String(1/0.001/1000) (Optional) + * olympicRecord: String(9.58/19.3) (Optional) + * olympicRecordValue: String(9.58/19.3) (Optional) * } * } * @@ -784,6 +798,8 @@ public Mono> getOperationWithResponseAsync(String state, Re * colorValue: String(Red/Blue/Green) (Required) * colorModelValue: String(Red/Blue/Green) (Required) * unitValue: String(1/0.001/1000) (Optional) + * olympicRecord: String(9.58/19.3) (Optional) + * olympicRecordValue: String(9.58/19.3) (Optional) * } * } * diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/models/OlympicRecordModel.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/models/OlympicRecordModel.java new file mode 100644 index 0000000000..4d11d95a20 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/models/OlympicRecordModel.java @@ -0,0 +1,93 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.cadl.enumservice.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.util.ExpandableEnum; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Defines values for OlympicRecordModel. + */ +public final class OlympicRecordModel implements ExpandableEnum { + private static final Map VALUES = new ConcurrentHashMap<>(); + + /** + * Static value 9.58 for OlympicRecordModel. + */ + @Generated + public static final OlympicRecordModel OLYMPIC_100_METERS = fromValue(9.58); + + /** + * Static value 19.3 for OlympicRecordModel. + */ + @Generated + public static final OlympicRecordModel OLYMPIC_200_METERS = fromValue(19.3); + + private final Double value; + + private OlympicRecordModel(Double value) { + this.value = value; + } + + /** + * Creates or finds a OlympicRecordModel. + * + * @param value a value to look for. + * @return the corresponding OlympicRecordModel. + */ + @Generated + public static OlympicRecordModel fromValue(Double value) { + Objects.requireNonNull(value, "'value' cannot be null."); + OlympicRecordModel member = VALUES.get(value); + if (member != null) { + return member; + } + return VALUES.computeIfAbsent(value, key -> new OlympicRecordModel(key)); + } + + /** + * Gets known OlympicRecordModel values. + * + * @return Known OlympicRecordModel values. + */ + @Generated + public static Collection values() { + return new ArrayList<>(VALUES.values()); + } + + /** + * Gets the value of the OlympicRecordModel instance. + * + * @return the value of the OlympicRecordModel instance. + */ + @Generated + @Override + public Double getValue() { + return this.value; + } + + @Generated + @Override + public String toString() { + return Objects.toString(this.value); + } + + @Generated + @Override + public boolean equals(Object obj) { + return Objects.equals(this.value, obj); + } + + @Generated + @Override + public int hashCode() { + return Objects.hashCode(this.value); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/models/Operation.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/models/Operation.java index ccadb18682..9d7002f5a5 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/models/Operation.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/models/Operation.java @@ -77,6 +77,18 @@ public final class Operation implements JsonSerializable { @Generated private Unit unitValue; + /* + * The olympicRecord property. + */ + @Generated + private OlympicRecordModel olympicRecord; + + /* + * The olympicRecordValue property. + */ + @Generated + private OlympicRecordModel olympicRecordValue; + /** * Creates an instance of Operation class. * @@ -205,6 +217,50 @@ public Operation setUnitValue(Unit unitValue) { return this; } + /** + * Get the olympicRecord property: The olympicRecord property. + * + * @return the olympicRecord value. + */ + @Generated + public OlympicRecordModel getOlympicRecord() { + return this.olympicRecord; + } + + /** + * Set the olympicRecord property: The olympicRecord property. + * + * @param olympicRecord the olympicRecord value to set. + * @return the Operation object itself. + */ + @Generated + public Operation setOlympicRecord(OlympicRecordModel olympicRecord) { + this.olympicRecord = olympicRecord; + return this; + } + + /** + * Get the olympicRecordValue property: The olympicRecordValue property. + * + * @return the olympicRecordValue value. + */ + @Generated + public OlympicRecordModel getOlympicRecordValue() { + return this.olympicRecordValue; + } + + /** + * Set the olympicRecordValue property: The olympicRecordValue property. + * + * @param olympicRecordValue the olympicRecordValue value to set. + * @return the Operation object itself. + */ + @Generated + public Operation setOlympicRecordValue(OlympicRecordModel olympicRecordValue) { + this.olympicRecordValue = olympicRecordValue; + return this; + } + /** * {@inheritDoc} */ @@ -223,6 +279,9 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStringField("colorModelValue", this.colorModelValue == null ? null : this.colorModelValue.toString()); jsonWriter.writeNumberField("unitValue", this.unitValue == null ? null : this.unitValue.toDouble()); + jsonWriter.writeNumberField("olympicRecord", this.olympicRecord == null ? null : this.olympicRecord.getValue()); + jsonWriter.writeNumberField("olympicRecordValue", + this.olympicRecordValue == null ? null : this.olympicRecordValue.getValue()); return jsonWriter.writeEndObject(); } @@ -243,6 +302,8 @@ public static Operation fromJson(JsonReader jsonReader) throws IOException { ColorModel color = null; Unit unit = null; Unit unitValue = null; + OlympicRecordModel olympicRecord = null; + OlympicRecordModel olympicRecordValue = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); @@ -257,12 +318,18 @@ public static Operation fromJson(JsonReader jsonReader) throws IOException { unit = Unit.fromDouble(reader.getDouble()); } else if ("unitValue".equals(fieldName)) { unitValue = Unit.fromDouble(reader.getDouble()); + } else if ("olympicRecord".equals(fieldName)) { + olympicRecord = OlympicRecordModel.fromValue(reader.getDouble()); + } else if ("olympicRecordValue".equals(fieldName)) { + olympicRecordValue = OlympicRecordModel.fromValue(reader.getDouble()); } else { reader.skipChildren(); } } Operation deserializedOperation = new Operation(name, priority, color, unit); deserializedOperation.unitValue = unitValue; + deserializedOperation.olympicRecord = olympicRecord; + deserializedOperation.olympicRecordValue = olympicRecordValue; return deserializedOperation; }); diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/models/PriorityModel.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/models/PriorityModel.java index edfd132508..040b9ecbe8 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/models/PriorityModel.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/cadl/enumservice/models/PriorityModel.java @@ -5,53 +5,89 @@ package com.cadl.enumservice.models; import com.azure.core.annotation.Generated; -import com.azure.core.util.ExpandableStringEnum; +import com.azure.core.util.ExpandableEnum; +import java.util.ArrayList; import java.util.Collection; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; /** * Defines values for PriorityModel. */ -public final class PriorityModel extends ExpandableStringEnum { +public final class PriorityModel implements ExpandableEnum { + private static final Map VALUES = new ConcurrentHashMap<>(); + /** * Static value 100 for PriorityModel. */ @Generated - public static final PriorityModel HIGH = fromInt(100); + public static final PriorityModel HIGH = fromValue(100); /** * Static value 0 for PriorityModel. */ @Generated - public static final PriorityModel LOW = fromInt(0); + public static final PriorityModel LOW = fromValue(0); + + private final Integer value; + + private PriorityModel(Integer value) { + this.value = value; + } /** - * Creates a new instance of PriorityModel value. + * Creates or finds a PriorityModel. * - * @deprecated Use the {@link #fromInt(int)} factory method. + * @param value a value to look for. + * @return the corresponding PriorityModel. */ @Generated - @Deprecated - public PriorityModel() { + public static PriorityModel fromValue(Integer value) { + Objects.requireNonNull(value, "'value' cannot be null."); + PriorityModel member = VALUES.get(value); + if (member != null) { + return member; + } + return VALUES.computeIfAbsent(value, key -> new PriorityModel(key)); } /** - * Creates or finds a PriorityModel from its string representation. + * Gets known PriorityModel values. * - * @param name a name to look for. - * @return the corresponding PriorityModel. + * @return Known PriorityModel values. */ @Generated - public static PriorityModel fromInt(int name) { - return fromString(String.valueOf(name), PriorityModel.class); + public static Collection values() { + return new ArrayList<>(VALUES.values()); } /** - * Gets known PriorityModel values. + * Gets the value of the PriorityModel instance. * - * @return known PriorityModel values. + * @return the value of the PriorityModel instance. */ @Generated - public static Collection values() { - return values(PriorityModel.class); + @Override + public Integer getValue() { + return this.value; + } + + @Generated + @Override + public String toString() { + return Objects.toString(this.value); + } + + @Generated + @Override + public boolean equals(Object obj) { + return Objects.equals(this.value, obj); + } + + @Generated + @Override + public int hashCode() { + return Objects.hashCode(this.value); } } diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Snake.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Snake.java index cea781f69a..062f4a8d3c 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Snake.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Snake.java @@ -21,7 +21,7 @@ public class Snake implements JsonSerializable { * discriminator property */ @Generated - private SnakeKind kind = SnakeKind.fromString("Snake"); + private SnakeKind kind; /* * Length of the snake diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/cadl-enumservice_apiview_properties.json b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/cadl-enumservice_apiview_properties.json index c1425196a7..aa079535b9 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/cadl-enumservice_apiview_properties.json +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/cadl-enumservice_apiview_properties.json @@ -66,6 +66,7 @@ "com.cadl.enumservice.EnumServiceClientBuilder": "Cadl.EnumService.EnumOp", "com.cadl.enumservice.models.Color": "Cadl.EnumService.Color", "com.cadl.enumservice.models.ColorModel": "Cadl.EnumService.ColorModel", + "com.cadl.enumservice.models.OlympicRecordModel": "Cadl.EnumService.OlympicRecordModel", "com.cadl.enumservice.models.Operation": "Cadl.EnumService.Operation", "com.cadl.enumservice.models.OperationName": "Operation.name.anonymous", "com.cadl.enumservice.models.OperationStateValues": "Cadl.EnumService.OperationStateValues", diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armresourceprovider-generated/reflect-config.json b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armresourceprovider-generated/reflect-config.json index 95474aab06..3e2f29f312 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armresourceprovider-generated/reflect-config.json +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armresourceprovider-generated/reflect-config.json @@ -1 +1 @@ -[{"name":"com.cadl.armresourceprovider.fluent.models.ChildExtensionResourceInner","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.ChildResourceInner","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.ChildResourceProperties","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.CustomTemplateResourceInner","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.CustomTemplateResourceProperties","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.OperationInner","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.ResultInner","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.TopLevelArmResourceInner","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.TopLevelArmResourceProperties","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.TopLevelArmResourceUpdateProperties","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.implementation.models.ChildExtensionResourceListResult","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.implementation.models.ChildResourceListResult","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.implementation.models.OperationListResult","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.implementation.models.TopLevelArmResourceListResult","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.ActionType","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.ChildExtensionResourceProperties","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.ChildExtensionResourceUpdate","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.ChildResourceUpdate","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.CustomTemplateResourcePatch","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.CustomTemplateResourcePropertiesAnonymousEmptyModel","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.Dog","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.DogKind","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.EmptyModel","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.Golden","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.ManagedServiceIdentity","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.ManagedServiceIdentityType","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.OperationDisplay","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.Origin","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.ProvisioningState","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.TopLevelArmResourceUpdate","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.UserAssignedIdentity","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true}] \ No newline at end of file +[{"name":"com.cadl.armresourceprovider.fluent.models.ChildExtensionResourceInner","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.ChildResourceInner","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.ChildResourceProperties","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.CustomTemplateResourceInner","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.CustomTemplateResourceProperties","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.OperationInner","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.ResultInner","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.TopLevelArmResourceInner","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.TopLevelArmResourceProperties","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.fluent.models.TopLevelArmResourceUpdateProperties","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.implementation.models.ChildExtensionResourceListResult","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.implementation.models.ChildResourceListResult","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.implementation.models.OperationListResult","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.implementation.models.TopLevelArmResourceListResult","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.ActionType","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.ChildExtensionResourceProperties","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.ChildExtensionResourceUpdate","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.ChildResourceUpdate","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.CustomTemplateResourcePatch","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.CustomTemplateResourcePropertiesAnonymousEmptyModel","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.Dog","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.DogKind","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.EmptyModel","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.Golden","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.ManagedServiceIdentity","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.ManagedServiceIdentityType","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.OperationDisplay","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.Origin","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.PriorityModel","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.ProvisioningState","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.TopLevelArmResourceUpdate","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true},{"name":"com.cadl.armresourceprovider.models.UserAssignedIdentity","allDeclaredConstructors":true,"allDeclaredFields":true,"allDeclaredMethods":true}] \ No newline at end of file diff --git a/packages/http-client-java/generator/http-client-generator-test/tsp/arm.tsp b/packages/http-client-java/generator/http-client-generator-test/tsp/arm.tsp index ef52c170d8..933006b6c6 100644 --- a/packages/http-client-java/generator/http-client-generator-test/tsp/arm.tsp +++ b/packages/http-client-java/generator/http-client-generator-test/tsp/arm.tsp @@ -147,6 +147,7 @@ model CustomTemplateResourceProperties { dog: Dog; namedEmptyModel: EmptyModel; anonymousEmptyModel: {}; + priority: PriorityModel; } @doc("Empty model.") @@ -183,6 +184,12 @@ model Result { reason?: string; } +union PriorityModel { + int32, + HIGH: 0, + LOW: 1, +} + // #suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-envelope-property" "built-in conditional request includes time based conditional headers" alias IfMatchParameters = { @header("If-Match") diff --git a/packages/http-client-java/generator/http-client-generator-test/tsp/enum.tsp b/packages/http-client-java/generator/http-client-generator-test/tsp/enum.tsp index 316447e11b..34de706783 100644 --- a/packages/http-client-java/generator/http-client-generator-test/tsp/enum.tsp +++ b/packages/http-client-java/generator/http-client-generator-test/tsp/enum.tsp @@ -37,6 +37,12 @@ union PriorityModel { Low: 0, } +union OlympicRecordModel { + float32, + Olympic_100_Meters: 9.58, + Olympic_200_Meters: 19.30, +} + #suppress "@azure-tools/typespec-azure-core/use-extensible-enum" "For testing" enum Priority { High: 100, @@ -69,6 +75,8 @@ model Operation { colorValue: Color.Green; colorModelValue: ColorModel.Blue; unitValue?: Unit.Milligram; + olympicRecord?: OlympicRecordModel; + olympicRecordValue?: OlympicRecordModel.Olympic_100_Meters; } @client({