PayU / openapi-validator-middleware

Input validation using Swagger (Open API) and ajv
Apache License 2.0
144 stars 50 forks source link

Regression? Express + OpenAPI 3.0 + Multer + multipart/form-data rejects valid file #165

Open Striar-Yunis opened 3 years ago

Striar-Yunis commented 3 years ago

Reproduction

Note: I have created a minimal reproducible example in CodeSandBox. To use this example:

System Description

Issue Description

The validation middleware isn't accepting files that are defined in the OpenAPI yaml. The files are correctly parsed by multer but they are marked as extra.

Swagger

openapi: 3.0.3
info:
  title: Swagger 3 File Upload Fails
  description: Why doesn't this work?
  version: "1.0"
paths:
  /example:
    post:
      summary: This displays
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                core:
                  type: string
                  format: binary
      responses:
        default:
          description: Doesn't matter

OpenApiValidator Config

{
  framework: "express",
  beautifyErrors: true,
  expectFormFieldsInBody: true
}

Curl

curl -X POST --form 'core=@/home/...YOUR_PATH.../core' https://GET_URL_FROM_ADDRESS_BAR/example

The Error

["body/files Extra files are not allowed. Not allowed files: core"]
AdaoBMF commented 2 months ago

Probably solved already but, in case someone gets here with the same issue you should use the property "file" instead of "core". like:

      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary