Skip to content

v2 : OpenAPI 2.0 file Type Parsing Incorrectly Handled #2303

@huaxing-yuan

Description

@huaxing-yuan

Describe the bug
When parsing OpenAPI 2.0 specifications containing parameters with type: file, the library (2.0.0-preview.16) converts these to string type without setting format: binary. In my expectation, when viewing OpenAPI 3.x examples, the old file type should be parsed as string with binary format.

We can take a look at /uploadImage service from petStore example
there is a file parameter of type file

    "/pet/{petId}/uploadImage": {
      "post": {
        "tags": [ "pet" ],
        "summary": "uploads an image",
        "description": "",
        "operationId": "uploadFile",
        "consumes": [ "multipart/form-data" ],
        "produces": [ "application/json" ],
        "parameters": [
          {
            "name": "petId",
            "in": "path",
            "description": "ID of pet to update",
            "required": true,
            "type": "integer",
            "format": "int64"
          },
          {
            "name": "additionalMetadata",
            "in": "formData",
            "description": "Additional data to pass to server",
            "required": false,
            "type": "string"
          },
          {
            "name": "file",
            "in": "formData",
            "description": "file to upload",
            "required": false,
            "type": "file"
          }
        ],

But after debugging, i found this parameter is parsed to string type with format = null.
I didn't find another usable property in schemas to detect it's binary file and not a string.

OpenApi File To Reproduce

  1. Load the PetStore OpenAPI 2.0 example: https://petstore.swagger.io/v2/swagger.json
  2. Examine the /pet/{petId}/uploadImage operation
  3. Observe the file parameter is parsed as:
    type = "string",
    format = null // -> Expected Format = "binary"

Expected behavior
Parameters with type: file in OpenAPI 2.0 should be parsed as:
type = "string",
format = "binary"

Screenshots/Code Snippets

Image

Image

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions