microsoft / microsoft/typespec

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

Open
#3,314 14 comments 0 reactions 0 assignees View on GitHub
design:needed docs triaged:core
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

TSP:
```ts
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.