Skip to content

Instantly share code, notes, and snippets.

@JosephGaiser
Last active January 21, 2020 20:55
Show Gist options
  • Save JosephGaiser/08190da6de7fc43cdf0b41ea8de690d3 to your computer and use it in GitHub Desktop.
Save JosephGaiser/08190da6de7fc43cdf0b41ea8de690d3 to your computer and use it in GitHub Desktop.

Contract

This contract is set up to respond to POST requests to the /person endpoint with a 201.
The body of the response will reflect the values passed in the request.

name: Post person
request:
  method: POST
  urlPath: /person
  headers:
    Content-Type: application/json
  body:
    name: Joe
    someBool: true
  matchers:
    body:
      - path: $.name
        type: by_regex
        predefined: non_blank
      - path: $.someBool
        type: by_regex
        predefined: any_boolean
response:
  status: 201
  body:
    name: "{{{ jsonpath this '$.name' }}}"
    someBool: "{{{ jsonpath this '$.someBool' }}}"
  matchers:
    body:
      - path: $.someBool
        type: by_regex
        predefined: any_boolean
        regexType: as_boolean    <---- Proposed change by Marcin

Example POST Request

POST localhost:5555/Person
{
  "name": "Marcin",
  "someBool": true
}

Actual Response

This is the reponse I get from the stub when making the example post request

{
  "name": "Marcin",
  "someBool": "true" <--- STRING
}

Desired Response

This is what I want the stub to respond with when making the example post request

{
  "name": "Marcin",
  "someBool": true <--- BOOLEAN
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment