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

fix: array initial value to be undefined on try it out #9258

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

G4brym
Copy link

@G4brym G4brym commented Sep 27, 2023

Description

When using the "Try it out" on a endpoint with a parameter that is an array and has an example value, that example value is defined as initial value for that parameter, despite the UI rendering the array with 0 item.

Motivation and Context

Example, this endpoint in the image bellow, has a single parameter that's an array of string and includes an example, when you click Try it out, the parameter renders with 0 items, so you would assume that when trying this endpoint no query parameters would be sent, but in reality the swagger-ui is sending the example value in the request:

2 possible solutions for this:

  • when you click Try it out, all arrays with examples start with 1 item prefill with example value
  • or because arrays start with 0 items by default, don't use the example in that parameter as the initial value for it.

I think the latter is the best approach and the one that would change the little.
This pull request also implements the latter.

How Has This Been Tested?

I've tested this change using this example openapi.json schema:

{
   "openapi":"3.1.0",
   "info":{
      "version":"1.0.0",
      "title":"OpenAPI"
   },
   "components":{
      "schemas":{
         
      },
      "parameters":{
         
      }
   },
   "paths":{
      "/api/v1/netflows/top/ases":{
         "get":{
            "operationId":"get-netflows-top-ases",
            "parameters":[
               {
                  "schema":{
                     "type":"array",
                     "items":{
                        "type":"string",
                        "format":"date-time"
                     },
                     "description":"Array of datetimes to filter the end of a series.",
                     "example":"2023-09-01T11:41:33.782Z"
                  },
                  "required":false,
                  "name":"dateEnd",
                  "in":"query"
               }
            ],
            "responses":{
               
            }
         }
      }
   },
   "webhooks":{
      
   }
}

To test this, just run this schema in the latest release of swagger-ui vs this pr version, and click try it out, then execute without changing any parameters.

Screenshots (if appropriate):

image

Checklist

My PR contains...

  • No code changes (src/ is unmodified: changes to documentation, CI, metadata, etc.)
  • Dependency changes (any modification to dependencies in package.json)
  • Bug fixes (non-breaking change which fixes an issue)
  • Improvements (misc. changes to existing features)
  • Features (non-breaking change which adds functionality)

My changes...

  • are breaking changes to a public API (config options, System API, major UI change, etc).
  • are breaking changes to a private API (Redux, component props, utility functions, etc.).
  • are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
  • are not breaking changes.

Documentation

  • My changes do not require a change to the project documentation.
  • My changes require a change to the project documentation.
  • If yes to above: I have updated the documentation accordingly.

Automated tests

  • Not sure if this can be tested by unit.
  • My changes can not or do not need to be tested.
  • My changes can and should be tested by unit and/or integration tests.
  • If yes to above: I have added tests to cover my changes.
  • If yes to above: I have taken care to cover edge cases in my tests.
  • All new and existing tests passed.

@G4brym G4brym changed the title Fix array initial value on try it out fix: array initial value to be undefined on try it out Sep 28, 2023
@seryckd
Copy link

seryckd commented Nov 15, 2023

We have this issue as well. +1 for incorporating this fix.

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 this pull request may close these issues.

None yet

2 participants