You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将WebkitFormBoundary转换为Swagger/OpenAPI YAML格式?附具体表单转换示例

Converting WebKitFormBoundary Multipart Form Data to Swagger/OpenAPI YAML

Absolutely! Turning multipart form data (like the WebKitFormBoundary example you shared) into valid Swagger/OpenAPI YAML is straightforward. Let’s break this down—first the general approach, then a direct conversion of your specific form content.

General Method for Conversion

  • Identify the request type: Your content uses multipart/form-data, so in OpenAPI, you’ll define this as the content type under requestBody.
  • Map each form field: Every form-data entry in your WebKitBoundary content translates to a property in the OpenAPI schema.
  • Handle file fields: For file uploads (like your image field), set the schema type to string with format binary, and include details like the example filename and content type.
  • Handle text fields: For plain text fields (like your text field), use a string type and add the example value from your form.

Conversion of Your Specific Form Content

First, here’s your original WebKitFormBoundary content for reference:

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="image"; filename="1.png"
Content-Type: image/png

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="text"

This is a picture of me
------WebKitFormBoundary7MA4YWxkTrZu0gW--

And here’s the equivalent Swagger/OpenAPI 3.0 YAML definition, which you can drop into your spec:

openapi: 3.0.3
info:
  title: Example Multipart Upload API
  version: 1.0.0
paths:
  /upload:
    post:
      summary: Upload an image with accompanying text
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                image:
                  type: string
                  format: binary
                  description: The image file to upload
                  example:
                    filename: 1.png
                    contentType: image/png
                text:
                  type: string
                  description: Descriptive text for the image
                  example: "This is a picture of me"
            encoding:
              image:
                contentType: image/png
      responses:
        '200':
          description: Upload successful
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: "Upload completed"

Key Notes on the Conversion

  • The image field maps directly to your file upload entry—we specify binary format and include the example filename/content type from your original form.
  • The text field uses the exact example text provided in your form.
  • The encoding section explicitly sets the content type for the image, matching what’s in your WebKitBoundary content.

内容的提问来源于stack exchange,提问作者ssDev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 17:07:49