swagger-api / swagger-editor

Swagger Editor
https://editor.swagger.io
Apache License 2.0
8.86k stars 2.24k forks source link

Duplicate Array created: Error: Value must be a string #3754

Open RobertoDonPedro opened 1 year ago

RobertoDonPedro commented 1 year ago

Hi,

when defining and referencing the following component (in a query parameter)

components:
  schemas:
    data:
      type: object
      properties:  
        return_fields: 
          type: array
          items: 
            type: string
            example: 
              - field1
              - field2
              - field3

the "Try-it-out" description generates

{
  "return_fields": [
    [
      "field1",
      "field2",
      "field3"
    ]
  ]
}

and this validation error occurs

propKeyreturn_fieldserrorindex0errorValue must be a string

As opposed to the "return_fields" object above the API expects an array without duplicate square brackets like so

{
  "return_fields": [
      "field1",
      "field2",
      "field3"
  ]
}

How can I achieve this? ( I tried a lot yet but nothing seems to work) Thanks

Q&A (please complete the following information)

RobertoDonPedro commented 1 year ago

To make the issue more reproducable I also post my query parameter definition here: Thats how my dataquery parameter (that includes the return_fieldsproperty) looks like:

paths:
  /foo/bar:
    get:
      tags:
        - General
      summary: 'FOO BAR '
      description: Foo Bar
      security:
        - basicAuth: []
      parameters:
        - name: data
          in: query
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/data'
      responses:
        '200':
          description: Successful response
          content:
            application/json: {}

According to the Swagger V3 documation Describing Parameters (schema vs content) this should be supported. And I would need it this way since the content of the data parameter has to be json encoded.

I appreciate your help!