spring-cloud - spring cloud contract - 使用请求的主体作为响应主体
问题描述
在使用此合约的 Spring Cloud 合约 (v1.2.5) 中:
Contract.make {
description "update sthg"
request {
method PUT()
url value($(consumer('/path/to/sthg'),
producer(execute('somePutPathPath(0,\"xxx\")'))))
body(producer(
file('files/givens/my-body.json')
))
}
response {
status 200
headers {
contentType(applicationJson())
}
body(fromRequest().body())
}
}
生成测试时出现错误
org.springframework.cloud:spring-cloud-contract-maven-plugin:1.2.5.RELEASE:generateTests failed:net.minidev.json.parser.ParseException: Unexpected character ({) at position 1. -> [Help 1]
但如果我使用一切都很好:body(someProp: fromRequest().body())
Contract.make {
description "update sthg"
request {
method PUT()
url value($(consumer('/path/to/sthg'),
producer(execute('somePutPathPath(0,\"xxx\")'))))
body(producer(
file('files/givens/my-body.json')
))
}
response {
status 200
headers {
contentType(applicationJson())
}
body(someProp: fromRequest().body())
}
}
我如何将正文响应设置为请求的正文。
解决方案
我通过使用request.getBody()而不是:body(fromRequest().body())解决了这个问题
body($(
c(request.getBody()),
p(file('some.json'))
))
推荐阅读
- r - 如何删除R中数据的前10%和最后10%值
- amazon-web-services - 是否可以使用 AWS Lambda (HTTP API) 添加自定义标头
- reactjs - 收到错误为“postDetails”未定义 no-undef 我的状态变量
- sql-server - 由于插入触发器中的错误而未插入
- algorithm - Dijkstra:找到目的地时如何设置终止条件?
- ipython - iPython shell - 如何使用 $EDITOR 来编辑命令
- python - 在 Python 脚本中同时使用多处理和多线程来加快执行速度
- python - 用户警告:使用 0.22 版本时,尝试从 0.22.2.post1 版本中解开估计器 ExtraTreesClassifier
- recursion - 迭代定义深度的递归拆分
- javascript - 如何使用 Javascript D3 将单列 CSV 文件导入饼图?