提问者:小点点

Wiremck随机值作为字符串而不是数字返回


我正在使用随机值在路由响应中返回随机数。

当我刚刚返回它时,值作为数字返回。但是如果我作为响应正文中的属性发送,则值作为字符串返回。我可以将其作为数值返回吗?

我的码头工人:

version: '3.8'

services:
  wiremock:
    image: wiremock/wiremock
    container_name: wiremock_server
    volumes:
      - ./wiremock:/home/wiremock
    ports:
      - 8888:8080
    command:
      - -verbose
      - -global-response-templating
networks:
  default:
    ipam:
      config:
        - subnet: 172.30.0.0/16

我的Wiremck映射:

{
  "request": {
    "urlPattern": "/account/([0-9]*)/balance",
    "method": "GET"
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "body": "{ \"balance\": \"{{randomValue length=9 type='NUMERIC'}}\" }"
  }
}

收到的答复:

{
    "balance": "499336545"
}

预期反应c:

{
    "balance": 499336545
}

我尝试只返回随机值和作品,但我需要这里面的身体属性。


共1个答案

匿名用户

您正在引用响应定义中的值。只需使用这个:

{
  "request": {
    "urlPattern": "/account/([0-9]*)/balance",
    "method": "GET"
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "body": "{ \"balance\": {{randomValue length=9 type='NUMERIC'}} }"
  }
}