joolfe / postman-to-openapi

🛸 Convert postman collection to OpenAPI
MIT License
605 stars 105 forks source link

Wrong type when binary file in the request #204

Closed ssduman closed 2 years ago

ssduman commented 2 years ago

Hello,

If we send a file in binary form from Postman, p2o threats it as text/plain. Here is the example Postman and p2o result:

{
    "info": {
        "_postman_id": "daeaed7e-5dee-4aa8-8828-3280afb2b11a",
        "name": "Raw Body",
        "description": "Mi super test collection from postman",
        "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
    },
    "item": [
        {
            "name": "Test Raw Body - File",
            "request": {
                "method": "POST",
                "header": [],
                "body": {
                    "mode": "file",
                    "file": {
                        "src": "AuthBasic.json"
                    }
                },
                "url": {
                    "raw": "https://api.io/file",
                    "protocol": "https",
                    "host": [
                        "api",
                        "io"
                    ],
                    "path": [
                        "file"
                    ]
                }
            },
            "response": []
        }
    ],
    "event": [
        {
            "listen": "prerequest",
            "script": {
                "type": "text/javascript",
                "exec": [
                    ""
                ]
            }
        },
        {
            "listen": "test",
            "script": {
                "type": "text/javascript",
                "exec": [
                    ""
                ]
            }
        }
    ]
}

result:

openapi: 3.0.0
info:
  title: Raw Body
  description: Mi super test collection from postman
  version: 1.0.0
servers:
  - url: https://api.io
paths:
  /file:
    post:
      tags:
        - default
      summary: Test Raw Body - File
      requestBody:
        content:
          text/plain: {}
      responses:
        '200':
          description: Successful response
          content:
            application/json: {}

I believe this behavior due to this line: https://github.com/joolfe/postman-to-openapi/blob/master/lib/index.js#L180

case 'file':
  content = {
    'text/plain': {}
  }
  break

And also, postman and OpenAPI support this: image https://spec.openapis.org/oas/v3.0.3.html#considerations-for-file-uploads Thanks in advance.

joolfe commented 2 years ago

Hi @ssduman,

As described in the documentation the supported body formats are

Support postman “raw” body (Json and Text), “form-data” and “x-www-form-urlencoded”.

So this is just not supported by the library in this moment.

Best regards