-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix binary request & response openapi (#125)
- Loading branch information
1 parent
5713554
commit a6831d1
Showing
6 changed files
with
311 additions
and
5 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
common/changes/@cadl-lang/openapi3/fix-binary-response_2021-12-10-22-56.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@cadl-lang/openapi3", | ||
"comment": "**Fix** issue with @body body: bytes producing `type: string, format: bytes` instead of `type: string, format: binary` for requests and responses", | ||
"type": "patch" | ||
} | ||
], | ||
"packageName": "@cadl-lang/openapi3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import "@cadl-lang/rest"; | ||
|
||
using Cadl.Http; | ||
|
||
model HasBytes { | ||
bytes: bytes; | ||
} | ||
|
||
model BytesBody<ContentType> { | ||
@body body: bytes; | ||
@header contentType: ContentType; | ||
} | ||
|
||
@route("/test") | ||
namespace BytesMethod { | ||
@route("base64") | ||
@post | ||
op jsonWithBase64(@body body: HasBytes): HasBytes; | ||
|
||
@route("textPlain") | ||
@post | ||
op textPlain(...BytesBody<"text/plain">): BytesBody<"text/plain">; | ||
|
||
@route("binaryFile") | ||
@post | ||
op genericBinaryFile( | ||
...BytesBody<"application/octect-stream"> | ||
): BytesBody<"application/octect-stream">; | ||
|
||
@route("imagePng") | ||
@post | ||
op image(...BytesBody<"image/png">): BytesBody<"image/png">; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "./binary.cadl"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
{ | ||
"openapi": "3.0.0", | ||
"info": { | ||
"title": "(title)", | ||
"version": "0000-00-00" | ||
}, | ||
"tags": [], | ||
"paths": { | ||
"/test/base64": { | ||
"post": { | ||
"operationId": "BytesMethod_jsonWithBase64", | ||
"parameters": [], | ||
"responses": { | ||
"200": { | ||
"description": "A successful response", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/HasBytes" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"requestBody": { | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/HasBytes" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/test/textPlain": { | ||
"post": { | ||
"operationId": "BytesMethod_textPlain", | ||
"parameters": [], | ||
"responses": { | ||
"200": { | ||
"description": "A successful response", | ||
"content": { | ||
"text/plain": { | ||
"schema": { | ||
"type": "string", | ||
"format": "byte" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"requestBody": { | ||
"content": { | ||
"text/plain": { | ||
"schema": { | ||
"type": "string", | ||
"format": "byte" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/test/binaryFile": { | ||
"post": { | ||
"operationId": "BytesMethod_genericBinaryFile", | ||
"parameters": [], | ||
"responses": { | ||
"200": { | ||
"description": "A successful response", | ||
"content": { | ||
"application/octect-stream": { | ||
"schema": { | ||
"type": "string", | ||
"format": "binary" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"requestBody": { | ||
"content": { | ||
"application/octect-stream": { | ||
"schema": { | ||
"type": "string", | ||
"format": "binary" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/test/imagePng": { | ||
"post": { | ||
"operationId": "BytesMethod_image", | ||
"parameters": [], | ||
"responses": { | ||
"200": { | ||
"description": "A successful response", | ||
"content": { | ||
"image/png": { | ||
"schema": { | ||
"type": "string", | ||
"format": "binary" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"requestBody": { | ||
"content": { | ||
"image/png": { | ||
"schema": { | ||
"type": "string", | ||
"format": "binary" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"HasBytes": { | ||
"type": "object", | ||
"properties": { | ||
"bytes": { | ||
"type": "string", | ||
"format": "byte" | ||
} | ||
}, | ||
"required": [ | ||
"bytes" | ||
] | ||
} | ||
} | ||
} | ||
} |