typespec icon indicating copy to clipboard operation
typespec copied to clipboard

Type of model property/enum member when it is defined as constant number

Open haolingdong-msft opened this issue 3 months ago • 6 comments

TSP:

model Operation {
 age: 50;
}

@fixed
enum Priority {
  High: 100,
  Low: 0,
}

For model property/enum member defined as constant number, in above example, Operation.age, Property.High, Priority.Low, how to interprete the type of the property/enum member? Should it be int32 or int64?

If it is interpreted as int32, in the future, if another int64 enum value added, or the model property is set to a int64 number, it would be breaking changes for Java and .Net client code, as the type changed from int to long. If it is interpreted as int64, then we should make sure service understand this and can handle when user passes long value.

To solve this:

  • One solution is to have an explicit way to define the type of the constant number as int32 or int64. Avoid the definition like age: 50 as this is ambiguous.
  • Another solution is to an agreement from TypeSepc level on how to interprete the constant number defined as above, so that service and client can have correct behavior.

Would like to hear your thoughts and suggestions, Thanks.

haolingdong-msft avatar May 10 '24 09:05 haolingdong-msft