stoplightio / prism

Turn any OpenAPI2/3 and Postman Collection file into an API server with mocking, transformations and validations.
https://stoplight.io/open-source/prism
Apache License 2.0
4.23k stars 344 forks source link

Attempting to upload a binary file stops the Docker image #1773

Open rj93 opened 3 years ago

rj93 commented 3 years ago

Describe the bug

When attempting to hit a file upload endpoint that accepts a binary type, the docker errors and exits.

To Reproduce

  1. Given this OpenAPI document:
openapi: 3.0.3
info:
  title: Spotlight Error Example
  description: "Spotlight Error Example"
  version: 1.0.0

servers:
  - url: https://localhost:4010
    description: Mock server (uses mock data)

paths:
  /file-upload:
    post:
      summary: Upload file
      description: Upload a file
      operationId: uploadFile
      tags: ["Files"]
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
      responses:
        "201":
          description: Successfully uploaded file
          content:
            application/json:
              schema:
                type: object
                properties:
                  url:
                    type: string
                    format: uri
                    description: The URL from which the file can be downloaded.
              example:
                url: https://example.com/image.png
  1. Run Start the docker image:
docker run --rm -v $(pwd):/tmp -p 4010:4010 stoplight/prism:4 mock -h 0.0.0.0 "/tmp/openapi.yaml"
  1. Upload a file:
    curl --location --request POST 'http://localhost:4010/file-upload' \
    --form 'file=@"image.png"'
  2. See error:
    
    $ docker run --rm -v $(pwd):/tmp -p 4010:4010 stoplight/prism:4 mock -h 0.0.0.0 "/tmp/openapi.yaml"
    [2:07:48 PM] › [CLI] …  awaiting  Starting Prism…
    [2:07:49 PM] › [CLI] ℹ  info      POST       http://0.0.0.0:4010/file-upload
    [2:07:49 PM] › [CLI] ▶  start     Prism is listening on http://0.0.0.0:4010

/usr/src/prism/node_modules/split2/index.js:44 push(this, this.mapper(list[i])) ^ SyntaxError: Unexpected token ^ in JSON at position 623220 at Transform.parse [as mapper] () at Transform.transform [as _transform] (/usr/src/prism/node_modules/split2/index.js:44:23) at Transform._read (/usr/src/prism/node_modules/split2/node_modules/readable-stream/lib/_stream_transform.js:177:10) at Transform._write (/usr/src/prism/node_modules/split2/node_modules/readable-stream/lib/_stream_transform.js:164:83) at doWrite (/usr/src/prism/node_modules/split2/node_modules/readable-stream/lib/_stream_writable.js:409:139) at writeOrBuffer (/usr/src/prism/node_modules/split2/node_modules/readable-stream/lib/_stream_writable.js:398:5) at Transform.Writable.write (/usr/src/prism/node_modules/split2/node_modules/readable-stream/lib/_stream_writable.js:307:11) at Socket.ondata (_stream_readable.js:718:22) at Socket.emit (events.js:314:20) at addChunk (_stream_readable.js:297:12)

$


## Expected behavior

1. Docker image not to exit
2. Example response returned:

{ "url": "https://example.com/image.png" }



**Environment (remove any that are not applicable):**
 - Docker version: 4
 - OS: MacOS
 - REST Client: Postman
MetalArend commented 3 years ago

I have the exact same error trace (same files and lines), but with a different unexpected token. I'm not uploading any files, but I'm not sure what is going wrong in the JSON being passed. Is there some way to see the complete "wrong" JSON, maybe in some logs?

grissly-man commented 1 year ago

I have the same error. The error does not seem to occur when the upload is less than ~100kb. The error does not occur when running outside of a docker container (e.g. npx prism mock my-api.yaml allows for essentially an unlimited binary upload)