spring-cloud-contract icon indicating copy to clipboard operation
spring-cloud-contract copied to clipboard

Function, that allows multiple files to be passed inside a multipart request

Open tim-hilt opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe.

I'm testing an endpoint of my API using the following contract:

package contracts.setup_plans

import org.springframework.cloud.contract.spec.Contract

Contract.make {
  request {
    method 'POST'
    url '/api/v1/my/endpoint'
    headers {
      contentType 'multipart/form-data'
    }
    multipart(
      images: named(
        name: value(stub(regex('.+')), test('file')),
        content: value(stub(regex('.+')), test(fileAsBytes('files/image.png')))
      )
    )
  }
  response {
    status OK()
    body([
      'http://filehost/files/00001.png'
    ])
  }
}

which works as it should. However, the endpoint actually expects an array of files and I can't seem to find a way to send multiple files in this setup. As far as I understood, neither named(), nor test() accept an array of filenames or something like that.

Describe the solution you'd like

A function that allows accepts either an array of named() function-calls or an array of filenames, so that multiple files can be sent in a request.

Describe alternatives you've considered

Additional context

The endpoint is generated via an OpenAPI-specification, which defines the multipart-body to accept an array of strings, that contain bytes. The following example is taken directly out of the OpenAPI-specifiaction (search for "multipart")

requestBody:
  content:
    multipart/form-data:
      schema:
        properties:
          # The property name 'file' will be used for all files.
          file:
            type: array
            items:
              type: string
              format: binary

tim-hilt avatar Oct 06 '21 11:10 tim-hilt