swagger-api / swagger-api/swagger-ui

When using oneOf with multipart/form-data the ability to upload a file is incorrectly replaced with a string.

Open
#7,462 1 comment 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
  • OS: Ubuntu 20.04.2 LTS
  • Browser: Chrome
  • Version: Version 92.0.4515.131 (Official Build) (64-bit)
  • Method of installation: https://editor.swagger.io/
  • Swagger-UI version: Whatever is used by the online editor (also effects the latest 3.52.0)
  • Swagger/OpenAPI version: [OpenAPI 3.0]
Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.0.3
info:
  title: SE Demo
  description: Why doesn't this work?
  version: 4.0.0
paths:
  /does_work_common1:
    post:
      summary: This displays
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: "#/components/schemas/Common1Combine"
      responses:
        default:
          description: Doesn't matter
  /does_work_common2:
    post:
      summary: This displays
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: "#/components/schemas/Common2Combine"
      responses:
        default:
          description: Doesn't matter
  /does_not_work_combine:
    post:
      summary: This doesn't display
      requestBody:
        content:
          multipart/form-data:
            schema:
              oneOf:
                - $ref: "#/components/schemas/Common1Combine"
                - $ref: "#/components/schemas/Common2Combine"
      responses:
        default:
          description: Doesn't matter
components:
  schemas:
    Common1Combine:
      allOf:
        - $ref: "#/components/schemas/Common1"
        - $ref: "#/components/schemas/File"
    Common2Combine:
      allOf:
        - $ref: "#/components/schemas/Common2"
        - $ref: "#/components/schemas/File"
    Common1:
      type: object
      properties:
        common:
          type: object
          properties:
            a:
              type: string
              example: val1
            b:
              type: string
              example: val2
    Common2:
      type: object
      properties:
        common:
          type: object
          properties:
            c:
              type: string
              example: val1
            d:
              type: string
              example: val2
    File:
      type: object
      properties:
        core:
          type: string
          description: A zip
          format: binary
Describe the bug you're encountering

When using oneOf with multipart/form-data the ability to upload a file is incorrectly replaced with a string. When clicking does_work_common1's or does_work_common2's "Try it out" button, the common object is displayed and core allows for a file upload as expected. When clicking /does_not_work_combine's "Try it out" button the common object whole definition is json and does not allow for any file upload.

To reproduce...

Steps to reproduce the behavior:

  1. Go to 'https://editor.swagger.io/'
  2. Paste the above swagger yaml
  3. Click on '/does_not_work_combine'
  4. Click on 'Try it out'
  5. Scroll down to 'Request Body'
  6. See that 'core' is treated like a string and does not allow for a file upload.
Expected behavior

For oneOf to choose a ref and then display similar to /does_work_common1.

Screenshots

Screenshot from 2021-08-12 20-53-22
Screenshot from 2021-08-12 20-53-11
Screenshot from 2021-08-12 20-52-09

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin by reproducing the issue in Swagger Editor with the YAML example and compare the working multipart/form-data schemas with the oneOf schema. Trace the request-body rendering path for oneOf/allOf and binary fields; done when the core field in /does_not_work_combine offers file upload behavior like the working endpoints.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.