Skip to content

Instantly share code, notes, and snippets.

@johanhammar
Created August 26, 2015 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johanhammar/c5f41542cbcb8ad727e4 to your computer and use it in GitHub Desktop.
Save johanhammar/c5f41542cbcb8ad727e4 to your computer and use it in GitHub Desktop.
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
Copy link

RobWin 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
Copy link

RobWin commented Aug 26, 2015

@johanhammar
Copy link
Author

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

@johanhammar
Copy link
Author

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
Copy link
Author

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

@johanhammar
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment