apiaryio / api-blueprint

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

Unable to reference Data Structure object within array #195

Closed pete001 closed 9 years ago

pete001 commented 9 years ago

Hi there, thanks for such an awesome product!

I am documenting using JSONAPI format, and i am having an issue with expressing an object within an array. This is required due to the JSONAPI spec for non-empty to-many relationships.

Here is my example code:

# Group Stock
All inventory information and management is exposed through the `stock` endpoint.

## Stock [/stock/{id}]

- Parameters
    - id: 1 (number, required) - Specific `id` of a stock item

- Attributes (Stock Base)
    - id: 1 (number) - Specific id of a stock item
    - type: stock (string) - Resource type

### Retireve Stock [GET]
Fetch details about specific stock.

- Response 200 (application/vnd.api+json)
    - Attributes (Stock)

## Stocks [/stock]

- Attributes
    - data(array[Stock]) - Full output of all data

### List all Stock [GET]
Return details of all stock.

- Response 200 (application/vnd.api+json)
    - Attributes (Stocks)

# Data Structures

## Stock Base (object)
- price: 4.50 (number) - Standard price
- sale_price: 3.00 (number) - Specific sale only price
- description: Coconut yoghurt (string) - Text description of stock item
- ingredients: Coconut, Nuts, Milk (string) - Comma separated list of all ingredients
- allergens: Nuts, dairy (string) - Comma separated list of all allergen information
- Include Stock Links Base

## Stock Links Base (object)
- links (object) - JSON API links section
    - *dietary_requirements* (array)
        - Include Linkage
    - *stock_type*
        - Include Linkage

## Linkage (object)
- linkage (object) - JSON API linkage section
    - id: 1 (number)
    - type: reference_type (string)

If you render this in apiary, you will notice that the dietary_requirements array is empty, even though it references the Linkage Data Structure.

screen shot 2015-05-08 at 22 03 23

Any help would be much appreciated.

kylef commented 9 years ago

Try changing this:

- *dietary_requirements* (array)
    - Include Linkage

To this:

- *dietary_requirements* (array[Linkage])

screen shot 2015-05-08 at 22 08 05

I don't believe it's possible to use mixins (include) with arrays like in this example.

pete001 commented 9 years ago

Wow, totally amazing! Thanks so much for the speedy response, this worked perfectly :smile:

zdne commented 9 years ago

@kylef is correct – Include is meant to work with objects only (spec).

However the parser should warn on this occasion – isn't this the case? //cc @pksunkara

zdne commented 9 years ago

@pete001 also you can specify any type as a content of array like so:

- my_array (array)
    - (type1)
    - (type2)
    - (another type)
pete001 commented 9 years ago

Thanks @zdne! The apiary parser wasnt complaining at me, was validating ok.

pksunkara commented 9 years ago

The parser should give a warning. Let me check.