2

我正在使用 WireMock (Docker) docker.io/rodolpheche/wiremock:2.27.2-alpine。我通过 Docker Compose 进行设置,一切正常。

我正在尝试设置一个存根/映射来根据相应的 JSON 模式检查 JSON 输入。基本上,这是存根/映射:

{
  "name": "Create Character Stub",
  "request": {
    "headers": {
      "accept": {
        "caseInsensitive": true,
        "equalTo": "application/json"
      },
      "content-type": {
        "caseInsensitive": true,
        "equalTo": "application/json"
      }
    },
    "method": "POST",
    "url": "/api/characters",
    "body": {
      // [start] I made this up, but that's what I'm trying to achieve
      "type": "JSON_SCHEMA",
      "location": ""schemas/create-character.json""
      // [end]
    }
  },
  "response": {
    "headers": {
      "location": "{{ request.path }}/{{ randomValue type='UUID' }}"
    },
    "status": 201,
    "transformers": ["response-template"]
  }
}

...这是 JSON 模式的(摘录):

{
  "$schema": "http://json-schema.org/draft/2019-09/schema#",
  "type": "object",
  "description": "Character entity",
  "properties": {
    "first_name": {
      "type": "string",
      "description": ""
    },
    "last_name": {
      "type": "string",
      "description": ""
    },
    "age": {
      "type": "number",
      "description": ""
    }
  },
  "additionalProperties": false,
  "required": ["first_name", "last_name", "age"]
}

有没有办法用 WireMock 来完成这个?我一直在寻找类似的东西。我发现更接近的是使用 JSON 路径,但这与检查正确的模式并不完全相同 - 并且可能是长 JSON 请求的乏味任务。

我搜索了 WireMock 的 GitHub 存储库中的问题,但我只能看到这个(顺便关闭)。尽管如此,我还是看不到一种方法可以完全按照我的要求进行。我只有一个 JSON 模式作为输入。

4

0 回答 0