apiaryio / mson

Markdown Syntax for Object Notation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Array consisting of specified types only

honzatrtik opened this issue · comments

Hi,
we are struggling with defining MSON, which would describe array consisting of specified types only (we'd like to have included section of our json api (http://jsonapi.org/) responses fully validated by dredd).

So far, we tried this:

## Type1 (object, fixed-type)
+ prop1: `val1` (string)

## Type2 (object, fixed-type)
+ prop2: `val2` (string)

...

+ Response 200 (application/json)
    + Attributes
        + included (array, fixed-type)
            + (Type1)
            + (Type2)

Generated json schema validates this json:

{
  "included": [
    {
      "prop1": ""
    },
   {
      "prop2": ""
    }
  ]
}

but not this one:

{
  "included": [
    {
      "prop1": ""
    },
    {
      "prop1": ""
    },
   {
      "prop2": ""
    }
  ]
}

Another try was something like this:

## Type1 (object, fixed-type)
+ prop1: `val1` (string)

## Type2 (object, fixed-type)
+ prop2: `val2` (string)

...

+ Response 200 (application/json)
    + Attributes
        + included (array, fixed-type)
            + (enum)
                + (Type1)
                + (Type2)

But this seems to generate invalid json schema...

Are we missing something?
Thanks in advance!

I apologise for not getting back to you sooner.

I think the only way to achieve this would be using One Of, but that only applies to objects:

# GET /

+ Response 200 (application/json)
    + Attributes
        + One Of
            + included (array[Type1], fixed-type)
            + included (array[Type2], fixed-type)

# Data structures

## Type1
+ prop1: val1

## Type2
+ prop2: val2

messages image 2342085819