Hey hey, I love trying wiremock for our org. Appre...
# wiremock-cloud
y
Hey hey, I love trying wiremock for our org. Appreciate your thoughts on the following: We'd like to verify our mock integrity with OpenAPI so we import our OpenAPI and have wiremock cloud generates responses for us. Then, during specific tests the test scenario demands getting a specific value in the mocked response (e.g., user.isDeleted=true) but the wiremock response is random. It might be either true or false, both are valid from schema perspective, but 'true' is needed for this specific test. Is there a way to instruct wiremock to respond with a specific value for some request? Is there a way to create custom stubs and ask wiremock to verify that these stubs conform with some OpenAPI?
t
Hey @Yoni Goldberg, you can influence how stubs are generated from OpenAPI by supplying multiple named response examples and using our vendor extension attributes to specify the parameter values that should produce each example. So you can write the examples in a response element like:
Copy code
examples:
    one:
      summary: First example
      x-parameter-values:
        id: abc123
        category: staff
        search: things
      value: |
        { "name": "John" }

    two:
      summary: Second example
      x-parameter-values:
        id: cba321
      value: |
        { "name": "Jeff" }
And a stub will be generated for each example with request matchers using the parameter values you’ve specified.
y
Sounds awesome, many thanks Is there any documentation page about 'vendor extension attributes'?
+ One last request about this - is there a way to rely on custom testing-only header (e.g., x-scenario=deleted-user)? Why: I don't want the tests to remember that user-id=1 is the deleted user
t
Sorry, meant to share the doc link: https://docs.wiremock.io/swagger/
You can add a header matcher to a stub requiring that
x-scenario
equalTo
deleted-user
, so you’ll only see that response if if that header value is present. For a stub to be generated that works this way you’d have to declare
x-scenario
in the
parameters
section, then add something like this to the response example:
Copy code
x-parameter-values:
  x-scenario: deleted-user
y
Perfect!
👍 1