microsoft / microsoft/typespec
Generate code for TypeSpec "constants"
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
When adding properties decorators, such as: `minItems`, `maxItems`, `minValue`, `maxValue`, `pattern`, etc., I would like to use constants rather than explicit numbers (`@minItems(MinFieldValue)` rather than `@minItems(1)`), and also be able to use this definition in my generated code (using the _typespec-providerhub-controller_ emitter).
Today, using the `alias` keyword (e.g., `alias MinFieldValue = 1`) solves this issue for the TypeSpec but it does not generate corresponding constants in my generated csharp. Therefore, I define these constant twice.
IMO, the following use case should be common: verify that the objects you're building from a customer's request meet the API constraints. Is there a better way to do this (maybe I'm missing some parser configuration)? Would it be a good idea to introduce a `constant` keyword that is represented in _typespec-providerhub-controller_ emitter?
Contributor guide
Assessment
This issue has not been assessed yet.