Search code examples
spring-restdocs

Documenting Single Value Response Controller w/ Spring Rest Docs


Is it possible to document a response field for a controller that returns a single value?

Example: [GET] /book/count

JSON Response: 1


Solution

  • You can't use the response fields snippet. It expects a structured JSON or XML response. Given that your response is a single, numeric value I don't think you'd gain much from REST Docs documenting it anyway. There's next-to-nothing for it to document and verify.

    REST Docs will still automatically produce an HTTP response snippet that you could use. If you want something more, you could write your own Snippet implementation pretty easily.