typespec
typespec copied to clipboard
Cannot specify assertions on array/record elements
In Swagger 2, we can specify constraints on array/additionalProperty elements via:
"fieldConfidence": {
"additionalProperties": {
"maximum": 1,
"minimum": 0,
"type": "number"
},
"polygon": {
"items": {
"minimum": 0,
"type": "number"
},
"type": "array"
}
I do not believe there is a way to express the same concept in TypeSpec. We can define a new scalar, but that would also create a new intermediate definition in the Swagger and SDK. which is not desirable. Perhaps we can do something similar to:
@itemMinValue(0) @itemMaxValue(1)
fieldConfidence: Record<float32>;
@itemMinValue(0)
polygon: float32[];
@bojunehsu The existence of an extra schema in Swagger should not be an issue going forward. We do want tto make sure that DPG emitters handle this as appropriate by language
@markcowl discuss with DPG devs
Cllosing as by design