Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Swagger nested arrays
swagger: '2.0'
info:
version: "0.0.1"
title: Nested arrays
description: Demo of nested arrays
contact:
name: Johan Hammar
host: localhost
schemes:
- https
basePath: /v1
produces:
- application/json
consumes:
- application/json
paths:
/demo:
get:
tags:
- Demo
summary: Nested arrays demo
description: |
responses:
200:
description: Nested array object
schema:
type: object
$ref: '#/definitions/nested'
definitions:
nested:
properties:
nested_array:
type: array
items:
properties:
first_value:
type: string
second_value:
type: string
@RobWin

This comment has been minimized.

Copy link

commented Aug 26, 2015

What happens if you split the inner model into its own model definition and reference it from the outer array?

@RobWin

This comment has been minimized.

Copy link

commented Aug 26, 2015

@johanhammar

This comment has been minimized.

Copy link
Owner Author

commented Aug 26, 2015

Let me check if it works is I split out the inner model.

@johanhammar

This comment has been minimized.

Copy link
Owner Author

commented Aug 26, 2015

This seems to work

swagger: '2.0'

info:
  version: "0.0.1"
  title: Nested arrays
  description: Demo of nested arrays
  contact:
    name: Johan Hammar

host: localhost

schemes:
  - https

basePath: /v1
produces:
  - application/json
consumes:
  - application/json

paths:
  /demo:
    get:
      tags:
        - Demo
      summary: Nested arrays demo
      description: |

      responses:
        200:
          description: Nested array object
          schema:
            type: object
            $ref: '#/definitions/nested'
definitions:              
  nested:
    properties:
      nested_array:
        type: array
        items:
          $ref: '#/definitions/inner'
  inner:
    properties:
            first_value:
              type: string
            second_value:
              type: string
@johanhammar

This comment has been minimized.

Copy link
Owner Author

commented Aug 26, 2015

Do you still wan't me to open a bug regarding the first example?

@johanhammar

This comment has been minimized.

Copy link
Owner Author

commented Aug 26, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.