[英]Binary API documentation via swagger
I'm building an API that's able to upload multiple files at once.我正在构建一个能够一次上传多个文件的 API。 I need to document it through swagger, but I have no experience with it at all.
我需要通过 swagger 来记录它,但我根本没有这方面的经验。 My schema for the API is as follows:
我的 API 架构如下:
The http request body is an octet-stream that looks like this. http 请求正文是一个八位字节流,如下所示。 The first 4 bytes represents the number of packages, let the number of packages be n.
前4个字节表示包数,设包数为n。 The next 4*n bytes represents the sizes of the packages, where the first 4 bytes is the size of the first package, the next 4 is the size of the second package, etc. The end of the request simply consists of the packages.
接下来的 4*n 个字节表示包的大小,其中前 4 个字节是第一个包的大小,接下来的 4 个字节是第二个包的大小,依此类推。请求的结尾仅由包组成。
An example would be: The packages \\xDE\\xAD\\xBE\\xEF
and \\xFE\\xED\\xFA\\xCE\\xCA\\xFE\\xBE\\xEF
, would compose the request:一个例子是:包
\\xDE\\xAD\\xBE\\xEF
和\\xFE\\xED\\xFA\\xCE\\xCA\\xFE\\xBE\\xEF
将组成请求:
\x00\x00\x00\x02||\x00\x00\x00\x04\x00\x00\x00\x08||\xDE\xAD\xBE\xEF\xFE\xED\xFA\xCE\xCA\xFE\xBE\xEF
I've tried documenting this in swagger like this:我试过像这样大摇大摆地记录这个:
Batch:
type: object
properties:
header:
description: The number of packages represented in binary (big endian).
type: string
format: binary
maxLength: 8
minLength: 8
example: \x00\x00\x00\x02
subheader:
description: The size of each package, where the size of the first package is represented by the first 4 bytes, the second by the next 4 bytes, etc (big endnian).
type: string
format: binary
maxLength: 4294967295
minLength: 0
example: \x00\x00\x00\x04\x00\x00\x00\x04
data:
description: The data block for encryption/decryption
type: string
format: binary
maxLength: 18446744073709551616
minLength: 0
example: \xDE\xAD\xBE\xEF\xDE\xAD\xBE\xEF
But it shows the request body as a json object (due to type: object
).但它将请求正文显示为 json 对象(由于
type: object
)。 Any ideas on how to do this properly?关于如何正确执行此操作的任何想法?
Octet-stream request body is defined as a single binary string. Octet-stream 请求正文被定义为单个二进制字符串。 There's no way to define the contents/format of specific fragments of the octet-stream.
无法定义八位字节流的特定片段的内容/格式。
minLength
and maxLength
can be used to limit the size of the entire stream. minLength
和maxLength
可用于限制整个流的大小。
Also note that this is OpenAPI 3.0.另请注意,这是 OpenAPI 3.0。 OpenAPI 2.0 does not support
application/octet-stream
payloads (it only supports multipart/form-data
). OpenAPI 2.0 不支持
application/octet-stream
有效负载(它只支持multipart/form-data
)。
openapi: 3.0.2
paths:
/something:
post:
requestBody:
required: true
content:
application/octet-stream:
schema:
type: string
format: binary
maxLength: 12345
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.