microsoft / microsoft/typespec
`bytes` and `application/json` content type inconistencies
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
If you have both of those they get treated differently
```tsp
op a(@header contentType: "application/json;charset=utf-8", @body body: bytes): void;
op b(@header contentType: "application/json", @body body: bytes): void;
```
in the first case it see is as a binary payload(that should be json)
in the 2nd is see it as a json base64 encoded string of the value passed
[Playground Link](https://typespec.io/playground?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7Cgp1c2luZyBUeXBlU3BlYy5IdHRwOwoKQHJvdXRlKCJhIikKb3AgYSgKICBAaGVhZGVyIGNvbnRlbnTEMzogImFwcGxpY2F0aW9uL2pzb247Y2hhcnNldD11dGYtOCIsxDlib2R5IMQFOiBieXRlcywKKTogdm9pZDvJaWLGaWIo32bHZiIs0lbJVA%3D%3D&e=%40typespec%2Fopenapi3&options=%7B%22linterRuleSet%22%3A%7B%22extends%22%3A%5B%22%40typespec%2Fhttp%2Fall%22%5D%7D%7D)
There is a few things that are established that result in this behavior
- default content type is application/json
- `bytes` in a json object is a base64 encoded string of the bytes
- we only do this special treatment if content type is exactly `application/json`
Maybe we need to parse the content type to figure out the real media type without the attributes
However it is also weird that you can't just say this is a json file without defining the structure of it
Contributor guide
Assessment
This issue has not been assessed yet.