apiblueprint - Trying to describe the request and response using Data Structures in API Blueprint -
i'm trying document endpoint api blueprint, using new attributes , datastructures sections of spec.
my request payload looks this:
{ "url": "http://requestb.in/11v7i7e1", "active": true, "types": [ { "name": "sales", "version": "2.0" }, { "name": "products", "version": "2.0" } ] }
my response payload looks that:
{ "data": { "id": "dc85058a-a683-11e4-ef46-e9431a15be8c", "url": "http://requestb.in/11v7i7e1", "active": true, "types": [ { "name": "products", "version": "2.0" }, { "name": "sales", "version": "2.0" } ] } }
i tried following api blueprint markdown:
format: 1a # vend rest api 2.0 # group webhooks ## api/2.0/webhooks [/webhooks] ### list webhooks [get] returns list of webhooks created authorised application. + response 200 (application/json) + attributes (webhook collection) ### add new webhook [post] creates new webhook. + attributes (webhook base) + request (application/json) + attributes (webhook base) + response 200 (application/json) + attributes (webhook response) # data structures ## webhook base (object) + url: https://example.com/webhook (string, required) - address webhooks requests should submitted. + active: true (boolean, required) - field can used inspect or edit state of webhook. + types: array[webhook type] (array[webhook type], required) - collection of webhook types should trigger webhook event. ## webhook response base (webhook base) + id: dc85058a-a683-11e4-ef46-e8b98f1a7ae4 (string, required) - webhook `id`. ## webhook response (object) + data: webhook (webhook response base, required) ## webhook type (object) + name: sales (string, required) - 1 of: products, sales, customers, taxes + version: 2.0 (string, required) - version of payload delivered. supported value "2.0". ## webhook collection (object) + data: array[webhook response base] (array[webhook response base], required) - array of webhook objects.
now, when looking @ in apiary, tells me valid api blueprint document, doesn't how me json previews request , response. structures possible represent in api blueprint , able render nicely in apiary?
this combination of 2 problems:
- incorrect syntax
- bug in rendering
1. syntax
the problem seems here:
## webhook collection (object) + data: array[webhook response base] (array[webhook response base], required) - array of webhook objects.
looking @ + data: array[webhook response base] (array[webhook response base])
. basicaly when value expected (after :
) value should provided. instead – in case – have there type array[webhook response base]
.
let me demonstrate on simpler example:
+ data: number (array[number])
is incorrect.
correct version be
+ data: 42 (array[number])
or
+ data (array[number]) + 42
or
+ data (array) + 42 (number)
2. bug in rendering
even if correct blueprint won't rendered in apairy. bug have discovered in our json renderer. has been reported here https://github.com/apiaryio/drafter.js/issues/26 plan fix asap.
this has been fixed now
corrected blueprint
format: 1a # vend rest api 2.0 # group webhooks ## api/2.0/webhooks [/webhooks] ### list webhooks [get] returns list of webhooks created authorised application. + response 200 (application/json) + attributes (webhook collection) ### add new webhook [post] creates new webhook. + attributes (webhook base) + request (application/json) + attributes (webhook base) + response 200 (application/json) + attributes (webhook response) # data structures ## webhook base (object) + url: https://example.com/webhook (string, required) - address webhooks requests should submitted. + active: true (boolean, required) - field can used inspect or edit state of webhook. + types (array[webhook type], required) - collection of webhook types should trigger webhook event. ## webhook response base (webhook base) + id: dc85058a-a683-11e4-ef46-e8b98f1a7ae4 (string, required) - webhook `id`. ## webhook response (object) + data (webhook response base, required) ## webhook type (object) + name: sales (string, required) - 1 of: products, sales, customers, taxes + version: 2.0 (string, required) - version of payload delivered. supported value "2.0". ## webhook collection (object) + data (array[webhook response base], required) - array of webhook objects.
hope answers question. please let me know if further clarification needed.