【问题标题】:How to have different matchers for server side and client side for request url in groovy based spring cloud contract如何在基于 groovy 的 Spring Cloud 合约中为服务器端和客户端设置不同的匹配器以获取请求 url
【发布时间】:2019-07-09 21:44:14
【问题描述】:

所以我知道这是无效的

Contract dsl =
        Contract.make {
            description "should return correct expected response"
            request {
                method GET()
                url value(consumer(regex('/v2/abc/user/[0-9]{9,18}')),producer(regex("/abc/v2/user/[0-9]{9,18}")))

                }

            }
            response {
                body([
                        id : $(consumer(regex('.*'))),

                ])
                status 200
            }
        } 

生产者和消费者之间的API网关将生产者url转换为消费者。 Spring Cloud 合约是否允许 API 网关更改 URL 以查看消费者期望的情况?

当我尝试这样做时,错误很明显

You can't have a regular expression for the request on the server side

【问题讨论】:

    标签: spring-cloud-contract


    【解决方案1】:

    在生产者端使用正则表达式是没有意义的。那是因为在测试中我们需要向一个具体的 url 发送一个具体的请求。除非您告诉我们它的样子,否则我们找不到该 url。

    【讨论】:

    • 谢谢..regex 仅在消费者方面解决了我的问题 url $(consumer(~/(((?=.*(v2\/abc\/user)).*)|(( ?=.*(abc\/v2\/user)).*))\/[0-9]{9,18}/),producer('/abc/v2/user'))
    猜你喜欢
    • 2020-02-05
    • 1970-01-01
    • 2020-02-04
    • 1970-01-01
    • 2011-12-27
    • 2018-12-28
    • 1970-01-01
    • 2015-08-31
    • 2021-05-08
    相关资源
    最近更新 更多