Skip to content

File upload on the V3 spec through multipart/form-data is OK but disappears on the V2 spec #365

@justinyoo

Description

@justinyoo

Describe the issue

When the OpenAPI doc is rendered through the v3 spec, the multipart/form-data request body is rendered correctly. However, when it's rendered through the v2 spec, the request body is missing.

To Reproduce
Steps to reproduce the behavior:

  1. Build a function app containing a file upload field in a request body through the multipart/form-data content type.
  2. Run the function app.
  3. Access the OpenAPI document through http://localhost:7071/api/openapi/v3.json
  4. Confirm whether it renders correctly.
  5. Access the OpenAPI document through http://localhost:7071/api/openapi/v2.json
  6. Confirm whether the request body is missing.

Expected behavior

The request body should be converted to the parameters, with the in value of file, in the v2 spec.

Screenshots

When it uses the OpenAPI v3 spec, the request body is rendered with no issue.

{
  "openapi": "3.0.1",
  "paths": {
    "/pet/{petId}/uploadImage": {
      "post": {
        "operationId": "uploadFile",
        "parameters": [
        ],
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/petFormData"
              }
            }
          }
        },
      }
    },
  },
  "components": {
    "schemas": {
      "petFormData": {
        "type": "object",
        "properties": {
          "additionalMetadata": {
            "type": "string",
            "description": "Additional data to pass to server"
          },
          "file": {
            "type": "string",
            "description": "File to upload",
            "format": "binary"
          }
        }
      }
    }
  }
}

However, when it uses the OpenAPI spec v2, the request body is missing – it should be converted to a parameter of file.

{
  "swagger": "2.0",
  "paths": {
    "/pet/{petId}/uploadImage": {
      "post": {
        "operationId": "uploadFile",
        "consumes": [
          "multipart/form-data"
        ],
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "petId",
            "required": true,
            "type": "integer",
            "format": "int64"
          }
        ]
      }
    }
  },
  "definitions": {
    "petFormData": {
      "type": "object",
      "properties": {
        "additionalMetadata": {
          "description": "Additional data to pass to server",
          "type": "string"
        },
        "file": {
          "format": "binary",
          "description": "File to upload",
          "type": "string"
        }
      }
    }
  }
}

Additional context

It's because the referencing NuGet package, OpenAPI.NET v1.2.3 doesn't pick up the request body schema reference. This PR over OpenAPI.NET partially fixed this issue – it only looked after the request body properties, not reference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions