42Crunch / intellij-openapi-editor

OpenAPI (Swagger) Editor plugin for IntelliJ
9 stars 0 forks source link

Style: form, explode: false seems not being handled properly #40

Closed AndreyK7 closed 12 months ago

AndreyK7 commented 1 year ago

Hi,

Add a query parameter with 'explode: false':

    - in: query
      name: names
      description: optional array of strings for filtering item inventories by item names
      required: false
      style: form
      explode: false
      schema:
        type: array
        items:
          type: string
      example: [ name1,name2,name3 ]

Then if using "Try it", you would expect query to look like: names=name1,name2 but in example it adds: names=name1&names=name2

So seems that 'explode:false' is ignored.

ak1394 commented 1 year ago

Hi! I did a quick test and it seem to be working as expected (it honors the 'explode' setting).

Could you perhaps share your OpenAPI file? If not, can you tell if you're using Swagger 2.0 or OpenAPI 3.0.x?

AndreyK7 commented 1 year ago

Hi,

We use openapi: 3.0.0 in the yml file

Can you please try this? Add any endpoint in your yml file, for example "/test" and copy/past code below and then click "Try it" in the plugin UI

 get:
  tags:
    - Test plugin
  summary: Get total item inventories
  operationId: getTotalItemInventories
  parameters:
    - in: query
      name: names
      description: optional array of strings for filtering item inventories by item names
      required: false
      style: form
      explode: false
      schema:
        type: array
        items:
          type: string
      example: [ name1,name2,name3 ]
  responses:
    '200':
      description: ids of items with total rows
      content:
        application/json:
          schema:
            type: object
            required:
              - totalInventories
              - totalRows
            properties:
              totalInventories:
                type: array
                items:
                  type: string
                  format: uuid
              totalRows:
                type: number
                format: int64
                example: 12

I would expect in example to have names just once with comma separated values, but as you can see in the screenshot it adds separate parameter for each value. Thanks!

Screenshot 2023-11-02 at 15 08 22
ak1394 commented 1 year ago

Thanks for the sample! The UI works as expected, it will not change regardless of the 'explode'. UI allows entering query parameters in a convenient manner, and it's up to the rest of the code of 'TryIt' to format and send request accordingly.

It would be a good idea to show the request as we send it though. We plan to do in the future versions. For now you can try the OAS below, it uses Httpbin which shows the request it receives.

When sending requests I see that query parameters change depending on the 'explode' setting:

explode: false - https://httpbin.org/anything?names=name1,name2,name3 explode: true - https://httpbin.org/anything?names=name1&names=name2&names=name3

openapi: 3.0.0
info:
  title: Test OpenAPI

servers:
  - url: https://httpbin.org

paths:
  /anything:
    get:
      tags:
        - Test plugin
      summary: Get total item inventories
      operationId: getTotalItemInventories
      parameters:
        - in: query
          name: names
          description: optional array of strings for filtering item inventories by item names
          required: false
          style: form
          explode: false
          schema:
            type: array
            items:
              type: string
          example: [ name1,name2,name3 ]
      responses:
        '200':
          description: ids of items with total rows
          content:
            application/json:
              schema:
                type: object
                required:
                  - totalInventories
                  - totalRows
                properties:
                  totalInventories:
                    type: array
                    items:
                      type: string
                      format: uuid
                  totalRows:
                    type: number
                    format: int64
                    example: 12
AndreyK7 commented 12 months ago

Hi,

Thank you for your clarification about UI and actual request.

I didn't know about these UI limitations, I've tested it now and can now see that actual request is handling "explode: false" properly.

It would be indeed helpful to show actual request in UI. Thanks!

ak1394 commented 12 months ago

Thanks for confirming! As well, we plan to update TryIt to show the actual request that has been sent.