richard
richard

Reputation: 12526

How to structure a response with an array that has an href to itself in YAML/swagger.io?

How do I do something like this:

"groups":{  
      "href":"https://api.mydomain.com/account/abC132/groups",
      "items":[  

      ]
   }

I have this:

groups:
            type: array
            properties:
              href:
                type: string
            items:
              type: object
              name: division
              properties:
                href:
                  type: string
                id:
                  type: string

But the swagger editor isn't recognizing the href under properties for the group.

Upvotes: 4

Views: 6848

Answers (2)

Ron
Ron

Reputation: 14840

I believe you're looking for something along the lines of this:

definitions:
  groups:
    title: groups
    type: object
    properties:
      href:
        type: string
      items:
        type: array
        items:
          $ref: '#/definitions/group'
  group:
    type: object
    properties:
      href:
        type: string
      id:
        type: string

Upvotes: 6

Ryan Wild
Ryan Wild

Reputation: 11

I had to do the following:

definitions:
  groups:
    title: groups
    type: object
    properties:
      href:
        type: string
      items:
        type: array
        items:
          $ref: '#/definitions/group'
  group:
    type: object
    properties:
      href:
        type: string
      id:
        type: string

Upvotes: 1

Related Questions