You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're using TypeSpec to define a web API. One of the requirements is to add a larger enum to that API. My first, naive approach was the following:
/**
* Enumeration of all possible device types.
*/
enum DeviceType {
/**
* Unknown DeviceType
* UNKNOWN_DEVICETYPE
* */
UnknownDeviceType: -1,
/**
* Some other device type
* OTHER_DEVICETYPE
*/
OtherDeviceType: 0,
/**
* Some fancy device type
* FANCY_DEVICE
*/
SomeFancyDeviceType: 1,
...
}
Now, this code translates into the following using tsp compile and java -jar openapi-generator-cli-7.8.0.jar generate:
DeviceType:
type: number
enum:
- -1
- 0
- 1
This gets converted into the following c# class:
/// <summary>
/// Enumeration of all possible device types based on table `dbo.DeviceTypes`.
/// </summary>
/// <value>Enumeration of all possible device types based on table `dbo.DeviceTypes`.</value>
public enum DeviceType
{
/// <summary>
/// Enum _1Enum for -1
/// </summary>
[EnumMember(Value = "-1")]
_1Enum = 1,
/// <summary>
/// Enum _0Enum for 0
/// </summary>
[EnumMember(Value = "0")]
_0Enum = 2,
/// <summary>
/// Enum _1Enum2 for 1
/// </summary>
[EnumMember(Value = "1")]
_1Enum2 = 3,
...
}
As you can see, no names, no comments, just some weird and useless randomly generated enum members with random numbers. Is there a way to use the generate a proper enum description with TypeSpec?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
We're using TypeSpec to define a web API. One of the requirements is to add a larger enum to that API. My first, naive approach was the following:
Now, this code translates into the following using
tsp compile
andjava -jar openapi-generator-cli-7.8.0.jar generate
:This gets converted into the following c# class:
As you can see, no names, no comments, just some weird and useless randomly generated enum members with random numbers. Is there a way to use the generate a proper enum description with TypeSpec?
Beta Was this translation helpful? Give feedback.
All reactions