question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optional array query params with enum are always sent after try out with non empty params

See original GitHub issue

Q&A (please complete the following information)

  • OS: macOS
  • Browser: chrom
  • Version: Chrome Version 72.0.3626.96 (Official Build) (64-bit)
  • Method of installation: https://editor.swagger.io/
  • Swagger-UI version: Not sure
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Example Swagger/OpenAPI definition:

openapi: '3.0.0'
info:
  description: >-
    Repro API
  title: Repro API
  version: '1.0'
paths:
  /test:
    get:
      summary: Test get
      parameters:
        - name: fields
          in: query
          required: false
          allowEmptyValue: false
          schema:
            type: array
            items:
              type: string
              enum:
                - friends
                - family
          example:
            - friends
          style: form
      responses:
        200:
          description: Success!
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: integer
                  name:
                    type: string

Swagger-UI configuration options:

Not sure; default?
No QueryStringConfig

Describe the bug you’re encountering

To reproduce…

Steps to reproduce the behavior:

  1. Click on ‘GET /test Test get’
  2. Click on ‘Try it out’
  3. Deselect “friends” by command+click; Or select ‘–’
  4. Click on ‘Execute’
  5. Check ‘Request URL’

Expected behavior

Expect ‘Request URL’ being: https://editor.swagger.io/test

Screenshots

screen shot 2019-02-12 at 11 41 38 am

Additional context or thoughts

This issue is similar to but different from #4223. There will be no problem if array items don’t have enum. The example is not required. It is there just to give a non-empty value to start with. As mentioned in the title, I do need to do a try out with some value(s) like “friends” if there is no example. In another word, it seems I couldn’t clear the field after the first, non-empty, try out.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
h4sohailcommented, Jul 27, 2021

This issue forced us to modify our validation and allow an empty string (which is a sort of a hack) as a query param, it would be great if selecting “–” option would just simply not send that param instead of sending it empty.

2reactions
pyce-lbcommented, Sep 10, 2021

@h4sohail as a work around you can Ctrl+Left Click on any previously selected values to unselect them, nevertheless I agree with your suggestion:

it would be great if selecting “–” option would just simply not send that param instead of sending it empty.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Enums as Request Parameters in Spring | Baeldung
Learn how to use enums as request parameters in Spring REST controllers and how to handle exceptions triggered by invalid input.
Read more >
Pass Array into ASP.NET Core Route Query String
NET Core 3, while trying to pass in a string Array. I solved it by passing in the query parameter as a temporary...
Read more >
Describing Parameters - Swagger
A constant parameter is always sent by the client, whereas the default value is something that the server uses if the parameter is...
Read more >
Resolvers - Apollo GraphQL Docs
If you don't define a resolver for a particular field, Apollo Server automatically ... A query always "bottoms out" on fields that return...
Read more >
MySQL 8.0 Reference Manual :: 11.3.5 The ENUM Type
An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found