postmanlabs / openapi-to-postman

Plugin for converting OpenAPI 3.0 specs to the Postman Collection (v2) format
Apache License 2.0
908 stars 195 forks source link

Text format used instead of file for binary fields in form-data #795

Closed dvacca-onfido closed 3 weeks ago

dvacca-onfido commented 2 months ago

Whenever a binary field is included in a request-body ("type": "string", "format": "binary"), e.g.:

  "requestBody": {
    "required": true,
    "content": {
      "multipart/form-data": {
        "schema": {
          "properties": {
            "inputfile": {
              "type": "string",
              "format": "binary",
              "description": "The file to be uploaded."
            }
          }
        }
      }
    }
  },

That's is wrongly converted into a text field ("type": "text" instead of "type": "file"), with an value field ("value": "<string>") which should perhaps be dropped:

  "method": "POST",
  "body": {
      "mode": "formdata",
      "formdata": [
          {
              "description": {
                  "content": "The file to be uploaded.",
                  "type": "text/plain"
              },
              "key": "inputfile",
              "value": "<string>",
              "type": "text"
          }
      ]
  }

This seems to be a regression of interface v2 compared with v1; for v1 fix below (not present in v2) has been found: https://github.com/postmanlabs/openapi-to-postman/commit/c3382897ea0334b1753bcd6c75887669de4e7110

Version: 4.21.0

To reproduce:

npx openapi2postmanv2 -s minimal-openapi.json -o minimal-collection-v2.json -i v2 -p
npx openapi2postmanv2 -s minimal-openapi.json -o minimal-collection-v1.json -i v1 -p

minimal-collection-v1.json minimal-collection-v2.json minimal-openapi.json

VShingala commented 1 month ago

@dvacca-onfido Thanks for reporting the issue! We'll work on the fix for this soon and inform here once this is fixed.

thim81 commented 1 month ago

@VShingala & @dvacca-onfido I created PR, which should solve the reported issue. I used your provided openapi as input for a test.

dvacca-onfido commented 1 month ago

@VShingala & @dvacca-onfido I created PR, which should solve the reported issue. I used your provided openapi as input for a test.

LGTM, thanks @thim81

dvacca-onfido commented 3 weeks ago

Issue is solved after https://github.com/postmanlabs/openapi-to-postman/pull/805