Hey
So not really an issue more a question. I'm generating my contracts now using rest docs, based on the following doc:
So that generates a contract in string based format, example (note this is a cut down exampleof what we have):
Contract.make {
request {
method 'POST'
url '/example'
body('''
{
"id" : "8913a65a-3e07-41ad-9edb-dd23579a6faf",
"status" : "new quote"
}
''')
headers {
header('''Content-Type''', '''application/json''')
header('''client-id''', '''ECLIQ''')
}
}
response {
status 200
headers {
header('''Content-Type''', '''application/json;charset=UTF-8''')
}
testMatchers {
jsonPath('$.id', byType())
}
}
}
Our contracts we defined before looks something like this.
Contract.make {
request {
method 'POST'
url '/examples'
body ([
id: $(regex(uuid())),
status: $(regex(nonEmpty()))
])
headers {
header('Content-Type', 'application/json')
header('client-id', $(regex(nonEmpty())))
}
}
response {
status 200
headers {
contentType('application/json')
}
}
}
just wondering how can we generate something similar to this using rest docs. using the regex stuff, as we dont care what the value is for id for example as long as it matches the uuid format.
Thanks
I think you've forgotten to ask the question ;) or I don't understand the problem
hey sorry Marcin, accidentally posted it without finishing, I updated the question now. Just looking at a way I can generate my contracts via my MVC tests, but have the ability to use the regex examples above. Hope you can steer me in the right direction, this is all new to us at the moment. thanks
also i do have a follow up question in addition to that, when I add a check for my id in my mock mvc test, for example .jsonPath("$.id"). it generates as jsonPath('$.id', byType()) in the contract, is there a way to generate this with other test matchers, such as byRegex for example.
Sure - just check out this sample - https://github.com/spring-cloud-samples/spring-cloud-contract-samples/blob/master/producer_with_restdocs/src/test/java/com/example/ProducerControllerTests.java#L62 and this part of the documentation where we explain how to do this https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html#_generating_stubs_using_restdocs
oh now I'm confused. So you have a problem that the contracts don't have these regular expressions - not stubs... So that might not really be possible at this moment. So that might be an issue...
yeah sorry the contracts I mean. I want the ability in my generated contract to use reg expressions.
hey
Just to follow up, I found it much easier when I followed your documentation for Generating Stubs using RestDocs. So I just generate the Stub and use them, and package them up into a jar. Also found it much more beneficial when I used the WireMock API in my mockMVC tests to generate the stubs, I could then use marchers and things like that.
Thanks for the help, your documentation was a great help. Was able to follow that the past couple of days and get up and running using Spring Cloud Contact with no experience with it beforehand.
This is absolutely awesome to hear :) Thank you so much for the feedback. The Spring Cloud Contract RestDocs side was mainly done by @dsyer so all the congrats should go to him :)
So if I understand it correctly - everything is fine and you've managed to fix your problems?
yeah everything is great. Thanks Marcin
Most helpful comment
yeah everything is great. Thanks Marcin