Skip to content

返回response json时,template无法使用 #333

Description

@toyood

我做了如下尝试都不行。应该如何使用呢?我的场景是模拟服务接口,返回参数能够定制规则,比如支持表达式等,template也是一种方式,但是他不能使用。配置如下:

[
  {
    "description": "验证测试",
    "request": {
      "uri": "/login",
      "method": "post",
      "headers":{
          "content-type":"application/json;charset=utf-8" 
      },
      "json": {
          "username":"test",
          "password":"123456"
      }
    },
    "response": {
      "json":{
        "msg":"login success",
        "status":"200",
	"testDt":{"template":"${now(\"yyyy-MM-dd\")}}" //error
	"template":{"testDt":"${now(\"yyyy-MM-dd\")}}" //error
	"testDt":"${now(\"yyyy-MM-dd\")}"              //error
      }
    }
  }
]

Activity

  1. tuozixuan commented on Aug 13, 2025

    @tuozixuan

    请问返回json数据时如何使用随机数函数,template试了一下不行。

    配置:

        {
            "description": "随机数字示例",
            "request":
            {
                "uri": {
                    "path": "/api/responseJsonRandomDemo"
                }
            },
            "response":
            {
                "json": {
                    "id": {
    			         "template":"${random(10000000,99999999,\"########\")}"
    			    }
    			}
            }
        }

    响应结果不符合预期:

    {"id":{"template":"${random(10000000,99999999,\"########\")}"}}
  2. Repository owner deleted a comment from yangli8866 on Sep 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions