Wiremock-如何匹配JSON中多部分/表单数据的数组元素的所有排列?

时间:2019-08-13 20:00:59

标签: arrays json yaml wiremock

我正在尝试使用JSON Wiremock来模拟YAML API,以用于PUT多部分/表单数据。多部分包含两个元数据数组。我如何匹配每个数组中的一组特定值(或正则表达式),而无视顺序。

我们一定会使用YAML 2.0(如果您想知道),这就是为什么我们为元数据提供了这两个数组的原因。我已经能够成功匹配数组的特定值(例如,对于fileMetadataName,我可以匹配“ permissions,owner”),但是我还没有找到如何匹配所有潜在值的集合(所有5个值可能的排列,请参见下面的YAML。

这是JSON Wiremock文件,可以匹配数组的一种情况:

{
        "request": {
                "method": "PUT",
                "urlPath": "/files",
                "headers": {
                        "Content-Type": { "contains": "multipart/form-data"},
                        "Source": { "matches": "POC(.+)"}
                },
                "multipartPatterns": [
                        {
                                "headers": {
                                        "Content-Disposition": {
                                                "contains": "name=\"typeOfFile\""
                                        }
                                },
                                "bodyPatterns": [ {
                                        "matches": "PDF"
                                } ]
                        },
                        {
                                "headers": {
                                        "Content-Disposition": {
                                                "contains": "name=\"fileMetadataName\""
                                        }
                                },
                                "bodyPatterns": [ {
                                        "matches": "permissions,owner"
                                } ]
                        }
                ]
        },
        "response": {
                "status": 201,
                "jsonBody": {
                        "DocumentId": "123456789-123456789"
                }
        }
}

以下是YAML的摘录,其中描述了多部分输入:

paths:
  '/files':
    put:
      tags:
        - ProofOfConcept
      summary: Upload a file in the files repository
      description: Do the job
      operationId: putFile
      consumes:
        - multipart/form-data
      produces:
        - application/json
      parameters:
        - name: Source
          description: ID of the sender
          in: header
          type: string
          required: true
        - name: theFile
          description: The file to be uploaded
          in: formData
          required: true
          type: file
        - name: typeOfFile
          description: 'File type: PDF, JPG...'
          in: formData
          required: true
          type: string
        - name: fileMetadataName
          description: 'Metadata name. Possible values are: permissions, owner, group, creationDate, appGeneratedId (format: <app-name>;<id>)'
          in: formData
          type: array
          items:
            type: string
        - name: fileMetadataValue
          description: Value associated to the corresponding metadata name
          in: formData
          type: array
          items:
            type: string
      responses:
        '201':
          description: Created
          schema:
            $ref: '#/definitions/DocumentId'

我希望能够匹配fileMetadataName,例如,所有排列:

permissions, owner, group, creationDate, appGeneratedId

对于fileMetadataValue,我希望能够匹配所有排列的正则表达式值(例如,权限为[[0-9] {3,3})。

0 个答案:

没有答案