swagger 3/OAS 3提交文件数据以及常规数据mutlipart请求

swagger 3/OAS 3提交文件数据以及常规数据mutlipart请求,swagger,Swagger,我有下面的代码addCustomer,用于发送包含图像和其他json数据的请求。当我从swagger hub运行代码时;它只发送json。我的定义正确吗?它不应该发送多部分请求吗 post: tags: - customers summary: Add a new customer to the store description: '' operationId: addCustomer requestBody: content: applicat

我有下面的代码addCustomer,用于发送包含图像和其他json数据的请求。当我从swagger hub运行代码时;它只发送json。我的定义正确吗?它不应该发送多部分请求吗

post:
  tags:
    - customers
  summary: Add a new customer to the store
  description: ''
  operationId: addCustomer
  requestBody:
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/NewCustomerWithImageUrl'
      application/xml:
        schema:
          $ref: '#/components/schemas/NewCustomerWithImageUrl'
      multipart/form-data:
        schema:
          $ref: '#/components/schemas/NewCustomerWithImage'
    description: Customer object that needs to be added to the store
    required: true


NewCustomerWithImage:
  type: object
  allOf:
    - $ref: '#/components/schemas/NewCustomer'
  properties:
    Image:
      type: string
      format: binary

Person:
  type: object
  required:
    - first_name
  properties:
    first_name:
      type: string
      example: John
    last_name:
      type: string
      example: Doe
    email:
      type: string
      example: john@example.com
    phone_number:
      type: string
      example: 555-555-5555
    address_1:
      type: string
      example: 123 Nowhere Street
    address_2:
      type: string
      example: Apartment 123
    city:
      type: string
      example: Rochester
    state:
      type: string
      example: New York
    zip:
      type: string
      example: '14445'
    country:
      type: string
      example: United States
    comments:
      type: string
      example: A great customer
    custom_fields:
      type: object
      minProperties: 0
      maxProperties: 10
      additionalProperties:
        type: string
      example:
        secondary phone number: '555-555-5555'
NewCustomer:
  type: object
  allOf:
    - $ref: '#/components/schemas/Person'
  properties:
    company_name:
      type: string
      example: PHP Point Of Sale
    tier_id:
      type: integer
      format: uuid
      example: 0
    account_number:
      type: string
      example: '3333'
    taxable:
      type: boolean
      example: false
    tax_certificate:
      type: string
      example: '1234'
    override_default_tax:
      type: boolean
      example: false
    tax_class_id:
      type: integer
      format: uuid
      example: 0
    balance: 
      type: number
      format: float
      example: 22.99
    credit_limit:
      example: null
    points:
      type: integer
      format: int32
      example: 333
    disable_loyalty:
      type: boolean 
      example: true
    amount_to_spend_for_next_point:
      type: number
      format: float
      readOnly: true
      example: 10.00
    remaining_sales_before_discount:
      type: integer
      format: int32
      readOnly: true
      example: 0
  xml:  
    name: Customer
已发送Json:

{"first_name":"John","last_name":"Doe","email":"john@example.com","phone_number":"555-555-5555","address_1":"123 Nowhere Street","address_2":"Apartment 123","city":"Rochester","state":"New York","zip":"14445","country":"United States","comments":"A great customer","custom_fields":{"secondary phone number":"555-555-5555"},"company_name":"PHP Point Of Sale","tier_id":0,"account_number":"3333","taxable":false,"tax_certificate":"1234","override_default_tax":false,"tax_class_id":0,"balance":22.99,"credit_limit":null,"points":333,"disable_loyalty":true,"Image":"string"}
Swagger中心文件:

1)Swagger UI(Swagger Hub使用的)尚不支持OpenAPI 3.0定义的表单数据和文件上传。按照本期更新状态:UPD:Swagger用户界面现在支持OAS3文件上传

2) 如果“包含图像和其他JSON数据的请求”是指像这样的
多部分
请求——

POST /foo HTTP/1.1
Content-Type: multipart/form-data; boundary=ABCDEF123

--ABCDEF123
Content-Disposition: form-data; name="Customer"
Content-Type: application/json

{
  "foo": "bar"
}

--ABCDEF123
Content-Disposition: form-data; name="Image"; filename="image1.png"
Content-Type: application/octet-steam

{…image content…}

--ABCDEF123--
那么请求主体定义应该如下所示:

requestBody:
内容:
...
多部分/表单数据:
模式:
类型:对象
特性:

客户:#文件上传在OpenAPI V3.0.3中受支持

下面是我的swagger.json的样子:

"/media/upload": {
      "post": {
        "tags": ["Media"],
        "name": "Upload Media",
        "description": "Uploads a Media file to the server.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "media": {
                    "type": "string",
                    "format": "base64"
                  }
                }
              }
            }
          }
        }
      }
    }
以下是它如何在大摇大摆中表现出来的:


第3节中的两个选项之间有什么区别?我只是想从Person和specific customer字段中附加属性