【问题标题】:spring cloud contract - use the request's body as the response bodyspring cloud contract - 使用请求的主体作为响应主体
【发布时间】:2018-10-26 15:15:54
【问题描述】:

在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())
        }
    }

如何将正文响应设置为请求正文。

【问题讨论】:

    标签: spring-cloud spring-cloud-contract


    【解决方案1】:

    我通过使用 request.getBody() 而不是:body(fromRequest().body())

    解决了这个问题
      body($(
                c(request.getBody()),
                p(file('some.json'))
        ))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-29
      • 2018-10-22
      • 1970-01-01
      • 2017-12-27
      • 1970-01-01
      • 2021-03-03
      • 1970-01-01
      • 2014-12-10
      相关资源
      最近更新 更多