Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using $ref in array query parameter #1145

Closed
alecmev opened this issue Jan 2, 2017 · 4 comments · May be fixed by Centaurioun/swagger-editor#8
Closed

Using $ref in array query parameter #1145

alecmev opened this issue Jan 2, 2017 · 4 comments · May be fixed by Centaurioun/swagger-editor#8

Comments

@alecmev
Copy link

alecmev commented Jan 2, 2017

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?

@webron
Copy link
Contributor

webron commented Jan 10, 2017

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.

@webron webron closed this as completed Jan 10, 2017
@gjorgic
Copy link

gjorgic commented Feb 6, 2017

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?

@webron
Copy link
Contributor

webron commented Feb 6, 2017

@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.

@elharony
Copy link

elharony commented Dec 1, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants