microsoft / typespec

https://typespec.io/
MIT License
4.47k stars 210 forks source link

Should a enum be allowed for the value of the content type header #2727

Open timotheeguerin opened 11 months ago

timotheeguerin commented 11 months ago
op test(@header contentType: ImagesContentTypes, @body body: bytes): void;

enum ImagesContentTypes {
  `image/png`,
  `image/jpeg`,
}

Right now we report an error for this. Playground Link

timotheeguerin commented 10 months ago

est: 5

swathipil commented 9 months ago

Hey @timotheeguerin - any updates on this?

timotheeguerin commented 9 months ago

@swathipil this is on the backlog and hasn't been planned to be worked on, can you share more about your use case and why you need an enum here and the union wouldn't work?

catalinaperalta commented 9 months ago

Similar to what @swathipil ran into with Schema Registry, the Purview Datamap team also ran into an issue with the following TypeSpec auth definition: https://github.com/Azure/azure-rest-api-specs/blob/a371356b8bd9f1417c4dca1bbfce42f4044b57ac/specification/purview/Azure.Analytics.Purview.DataMap/main.tsp#L37-L44

Which generated the following model openapi.json: https://github.com/Azure/azure-rest-api-specs/blob/a371356b8bd9f1417c4dca1bbfce42f4044b57ac/specification/purview/data-plane/Azure.Analytics.Purview.DataMap/stable/2023-09-01/openapi.json#L7231

That resulted in the following CI error:

❌ XmsEnumValidation | The enum types should have x-ms-enum type extension set with appropriate options.Location: Azure.Analytics.Purview.DataMap/stable/2023-09-01/openapi.json#L7235 -- | --

When can we expect a fix for this issue?

timotheeguerin commented 9 months ago

Hey @catalinaperalta not sure how this is related to this issue. For this one you either set omit-unreachable-types:true for autorest emitter or move the model out of the service namespace

swathipil commented 4 months ago

Hi @timotheeguerin - sorry for the late response! I didn't get a notification that I was tagged for some reason.

I believe that I originally asked for updates in case this issue was related to #2853, which is blocking us. More info on that in the issue. Thanks!