typespec
typespec copied to clipboard
Type of model property/enum member when it is defined as constant number
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
orint64
. Avoid the definition likeage: 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.