microsoft / microsoft/typespec

Some float value would map to int in enum values e.g `1.0` -> `1`

Open
#2,240 6 comments 0 reactions 0 assignees View on GitHub
design:needed needs-area
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

See [the example](https://cadlplayground.z22.web.core.windows.net/?c=ZW51bSBJbnRlZ2VyRcQMew0KICBPbmU6IDEsxAtUd286IDLGC2hyZWU6IDMsDQp9DQoNCsU8RmxvYXTQOi4wyzzIDcc%2BxQ%2FFQG1vZGVsIFJlc3VsdMY%2BaW50OuwAjsU5ZsRiOsppxz5Ac2VydmljZSh7fSkNCm5hbWVzcGFjZSBUZXPHTm9wIGdldCgpOsdkOw0KfQ%3D%3D&e=%40typespec%2Fopenapi3&options=%7B%7D) for `FloatEnum` which has values `1.0, 2.0, 3.0` would be mapped to `1, 2, 3`. I think this is incorrect.

```
enum FloatEnum {
One: 1.0,
Two: 2.0,
Three: 3.0,
}
```
swagger spec:

```
FloatEnum:
type: number
enum:
- 1
- 2
- 3
```

Another thing is I notice that the [docs](https://microsoft.github.io/typespec/language-basics/enums#values) guides me following cases but it doesn't work, could you update the docs?

```
enum Hour {
Zero = 0,
Quarter = 0.25,
Half = 0.5,
ThreeQuarter = 0.75,
}
```

![image](https://github.com/microsoft/typespec/assets/9943211/6a7f09b1-e0bd-4be1-acd8-6714e74e9cf6)

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.