drafter icon indicating copy to clipboard operation
drafter copied to clipboard

Ability to reuse responses

Open goganchic opened this issue 7 years ago • 0 comments

In our project we have very big api documentation. A lot of actions have identical responses like:

+ Response 401 (appliction/json)
    + Attributes
        + status: Unauthorized (required, fixed)

It's inconvenient to add such responses to almost every action. If we adds/modify/remove some common responses we have to process all actions. Chance to forget or misspell something is huge. So it will be very useful to have an ability to write common responses only once and drafter should do all required magic. Here is example:

# Group Authorized resources

# Common Data
+ Response 401 (application/json)
    + Attributes
        + status: Unauthorized (required, fixed)

## Posts [GET /posts]
+ Response 200 (application/json)
    + Attributes
        + result (array) - list of posts

## Comments [GET /comments]
+ Response 200 (application/json)
    + Attributes
        + result (array) - list of comments

In this case response 401 should be added to GET /posts and GET /comments actions. If I need to modify it - I'll do it only once in one place.

If I need to add some common data to one group only I can do it like this:

# Group Authorized resources

# Common Data
+ Response 401 (application/json)
    + Attributes
        + status: Unauthorized (required, fixed)

## Posts [GET /posts]
+ Response 200 (application/json)
    + Attributes
        + result (array) - list of posts

## Comments [GET /comments]
+ Response 200 (application/json)
    + Attributes
        + result (array) - list of comments

# Group Authentication

## Login [POST /login]
In this section 401 response will not be added, because it was defined in another group

goganchic avatar Apr 30 '17 16:04 goganchic