apiaryio / mson

Markdown Syntax for Object Notation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot specify root element as array in request attributes

qwertyuu opened this issue · comments

First of all, thanks for the awesome tool. Very handy.

I've been wanting to specify an array as root element of my request payload, but apiary throws a semantic issue warning.
I tried making the smallest possible case to reproduce the error. The MSON code I used is the example in the docs here.

FORMAT: 1A
HOST: http://polls.apiblueprint.org/

# test root array


## Array root [/questions]

### Array root [GET]

+ Request (application/json)
    + Attributes
        - (array)
            - (object)
                - name: snow (string)
                - description (string)
            - 42 (number)
+ Response 200 (application/json)

The JSON I expect from this MSON in the Attributes field is this one:

[
    {
        "name": "snow",
        "description": ""
    },
    42
]

But I get

{}

I also saw that the JSON Schema that was rendered always assumed an object as root element, which does not really reflect what is written in the docs. The JSON Schema output would not work in my case.
The issue can be ignored by specifying a JSON body and living with the semantic issue that the validator throws.
image
(Line 13 is the - (array) line where it waits for a property to put in the root object element)

@qwertyuu The syntax you are l looking for is as follows (+ Attributes (array)):

FORMAT: 1A
HOST: http://polls.apiblueprint.org/

# test root array


## Array root [/questions]

### Array root [GET]

+ Request (application/json)
    + Attributes (array)
        - (object)
            - name: snow (string)
            - description (string)
        - 42 (number)

+ Response 200 (application/json)

+ Attributes by default is object type, so the snippet you included tries to place a array without an identifier inside an object. Hence the warning saying the identifier (the key for the property in the object) is not specified.

@kylef I really need to use an array (that is, without identifier) as root element for the payload we're designing. Is that possible?

EDIT: Nevermind, I misread. Very nice of you, have a good day!