typespec icon indicating copy to clipboard operation
typespec copied to clipboard

Cannot specify assertions on array/record elements

Open bojunehsu opened this issue 3 years ago • 2 comments

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 avatar Oct 20 '23 22:10 bojunehsu

@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

markcowl avatar Oct 23 '23 18:10 markcowl

Cllosing as by design

markcowl avatar Nov 06 '23 02:11 markcowl