microsoft / microsoft/typespec

Is it possible to have payload encoded as base64 but has octet-stream content-type ?

Open
#2,615 1 comment 0 reactions 0 assignees View on GitHub
triaged:core
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

As title. I wonder if this is a valid typespec ? [typespec playground link](https://cadlplayground.z22.web.core.windows.net/?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7CtIZcmVzdCI7CgpAc2VydmljZSh7CiAgdGl0bGU6ICJXaWRnZXQgU8YbIiwKfSkKbmFtZXNwYWNlIERlbW%2FHGzsKCnVzaW5nIFR5cGVTcGVjLkh0dHA70BVSZXN0OwoKb3AgYW5hbHl6ZUZyb21TdHJlYW0oCiAgQGRvYygiVGhlIGZvcm1hdCBvZiB0aGUgSFRUUCBwYXlsb2FkLiIpxCpoZWFkZXIKICBjb250ZW50xGM6ICJhcHBsaWNhdGlvbi9vY3RldC1zxV4iLArNYGltYWdlIHRvIGJl6ACLZMZZYm9kecQIZW5jb2RlKCJiYXNlNjTFHMQbOiBieXRlczsKKTogdm9pZDsK&e=%40typespec%2Fopenapi3&options=%7B%22linterRuleSet%22%3A%7B%22extends%22%3A%5B%22%40typespec%2Fhttp%2Fall%22%5D%7D%7D) If yes, should OpenAPI3 emitter output such kind of encoding information?
```
op analyzeFromStream(
@doc("The format of the HTTP payload.")
@header
contentType: "application/octet-stream",

@doc("The image to be analyzed")
@body
@encode("base64")
body: bytes;
): void;
```
The OpenAPI3 emitter output still treats the body as binary.
```yaml
requestBody:
description: The image to be analyzed
required: true
content:
application/octet-stream:
schema:
type: string
format: binary
```

From the openapi3 document here https://swagger.io/docs/specification/describing-request-body/file-upload/ it says the format could be binary or base64 in the application/octet-stream content type?

if we have a self-defined scalar and add the encode info here, it can express base64 encoding with content type of "application/octet-stream" in the openapi3 emitter result. [typespec link](https://cadlplayground.z22.web.core.windows.net/?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7CtIZcmVzdCI7CgpAc2VydmljZSh7CiAgdGl0bGU6ICJXaWRnZXQgU8YbIiwKfSkKbmFtZXNwYWNlIERlbW%2FHGzsKCnVzaW5nIFR5cGVTcGVjLkh0dHA70BVSZXN0xGxlbmNvZGUoImJhc2U2NCIpCnNjYWxhciBCxRBCeXRlcyBleHRlbmRzIGLEDjsKCm9wIGFuYWx5emVGcm9tU3RyZWFtKAogIEBkb2MoIlRoZSBmb3JtYXQgb2YgdGhlIEhUVFAgcGF5bG9hZC4iKcQqaGVhZGVyCiAgY29udGVudOQAmDogImFwcGxpY2F0aW9uL29jdGV0LXPFXiIsCs1gaW1hZ2UgdG8gYmXoAItkxllib2R5CiAgxAc67ADFOwopOiB2b2lkOwo%3D&e=%40typespec%2Fopenapi3&options=%7B%22linterRuleSet%22%3A%7B%22extends%22%3A%5B%22%40typespec%2Fhttp%2Fall%22%5D%7D%7D)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.