typespec icon indicating copy to clipboard operation
typespec copied to clipboard

Generate code for TypeSpec "constants"

Open Yosi-Hezi opened this issue 3 years ago • 0 comments

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?

Yosi-Hezi avatar Jul 29 '23 07:07 Yosi-Hezi