Spring Cloud Contract is able to generate REST Docs from contracts, but currently the generated docs are quite spare, missing important information such as the ability to provide descriptions for request and response fields. While markup is half the battle, for providing this information in the contracts it could work similar to how matches are used, YAML example below:
name: add-produce
description: Operation for adding a new produce item
request:
method: POST
url: /api/v1/produce
headers:
Content-Type: application/json;charset=UTF-8
body:
name: "Kiwi"
subName: ""
quantity: 75
matchers:
headers:
- key: Content-Type
regex: "application/json.*"
body:
- path: $.quantity
type: by_regex
value: "[0-9]+"
- path: $.name
type: by_regex
predefined: only_alpha_unicode
descriptions:
headers:
- key: Content-Type
description: "Produce endpoint expects JSON encoded request bodies"
body:
- path: $.name
description: "Name of new produce item"
- path: $.subName
description: "Sub-name of new produce item providing a more specific name for the produce item"
- path: $.quantity
description: "Number of produce item currently in stock"
response:
status: 200
body:
id: 10
name: "Kiwi"
subName: ""
quantity: 75
headers:
Content-Type: application/json;charset=UTF-8
matchers:
body:
- path: $.id
type: by_regex
value: "[0-9]+"
descriptions:
headers:
- key: Content-Type
description: "Produce endpoint provides responses in JSON"
body:
- path: $.id
description: "Unique id of new produce item"
- path: $.name
description: "Name of new produce item"
- path: $.subName
description: "Sub-name of new produce item providing a more specific name for the produce item"
- path: $.quantity
description: "Number of produce item currently in stock"
Spring Cloud Contract is able to generate REST Docs from contracts, but currently the generated docs are quite spare, missing important information such as the ability to provide descriptions for request and response fields. While markup is half the battle, for providing this information in the contracts it could work similar to how matches are used, YAML example below: