Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Sample request/response #204

Closed
sudsk opened this issue Feb 13, 2017 · 3 comments
Closed

Feature request: Sample request/response #204

sudsk opened this issue Feb 13, 2017 · 3 comments

Comments

@sudsk
Copy link

sudsk commented Feb 13, 2017

Hi,

Thanks for the great work on reDoc!
I have a request if its possible to introduce sample request/response. For example have a look at this url for Shopify's API reference - https://help.shopify.com/api/reference/transaction.
Same endpoint can support one or more request scenarios. Provide samples would provide complete client documentation. This could be a new section below Responses section for each endpoint. The content of samples can be provided as JSON or YAML objects.

A scenario is presented below from above shopify url.

Scenario - Capture a specified amount on a previously authorized order.

POST /admin/orders/#{id}/transactions.json

{
  "transaction": {
    "amount": "10.00",
    "kind": "capture"
  }
}

Hide Response
HTTP/1.1 201 Created

{
  "transaction": {
    "id": 1068278464,
    "order_id": 450789469,
    "amount": "10.00",
    "kind": "capture",
    "gateway": "bogus",
    "status": "success",
    "message": "Bogus Gateway: Forced success",
    "created_at": "2017-01-05T15:31:49-05:00",
    "test": true,
    "authorization": null,
    "currency": "USD",
    "location_id": null,
    "user_id": null,
    "parent_id": 389404469,
    "device_id": null,
    "receipt": {},
    "error_code": null,
    "source_name": "755357713"
  }
}
@sudsk sudsk changed the title Sample request/response Feature request: Sample request/response Feb 13, 2017
@sudsk
Copy link
Author

sudsk commented Feb 13, 2017

The way it could be written in swagger spec is, after the response section in spec we can have a section for sample request/response.

  responses:
    '201': ...........
    '4xx':.....
    '5xx':.....
  x-<app>-samples:
    - $ref: '#/x-<app>-samples/orders-capture-after-auth'

The at the bottom of model definition section we can define these:-

x-<app>-samples:
  orders-capture-after-auth:
    title: Capture a specified amount on a previously authorized order.
    description: This sample captures a specified amount on a previously authorized order.
    method: POST
    url: /admin/orders/#{id}/transactions.json
    Request: {
       "transaction": {
       "amount": "10.00",
       "kind": "capture"
    }
    Response: 
    HTTP/1.1 201 Created
    {
      "transaction": {
      "id": 1068278464,
      "order_id": 450789469,
      "amount": "10.00",
      "kind": "capture",
      "gateway": "bogus",
      "status": "success",
      "message": "Bogus Gateway: Forced success",
      "created_at": "2017-01-05T15:31:49-05:00",
      "test": true,
      "authorization": null,
      "currency": "USD",
      "location_id": null,
      "user_id": null,
      "parent_id": 389404469,
      "device_id": null,
      "receipt": {},
      "error_code": null,
      "source_name": "755357713"
      }
}

@RomanHotsiy
Copy link
Member

@suds123 ReDoc is more focused on Reference documentation and what you suggest is more like tutorials.
We have considered tutorials and we believe that this should not be a part of ReDoc lib. But I can help you to create a customized build for you.
Feel free to contact me (see email on my GitHub profile)

@RomanHotsiy
Copy link
Member

Closing this for now as it's beyond the scope of the project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants