Drew Baker
Drew Baker

Reputation: 14450

API Blueprint - Use Data Strucutres in response, without Attributes

I'm using Apiary to mock out a new API.

I'm trying to avoid having to write out all the JSON responses over and over again. If I do that using a + Attributes(user) then it will auto generate a bunch of attributes blocks in the machine panel, which is super confusing in my mind (especially when you have multiple responses).

The resulting documentation looks way better if you write out the JSON request/response blocks manually.

Is there a way to store Request/Response objects as a Data Structure? Maybe a Model perhaps?

I'd love to be able to do something like this:

## Users [/auth]
A user object contains the these attributes.

+ Attributes (user) <!-- I like this here -->

### Refresh a token for a user [POST /auth/refresh]

+ Request (application/json)
    + Headers

            Authorization: Bearer jsonWebToken


+ Response 200 (application/json)          
    + Body

            {
                "data": [
                    (user) <!-- I wish this was the user data structure as JSON -->
                ],
                "meta": {
                    "access_token": "jsonWebToken",
                    "token_type": "Bearer",
                    "expires_in": 3600
                }
            }



# Data Structures

## user (object)
+ id: 123 (number)
+ email: [email protected]

Note: The user object is 30 attributes long in real life.

Upvotes: 0

Views: 202

Answers (1)

Vincenzo
Vincenzo

Reputation: 1559

Unfortunately that's not a supported scenario, you can't but data structures into your JSON payloads.

So if I understand correctly - using Attributes is fine but you would like hide them in documentation. Could you confirm that?

Upvotes: 0

Related Questions