Skip to content

Commit

Permalink
tsp, enum is closed enum (#2752)
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored May 11, 2024
1 parent bcb3082 commit 5324fdb
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 185 deletions.
6 changes: 6 additions & 0 deletions typespec-extension/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 0.15.18 (2024-05-13)

Compatible with compiler 0.56.

- `enum` is closed enum.

## 0.15.17 (2024-05-11)

Compatible with compiler 0.56.
Expand Down
4 changes: 2 additions & 2 deletions typespec-extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion typespec-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/typespec-java",
"version": "0.15.17",
"version": "0.15.18",
"description": "TypeSpec library for emitting Java client from the TypeSpec REST protocol binding",
"keywords": [
"TypeSpec"
Expand Down
3 changes: 1 addition & 2 deletions typespec-extension/src/code-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import { Version, getAddedOnVersions, getVersion } from "@typespec/versioning";
import {
isPollingLocation,
getPagedResult,
isFixed,
getLroMetadata,
getUnionAsEnum,
UnionEnum,
Expand Down Expand Up @@ -1726,7 +1725,7 @@ export class CodeModelBuilder {
return this.processConstantSchemaForLiteral(type, nameHint);

case "Enum":
return this.processChoiceSchema(type, this.getName(type), isFixed(this.program, type));
return this.processChoiceSchema(type, this.getName(type), true);

case "Union":
return this.processUnionSchema(type, this.getName(type, nameHint));
Expand Down
2 changes: 1 addition & 1 deletion typespec-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@azure-tools/cadl-ranch-specs": "0.33.4",
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.15.17.tgz"
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.15.18.tgz"
},
"devDependencies": {
"@typespec/prettier-plugin-typespec": "~0.56.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,68 @@

package com.cadl.longrunning.models;

import com.azure.core.annotation.Generated;
import com.azure.core.util.ExpandableStringEnum;
import java.util.Collection;

/**
* Enum describing allowed operation states.
*/
public final class OperationState extends ExpandableStringEnum<OperationState> {
public enum OperationState {
/**
* The operation has not started.
*/
@Generated
public static final OperationState NOT_STARTED = fromString("NotStarted");
NOT_STARTED("NotStarted"),

/**
* The operation is in progress.
*/
@Generated
public static final OperationState RUNNING = fromString("Running");
RUNNING("Running"),

/**
* The operation has completed successfully.
*/
@Generated
public static final OperationState SUCCEEDED = fromString("Succeeded");
SUCCEEDED("Succeeded"),

/**
* The operation has failed.
*/
@Generated
public static final OperationState FAILED = fromString("Failed");
FAILED("Failed"),

/**
* The operation has been canceled by the user.
*/
@Generated
public static final OperationState CANCELED = fromString("Canceled");
CANCELED("Canceled");

/**
* Creates a new instance of OperationState value.
*
* @deprecated Use the {@link #fromString(String)} factory method.
* The actual serialized value for a OperationState instance.
*/
@Generated
@Deprecated
public OperationState() {
private final String value;

OperationState(String value) {
this.value = value;
}

/**
* Creates or finds a OperationState from its string representation.
* Parses a serialized value to a OperationState instance.
*
* @param name a name to look for.
* @return the corresponding OperationState.
* @param value the serialized value to parse.
* @return the parsed OperationState object, or null if unable to parse.
*/
@Generated
public static OperationState fromString(String name) {
return fromString(name, OperationState.class);
public static OperationState fromString(String value) {
if (value == null) {
return null;
}
OperationState[] items = OperationState.values();
for (OperationState item : items) {
if (item.toString().equalsIgnoreCase(value)) {
return item;
}
}
return null;
}

/**
* Gets known OperationState values.
*
* @return known OperationState values.
* {@inheritDoc}
*/
@Generated
public static Collection<OperationState> values() {
return values(OperationState.class);
@Override
public String toString() {
return this.value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,68 @@

package com.cadl.response.models;

import com.azure.core.annotation.Generated;
import com.azure.core.util.ExpandableStringEnum;
import java.util.Collection;

/**
* Enum describing allowed operation states.
*/
public final class OperationState extends ExpandableStringEnum<OperationState> {
public enum OperationState {
/**
* The operation has not started.
*/
@Generated
public static final OperationState NOT_STARTED = fromString("NotStarted");
NOT_STARTED("NotStarted"),

/**
* The operation is in progress.
*/
@Generated
public static final OperationState RUNNING = fromString("Running");
RUNNING("Running"),

/**
* The operation has completed successfully.
*/
@Generated
public static final OperationState SUCCEEDED = fromString("Succeeded");
SUCCEEDED("Succeeded"),

/**
* The operation has failed.
*/
@Generated
public static final OperationState FAILED = fromString("Failed");
FAILED("Failed"),

/**
* The operation has been canceled by the user.
*/
@Generated
public static final OperationState CANCELED = fromString("Canceled");
CANCELED("Canceled");

/**
* Creates a new instance of OperationState value.
*
* @deprecated Use the {@link #fromString(String)} factory method.
* The actual serialized value for a OperationState instance.
*/
@Generated
@Deprecated
public OperationState() {
private final String value;

OperationState(String value) {
this.value = value;
}

/**
* Creates or finds a OperationState from its string representation.
* Parses a serialized value to a OperationState instance.
*
* @param name a name to look for.
* @return the corresponding OperationState.
* @param value the serialized value to parse.
* @return the parsed OperationState object, or null if unable to parse.
*/
@Generated
public static OperationState fromString(String name) {
return fromString(name, OperationState.class);
public static OperationState fromString(String value) {
if (value == null) {
return null;
}
OperationState[] items = OperationState.values();
for (OperationState item : items) {
if (item.toString().equalsIgnoreCase(value)) {
return item;
}
}
return null;
}

/**
* Gets known OperationState values.
*
* @return known OperationState values.
* {@inheritDoc}
*/
@Generated
public static Collection<OperationState> values() {
return values(OperationState.class);
@Override
public String toString() {
return this.value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,53 @@

package com.versioning.added.models;

import com.azure.core.annotation.Generated;
import com.azure.core.util.ExpandableStringEnum;
import java.util.Collection;

/**
* Defines values for EnumV1.
*/
public final class EnumV1 extends ExpandableStringEnum<EnumV1> {
public enum EnumV1 {
/**
* Static value enumMemberV1 for EnumV1.
* Enum value enumMemberV1.
*/
@Generated
public static final EnumV1 ENUM_MEMBER_V1 = fromString("enumMemberV1");
ENUM_MEMBER_V1("enumMemberV1"),

/**
* Static value enumMemberV2 for EnumV1.
* Enum value enumMemberV2.
*/
@Generated
public static final EnumV1 ENUM_MEMBER_V2 = fromString("enumMemberV2");
ENUM_MEMBER_V2("enumMemberV2");

/**
* Creates a new instance of EnumV1 value.
*
* @deprecated Use the {@link #fromString(String)} factory method.
* The actual serialized value for a EnumV1 instance.
*/
@Generated
@Deprecated
public EnumV1() {
private final String value;

EnumV1(String value) {
this.value = value;
}

/**
* Creates or finds a EnumV1 from its string representation.
* Parses a serialized value to a EnumV1 instance.
*
* @param name a name to look for.
* @return the corresponding EnumV1.
* @param value the serialized value to parse.
* @return the parsed EnumV1 object, or null if unable to parse.
*/
@Generated
public static EnumV1 fromString(String name) {
return fromString(name, EnumV1.class);
public static EnumV1 fromString(String value) {
if (value == null) {
return null;
}
EnumV1[] items = EnumV1.values();
for (EnumV1 item : items) {
if (item.toString().equalsIgnoreCase(value)) {
return item;
}
}
return null;
}

/**
* Gets known EnumV1 values.
*
* @return known EnumV1 values.
* {@inheritDoc}
*/
@Generated
public static Collection<EnumV1> values() {
return values(EnumV1.class);
@Override
public String toString() {
return this.value;
}
}
Loading

0 comments on commit 5324fdb

Please sign in to comment.