1

For example I need to represent following structure in swagger yaml format:

  "included": [
    {
      "type": "people",
      "id": "42",
      "attributes": {
        "name": "John",
        "age": 80,
        "gender": "male"
      }
    }
  ]

With single object everything is fine:

  included:
    type: "array"
    items:
      type: object
      properties:
        type:
          type: "string"
        # and so on 

The question is what if I need to describe something like:

"included": [{
    "type": "people",
    "id": "9",
    "attributes": {
      "first-name": "Dan",
      "last-name": "Gebhardt",
      "twitter": "dgeb"
    },
    "links": {
      "self": "http://example.com/people/9"
    }
  }, {
    "type": "comments",
    "id": "5",
    "attributes": {
      "body": "First!"
    },
    "relationships": {
      "author": {
        "data": { "type": "people", "id": "2" }
      }
    },
    "links": {
      "self": "http://example.com/comments/5"
    }
  }, {
    "type": "comments",
    "id": "12",
    "attributes": {
      "body": "I like XML better"
    },
    "relationships": {
      "author": {
        "data": { "type": "people", "id": "9" }
      }
    },
    "links": {
      "self": "http://example.com/comments/12"
    }
  }]

I know that in OpenAPI it's possible ( aka swagger 3 ) and tried some workarounds in current version but with no luck.

  • In your 2nd example both array items have same-type properties, so it's essentially the same as the 1st example with 1 array item. What exactly is the problem? – Helen Jun 28 '17 at 10:34
  • Hi @Helen thanks for noticing. I've updated second object. Orginaly these objects wouldn't be the same. They will have different attributes, etc. – deividaspetraitis Jun 28 '17 at 10:47
  • Possible duplicate of [How do you create a swagger schema that includes an array of varying types](https://stackoverflow.com/questions/36318849/how-do-you-create-a-swagger-schema-that-includes-an-array-of-varying-types) – Helen Jun 28 '17 at 13:20

0 Answers0