Skip to content

Commit 5324fdb

Browse files
tsp, enum is closed enum (#2752)
1 parent bcb3082 commit 5324fdb

File tree

14 files changed

+175
-185
lines changed

14 files changed

+175
-185
lines changed

typespec-extension/changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release History
22

3+
## 0.15.18 (2024-05-13)
4+
5+
Compatible with compiler 0.56.
6+
7+
- `enum` is closed enum.
8+
39
## 0.15.17 (2024-05-11)
410

511
Compatible with compiler 0.56.

typespec-extension/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typespec-extension/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure-tools/typespec-java",
3-
"version": "0.15.17",
3+
"version": "0.15.18",
44
"description": "TypeSpec library for emitting Java client from the TypeSpec REST protocol binding",
55
"keywords": [
66
"TypeSpec"

typespec-extension/src/code-model-builder.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import { Version, getAddedOnVersions, getVersion } from "@typespec/versioning";
6161
import {
6262
isPollingLocation,
6363
getPagedResult,
64-
isFixed,
6564
getLroMetadata,
6665
getUnionAsEnum,
6766
UnionEnum,
@@ -1726,7 +1725,7 @@ export class CodeModelBuilder {
17261725
return this.processConstantSchemaForLiteral(type, nameHint);
17271726

17281727
case "Enum":
1729-
return this.processChoiceSchema(type, this.getName(type), isFixed(this.program, type));
1728+
return this.processChoiceSchema(type, this.getName(type), true);
17301729

17311730
case "Union":
17321731
return this.processUnionSchema(type, this.getName(type, nameHint));

typespec-tests/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"dependencies": {
1212
"@azure-tools/cadl-ranch-specs": "0.33.4",
13-
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.15.17.tgz"
13+
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.15.18.tgz"
1414
},
1515
"devDependencies": {
1616
"@typespec/prettier-plugin-typespec": "~0.56.0",

typespec-tests/src/main/java/com/cadl/longrunning/models/OperationState.java

+29-33
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,68 @@
44

55
package com.cadl.longrunning.models;
66

7-
import com.azure.core.annotation.Generated;
8-
import com.azure.core.util.ExpandableStringEnum;
9-
import java.util.Collection;
10-
117
/**
128
* Enum describing allowed operation states.
139
*/
14-
public final class OperationState extends ExpandableStringEnum<OperationState> {
10+
public enum OperationState {
1511
/**
1612
* The operation has not started.
1713
*/
18-
@Generated
19-
public static final OperationState NOT_STARTED = fromString("NotStarted");
14+
NOT_STARTED("NotStarted"),
2015

2116
/**
2217
* The operation is in progress.
2318
*/
24-
@Generated
25-
public static final OperationState RUNNING = fromString("Running");
19+
RUNNING("Running"),
2620

2721
/**
2822
* The operation has completed successfully.
2923
*/
30-
@Generated
31-
public static final OperationState SUCCEEDED = fromString("Succeeded");
24+
SUCCEEDED("Succeeded"),
3225

3326
/**
3427
* The operation has failed.
3528
*/
36-
@Generated
37-
public static final OperationState FAILED = fromString("Failed");
29+
FAILED("Failed"),
3830

3931
/**
4032
* The operation has been canceled by the user.
4133
*/
42-
@Generated
43-
public static final OperationState CANCELED = fromString("Canceled");
34+
CANCELED("Canceled");
4435

4536
/**
46-
* Creates a new instance of OperationState value.
47-
*
48-
* @deprecated Use the {@link #fromString(String)} factory method.
37+
* The actual serialized value for a OperationState instance.
4938
*/
50-
@Generated
51-
@Deprecated
52-
public OperationState() {
39+
private final String value;
40+
41+
OperationState(String value) {
42+
this.value = value;
5343
}
5444

5545
/**
56-
* Creates or finds a OperationState from its string representation.
46+
* Parses a serialized value to a OperationState instance.
5747
*
58-
* @param name a name to look for.
59-
* @return the corresponding OperationState.
48+
* @param value the serialized value to parse.
49+
* @return the parsed OperationState object, or null if unable to parse.
6050
*/
61-
@Generated
62-
public static OperationState fromString(String name) {
63-
return fromString(name, OperationState.class);
51+
public static OperationState fromString(String value) {
52+
if (value == null) {
53+
return null;
54+
}
55+
OperationState[] items = OperationState.values();
56+
for (OperationState item : items) {
57+
if (item.toString().equalsIgnoreCase(value)) {
58+
return item;
59+
}
60+
}
61+
return null;
6462
}
6563

6664
/**
67-
* Gets known OperationState values.
68-
*
69-
* @return known OperationState values.
65+
* {@inheritDoc}
7066
*/
71-
@Generated
72-
public static Collection<OperationState> values() {
73-
return values(OperationState.class);
67+
@Override
68+
public String toString() {
69+
return this.value;
7470
}
7571
}

typespec-tests/src/main/java/com/cadl/response/models/OperationState.java

+29-33
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,68 @@
44

55
package com.cadl.response.models;
66

7-
import com.azure.core.annotation.Generated;
8-
import com.azure.core.util.ExpandableStringEnum;
9-
import java.util.Collection;
10-
117
/**
128
* Enum describing allowed operation states.
139
*/
14-
public final class OperationState extends ExpandableStringEnum<OperationState> {
10+
public enum OperationState {
1511
/**
1612
* The operation has not started.
1713
*/
18-
@Generated
19-
public static final OperationState NOT_STARTED = fromString("NotStarted");
14+
NOT_STARTED("NotStarted"),
2015

2116
/**
2217
* The operation is in progress.
2318
*/
24-
@Generated
25-
public static final OperationState RUNNING = fromString("Running");
19+
RUNNING("Running"),
2620

2721
/**
2822
* The operation has completed successfully.
2923
*/
30-
@Generated
31-
public static final OperationState SUCCEEDED = fromString("Succeeded");
24+
SUCCEEDED("Succeeded"),
3225

3326
/**
3427
* The operation has failed.
3528
*/
36-
@Generated
37-
public static final OperationState FAILED = fromString("Failed");
29+
FAILED("Failed"),
3830

3931
/**
4032
* The operation has been canceled by the user.
4133
*/
42-
@Generated
43-
public static final OperationState CANCELED = fromString("Canceled");
34+
CANCELED("Canceled");
4435

4536
/**
46-
* Creates a new instance of OperationState value.
47-
*
48-
* @deprecated Use the {@link #fromString(String)} factory method.
37+
* The actual serialized value for a OperationState instance.
4938
*/
50-
@Generated
51-
@Deprecated
52-
public OperationState() {
39+
private final String value;
40+
41+
OperationState(String value) {
42+
this.value = value;
5343
}
5444

5545
/**
56-
* Creates or finds a OperationState from its string representation.
46+
* Parses a serialized value to a OperationState instance.
5747
*
58-
* @param name a name to look for.
59-
* @return the corresponding OperationState.
48+
* @param value the serialized value to parse.
49+
* @return the parsed OperationState object, or null if unable to parse.
6050
*/
61-
@Generated
62-
public static OperationState fromString(String name) {
63-
return fromString(name, OperationState.class);
51+
public static OperationState fromString(String value) {
52+
if (value == null) {
53+
return null;
54+
}
55+
OperationState[] items = OperationState.values();
56+
for (OperationState item : items) {
57+
if (item.toString().equalsIgnoreCase(value)) {
58+
return item;
59+
}
60+
}
61+
return null;
6462
}
6563

6664
/**
67-
* Gets known OperationState values.
68-
*
69-
* @return known OperationState values.
65+
* {@inheritDoc}
7066
*/
71-
@Generated
72-
public static Collection<OperationState> values() {
73-
return values(OperationState.class);
67+
@Override
68+
public String toString() {
69+
return this.value;
7470
}
7571
}

typespec-tests/src/main/java/com/versioning/added/models/EnumV1.java

+28-29
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,53 @@
44

55
package com.versioning.added.models;
66

7-
import com.azure.core.annotation.Generated;
8-
import com.azure.core.util.ExpandableStringEnum;
9-
import java.util.Collection;
10-
117
/**
128
* Defines values for EnumV1.
139
*/
14-
public final class EnumV1 extends ExpandableStringEnum<EnumV1> {
10+
public enum EnumV1 {
1511
/**
16-
* Static value enumMemberV1 for EnumV1.
12+
* Enum value enumMemberV1.
1713
*/
18-
@Generated
19-
public static final EnumV1 ENUM_MEMBER_V1 = fromString("enumMemberV1");
14+
ENUM_MEMBER_V1("enumMemberV1"),
2015

2116
/**
22-
* Static value enumMemberV2 for EnumV1.
17+
* Enum value enumMemberV2.
2318
*/
24-
@Generated
25-
public static final EnumV1 ENUM_MEMBER_V2 = fromString("enumMemberV2");
19+
ENUM_MEMBER_V2("enumMemberV2");
2620

2721
/**
28-
* Creates a new instance of EnumV1 value.
29-
*
30-
* @deprecated Use the {@link #fromString(String)} factory method.
22+
* The actual serialized value for a EnumV1 instance.
3123
*/
32-
@Generated
33-
@Deprecated
34-
public EnumV1() {
24+
private final String value;
25+
26+
EnumV1(String value) {
27+
this.value = value;
3528
}
3629

3730
/**
38-
* Creates or finds a EnumV1 from its string representation.
31+
* Parses a serialized value to a EnumV1 instance.
3932
*
40-
* @param name a name to look for.
41-
* @return the corresponding EnumV1.
33+
* @param value the serialized value to parse.
34+
* @return the parsed EnumV1 object, or null if unable to parse.
4235
*/
43-
@Generated
44-
public static EnumV1 fromString(String name) {
45-
return fromString(name, EnumV1.class);
36+
public static EnumV1 fromString(String value) {
37+
if (value == null) {
38+
return null;
39+
}
40+
EnumV1[] items = EnumV1.values();
41+
for (EnumV1 item : items) {
42+
if (item.toString().equalsIgnoreCase(value)) {
43+
return item;
44+
}
45+
}
46+
return null;
4647
}
4748

4849
/**
49-
* Gets known EnumV1 values.
50-
*
51-
* @return known EnumV1 values.
50+
* {@inheritDoc}
5251
*/
53-
@Generated
54-
public static Collection<EnumV1> values() {
55-
return values(EnumV1.class);
52+
@Override
53+
public String toString() {
54+
return this.value;
5655
}
5756
}

0 commit comments

Comments
 (0)