apiaryio / api-blueprint

API Blueprint
https://apiblueprint.org
MIT License
8.64k stars 2.14k forks source link

Data Structure for Entire Response? #294

Closed bitdivision closed 8 years ago

bitdivision commented 8 years ago

I don't see any way to include a data structure as the entire response of an action. I'm essentially hoping to refactor a blueprint so that error responses don't have to be repeated for every endpoint.

e.g.

I currently have a lot of these:

+ Response 401 (application/json)

    + attributes (error)

    + body

            {
                "title": "Unauthorized",
                "description": "You do not have authorization to access this resource."
            }

on multiple endpoints and I'm hoping there's a way to factor them out into a single one and use something like

+ Response 401 (UnauthorizedError)

Is this possible?

zdne commented 8 years ago

You can do something like this:


## Error (object)
- title (string)
- description (string)

## UnauthorizedError (Error)
- title: Unauthorized
- description: You do not have authorization to access this resource.

# Group Lorem
## Ipsum [/ipsum]
### Retrieve [GET]
- response 200 (application/json)
- response 401 (application/json)
    - attributes (UnauthorizedError)

Does this help?

bitdivision commented 8 years ago

Okay. That's a little better. Thanks @zdne