Swagger-editor: Using $ref in array query parameter

Created on 2 Jan 2017  路  4Comments  路  Source: swagger-api/swagger-editor

Swagger File

swagger: '2.0'
info:
  title: snip
  version: 1.3.3.7
paths:
  /some-stuff:
    get:
      parameters:
      - name: some-filter
        in: query
        description: snip
        required: true
        type: array
        items:
          $ref: '#/definitions/SomeDef'
      responses:
        200:
          description: snip
definitions:
  SomeDef:
    type: integer
    format: int32
  • Version: 2.10.3

Issue

Given the file above, I get the following error:

If I replace

$ref: '#/definitions/SomeDef'

with plain

type: integer
format: int32

then the error goes away. Judging by Response Object Examples in the spec (not the same, but related), it should be okay to use $ref in this context. Is my assumption wrong, or is this a bug?

All 4 comments

You cannot use $ref's in any way under non-body parameters, not directly and not for arrays. You'd have to define it all inline. This changes in the next version of the spec.

Hi, i have simmilar issue; i try describe this form

<form>
    <input name="contact[0][name]" />
    <input name="contact[0][number]" />
    <input name="contact[1][name]" />
    <input name="contact[1][number]" />
    ...
    <input name="contact[n][name]" />
    <input name="contact[n][number]" />
</form>
swagger: '2.0'
info:
  title: Test case
  description: Complex form data
  version: 1.0.0
host: test.example.com
schemes:
  - http
basePath: /v1
produces:
  - application/json
paths:
  /test:
    post:
      summary: Example
      description: |
        Example
      parameters:
        - name: items
          in: formData
          description: Array of strings
          type: array
          items:
            type: string
        - name: contacts
          in: formData
          description: Array of objects which won't work
          type: array
          items:
            properties:
              example_id:
                type: string
                description: Unique identifier
              description:
                type: string
                description: Description of example.
      responses:
        default:
          description: Some response
          schema:
            $ref: '#/definitions/Example'
definitions:
  Examples:
    type: array
    items:
      $ref: '#/definitions/Example'
  Example:
    type: object
    properties:
      example_id:
        type: string
        description: Unique identifier
      description:
        type: string
        description: Description of example.

i got this error error_image

but fields are work fine gui_image

Can you help me with this?

Can i describe array of objects in form data request in current version of swagger?

@gjorgic - today, you'd need to declare those explicitly. So you'd need to create a parameter with the name contact[0][name]. In the next version there will be better support for it, but I'm not sure it will fully cover your use case.

I wonder; Is there a reason for not allowing $ref in array in a non-body parameter @webron ?

Was this page helpful?
0 / 5 - 0 ratings