简体   繁体   English

通过 swagger 的二进制 API 文档

[英]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. minLengthmaxLength可用于限制整个流的大小。

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.

相关问题 为Swagger文档实现OAuth2时出错 - Error in implementing OAuth2 for Swagger Documentation of an API swagger API 文档和我自己的 yaml 文件 - swagger API documentation with my own yaml file 使用Swagger文档将API文档添加到网站 - Add API documentation to website using Swagger document API文档-Django Rest Swagger-GET和POST的不同参数 - API Documentation - Django Rest Swagger - Different params for GET and POST 如何在swagger API文档中添加更多参数 - How to add some more parameter in swagger api documentation 如何共享 Swagger 文档 - How to share Swagger documentation 在哪里可以找到IBM Cloud IAM Identity Services API的Swagger文档(JSON doc) - Where can I find the Swagger documentation (JSON doc) for the IBM Cloud IAM Identity Services API Swagger API文档和flask-restplus:如何在请求主体中使用键表示对象 - Swagger API documentation and flask-restplus: How to represent an object with a key in the body of a request 如何使用 Swashbuckle 在 Swagger API 文档/OpenAPI 规范中包含子类? - How do I include subclasses in Swagger API documentation/ OpenAPI specification using Swashbuckle? 使用Swashbuckle Swagger创建Web API文档时,如何为每个控制器使用单独的URL? - How to have separate URLs for each controller when creating Web API documentation using Swashbuckle Swagger?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM