rspec_api_documentation icon indicating copy to clipboard operation
rspec_api_documentation copied to clipboard

Document all possible reponses of a single request in a single page

Open krazedkrish opened this issue 9 years ago • 2 comments

Hi!

Thanks for this great gem.

I would like to document all possible responses for a request in a single page for that request. For example, in github : the request curl https://api.github.com has three different responses for 3 cases,

Sending invalid JSON will result in a 400 Bad Request response.
HTTP/1.1 400 Bad Request
Content-Length: 35
{"message":"Problems parsing JSON"}

Sending the wrong type of JSON values will result in a 400 Bad Request response.
HTTP/1.1 400 Bad Request
Content-Length: 40
{"message":"Body should be a JSON object"}

Sending invalid fields will result in a 422 Unprocessable Entity response.
HTTP/1.1 422 Unprocessable Entity
Content-Length: 149
{
  "message": "Validation Failed",
  ...
}

Is there a way to document these in a single page? (Or may be an alternative way like making these nested, below the link for each page.)

krazedkrish avatar Sep 21 '16 05:09 krazedkrish

I have also been thinking about how to best structure multiple response for one request.

I found an example in the example documentation.

Looking at the source of the example app, it looks like you can just do multiple requests per example: https://github.com/zipmark/rspec_api_documentation/blob/master/example/spec/acceptance/orders_spec.rb#L47

phansch avatar Jun 09 '17 13:06 phansch

@phansch thank you for your response.

just like your example that was what i did. i wrote multiple requests per example. In each the requests were the same but the responses were different ( for example when creating order, if it had three responses 201, 403, 505, then the requests would be same, where as the responses would differ in status code, and body )

At that time i wish i could generate something like this: https://help.shopify.com/api/reference/order#cancel https://developer.github.com/v3/#root-endpoint

If rspec_api_documentation intendeds to use this issue as feature request, I have keep this issue open. Else I can close it, because my problem was solved the way @phansch mentioned.

krazedkrish avatar Jun 15 '17 15:06 krazedkrish