Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array consisting of specified types only #83

Open
honzatrtik opened this issue Apr 25, 2017 · 2 comments
Open

Array consisting of specified types only #83

honzatrtik opened this issue Apr 25, 2017 · 2 comments

Comments

@honzatrtik
Copy link

honzatrtik commented Apr 25, 2017

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!

@honzatrtik
Copy link
Author

ping? :)

@kylef
Copy link
Member

kylef commented Aug 25, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants