-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In toJson
, it called non-exist toInt
method on extensible enum whose value is Integer.
#2841
Comments
toJson
, it called non-exist toInt
method on extensible enum whose value is Integer.toJson
, it called non-exist toInt
method on extensible enum whose value is Integer.
Discussed with srikanta, will wait for azure-core support(currently on non-branding). |
TypeSpec@doc("Supported delays for release operation.")
union ReleaseDelay {
int32,
@doc("Release the event after 0 seconds.")
By0Seconds: 0,
@doc("Release the event after 10 seconds.")
By10Seconds: 10,
@doc("Release the event after 60 seconds.")
By60Seconds: 60,
@doc("Release the event after 600 seconds.")
By600Seconds: 600,
@doc("Release the event after 3600 seconds.")
By3600Seconds: 3600,
} GeneratedCodepublic final class ReleaseDelay implements ExpandableEnum<Integer> {
private static final Map<Integer, ReleaseDelay> VALUES = new ConcurrentHashMap<>();
private final Integer value;
private ReleaseDelay(Integer value) {
this.value= value;
}
@Override
public Integer getValue() {
return value;
}
/**
* Gets all known {@link ReleaseDelay} values.
*
* @return The known {@link ReleaseDelay} values.
*/
public static Collection<ReleaseDelay> values() {
return VALUES.values();
}
/**
* Creates or finds a {@link ReleaseDelay} for the passed {@code value}.
*
* <p>{@code null} will be returned if {@code value} is {@code null}.</p>
*
* @param value A value to look for.
*
* @return The corresponding {@link ReleaseDelay} of the provided value, or {@code null} if {@code value} was
* {@code null}.
*/
public static ReleaseDelay fromInt(Integer value) {
if (value == null) {
return null;
}
ReleaseDelay member = VALUES.get(value);
if (member!= null) {
return member;
}
return VALUES.computeIfAbsent(value, ReleaseDelay::new);
}
@Override
public String toString() {
return Objects.toString(value);
}
@Override
public int hashCode() {
return Objects.hashCode(value);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ReleaseDelay)) {
return false;
}
ReleaseDelay other = (ReleaseDelay) obj;
return Objects.equals(value, other.value);
}
/**
* Release the event after 0 seconds.
*/
public static final ReleaseDelay BY0SECONDS= fromInt(0);
/**
* Release the event after 10 seconds.
*/
public static final ReleaseDelay BY10SECONDS = fromInt(10);
/**
* Release the event after 60 seconds.
*/
public static final ReleaseDelay BY60SECONDS = fromInt(60);
/**
* Release the event after 600 seconds.
*/
public static final ReleaseDelay BY600SECONDS = fromInt(600);
/**
* Release the event after 3600 seconds.
*/
public static final ReleaseDelay BY3600SECONDS = fromInt(3600);
} Discussion
|
9-12 discussion conclusion:
|
We should also deal with unbranded. 9-26 discussion:
|
### Issue - Last item of Azure/autorest.java#2841 - Previous unbranded implementation has two major issues - No `equals()` override - Non-string implementation can't compile ### This PR - Apply current branded ExpandableEnum interface implementation to unbranded - `fromString` will be unified as `fromValue`, and will throw if parameter is null(previously will return null) ### Test Tested with openai, no compilation issue found: ```java// Code generated by Microsoft (R) TypeSpec Code Generator. package com.openai; import io.clientcore.core.annotation.Metadata; import io.clientcore.core.util.ExpandableEnum; import java.util.ArrayList; import java.util.Collection; import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; /** * Defines values for OlympicRecordModel. */ public final class OlympicRecordModel implements ExpandableEnum<Double> { private static final Map<Double, OlympicRecordModel> VALUES = new ConcurrentHashMap<>(); private static final Function<Double, OlympicRecordModel> NEW_INSTANCE = OlympicRecordModel::new; /** * Static value 9.58 for OlympicRecordModel. */ @metadata(generated = true) public static final OlympicRecordModel OLYMPIC_100_METERS = fromValue(9.58); /** * Static value 19.3 for OlympicRecordModel. */ @metadata(generated = true) 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. * @throws IllegalArgumentException if value is null. */ @metadata(generated = true) public static OlympicRecordModel fromValue(Double value) { if (value == null) { throw new IllegalArgumentException("'value' cannot be null."); } return VALUES.computeIfAbsent(value, NEW_INSTANCE); } /** * Gets known OlympicRecordModel values. * * @return Known OlympicRecordModel values. */ @metadata(generated = true) public static Collection<OlympicRecordModel> values() { return new ArrayList<>(VALUES.values()); } /** * Gets the value of the OlympicRecordModel instance. * * @return the value of the OlympicRecordModel instance. */ @metadata(generated = true) @OverRide public Double getValue() { return this.value; } @metadata(generated = true) @OverRide public String toString() { return Objects.toString(this.value); } @metadata(generated = true) @OverRide public boolean equals(Object obj) { return this == obj; } @metadata(generated = true) @OverRide public int hashCode() { return Objects.hashCode(this.value); } } ```
) ### Issue - Last item of Azure/autorest.java#2841 - Previous unbranded implementation has two major issues - No `equals()` override - Non-string implementation can't compile ### This PR - Apply current branded ExpandableEnum interface implementation to unbranded - `fromString` will be unified as `fromValue`, and will throw if parameter is null(previously will return null) ### Test Tested with openai, no compilation issue found: ```java// Code generated by Microsoft (R) TypeSpec Code Generator. package com.openai; import io.clientcore.core.annotation.Metadata; import io.clientcore.core.util.ExpandableEnum; import java.util.ArrayList; import java.util.Collection; import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; /** * Defines values for OlympicRecordModel. */ public final class OlympicRecordModel implements ExpandableEnum<Double> { private static final Map<Double, OlympicRecordModel> VALUES = new ConcurrentHashMap<>(); private static final Function<Double, OlympicRecordModel> NEW_INSTANCE = OlympicRecordModel::new; /** * Static value 9.58 for OlympicRecordModel. */ @metadata(generated = true) public static final OlympicRecordModel OLYMPIC_100_METERS = fromValue(9.58); /** * Static value 19.3 for OlympicRecordModel. */ @metadata(generated = true) 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. * @throws IllegalArgumentException if value is null. */ @metadata(generated = true) public static OlympicRecordModel fromValue(Double value) { if (value == null) { throw new IllegalArgumentException("'value' cannot be null."); } return VALUES.computeIfAbsent(value, NEW_INSTANCE); } /** * Gets known OlympicRecordModel values. * * @return Known OlympicRecordModel values. */ @metadata(generated = true) public static Collection<OlympicRecordModel> values() { return new ArrayList<>(VALUES.values()); } /** * Gets the value of the OlympicRecordModel instance. * * @return the value of the OlympicRecordModel instance. */ @metadata(generated = true) @OverRide public Double getValue() { return this.value; } @metadata(generated = true) @OverRide public String toString() { return Objects.toString(this.value); } @metadata(generated = true) @OverRide public boolean equals(Object obj) { return this == obj; } @metadata(generated = true) @OverRide public int hashCode() { return Objects.hashCode(this.value); } } ```
Swagger:
https://github.com/Azure/azure-rest-api-specs/blob/1cb8cb0a95c20513c5d767614888f415be99245d/specification/storagemover/resource-manager/Microsoft.StorageMover/stable/2024-07-01/storagemover.json#L1853-L1856
In
toJson
, we are doing:Tasks
The text was updated successfully, but these errors were encountered: