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

Uppercase string in filter[] query parameter causes unhandled exception when attempting to call mocked API #1267

Closed
csilcock opened this issue Jun 29, 2020 · 2 comments · Fixed by #1268
Assignees
Labels
bug team/platinum-falcons Team Platinum Falcons
Milestone

Comments

@csilcock
Copy link

csilcock commented Jun 29, 2020

Describe the bug

When attempting to make a call to a mock server running a swaggerfile that specifies an uppercase csv style array filter[] parameter, I encountered the below exception:

(node:90725) UnhandledPromiseRejectionWarning: Error: Space/pipe/comma.. delimited style is only applicable to array parameter
    at DelimitedStyleDeserializer.deserialize (/Users/silcocc/workspace/project-membership/node_modules/@stoplight/prism-cli/node_modules/@stoplight/prism-http/dist/validator/deserializers/style/delimited.js:18:19)
    at /Users/silcocc/workspace/project-membership/node_modules/@stoplight/prism-cli/node_modules/@stoplight/prism-http/dist/validator/validators/params.js:31:41
    at /Users/silcocc/workspace/project-membership/node_modules/lodash/lodash.js:13401:38
    at /Users/silcocc/workspace/project-membership/node_modules/lodash/lodash.js:4905:15
    at baseForOwn (/Users/silcocc/workspace/project-membership/node_modules/lodash/lodash.js:2990:24)
    at Function.mapValues (/Users/silcocc/workspace/project-membership/node_modules/lodash/lodash.js:13400:7)
    at /Users/silcocc/workspace/project-membership/node_modules/@stoplight/prism-cli/node_modules/@stoplight/prism-http/dist/validator/validators/params.js:27:62
    at map_ (/Users/silcocc/workspace/project-membership/node_modules/fp-ts/lib/Option.js:310:72)
    at /Users/silcocc/workspace/project-membership/node_modules/fp-ts/lib/Option.js:366:60
    at Object.pipe (/Users/silcocc/workspace/project-membership/node_modules/fp-ts/lib/function.js:202:38)
(node:90725) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)

Example of a parameter configuration that causes this:

        "parameters": [
          {
            "collectionFormat": "csv",
            "in": "query",
            "items": {
              "format": "uuid",
              "type": "string"
            },
            "name": "filter[somethingId]",
            "required": false,
            "type": "array"
          }
        ],

Whereas the following works fine:

        "parameters": [
          {
            "collectionFormat": "csv",
            "in": "query",
            "items": {
              "format": "uuid",
              "type": "string"
            },
            "name": "filter[somethingid]",     // lowercase i
            "required": false,
            "type": "array"
          }
        ],

To Reproduce

  1. Given the Swagger 2 json file below
  2. Run a mock server using the latest version of prism-cli: ./node_modules/.bin/prism mock -h 0.0.0.0 "./swagger.json"
  3. Make a GET request to the API endpoint: curl --location --request GET 'http://localhost:4010/v1/test'

Expected behavior

The API should response with a 200 OK

Additional context

Environment (remove any that are not applicable):

  • Library version: ^3

I wasn't able to find any similar topics in the community forum @ https://community.stoplight.io/search?q=filter

Full problematic Swagger 2 definition

{
  "consumes": [
    "application/json"
  ],
  "host": "localhost",
  "info": {
    "description": "Example service",
    "title": "Example",
    "version": "1"
  },
  "paths": {
    "/v1/test": {
      "get": {
        "description": "Test API",
        "operationId": "list_test",
        "parameters": [
          {
            "collectionFormat": "csv",
            "in": "query",
            "items": {
              "format": "uuid",
              "type": "string"
            },
            "name": "filter[somethingId]",
            "required": false,
            "type": "array"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "examples": {
              "error": false
            }
          },
          "default": {
            "description": "default",
            "examples": {
              "error": true
            }
          }
        }
      }
    }
  },
  "produces": [
    "application/json"
  ],
  "schemes": [
    "http",
    "https"
  ],
  "swagger": "2.0"
}
@csilcock csilcock added the bug label Jun 29, 2020
@XVincentX
Copy link
Contributor

XVincentX commented Jun 29, 2020

Hey @csilcock

it seems like you found a bug :)

We'll look into this — to workaround this in meantime, you are right; putting the parameter name is lowercase fixes the issue

- filter[somethingId]
+ filter[somethingid]

@XVincentX XVincentX added this to the 2020-06-24 milestone Jun 30, 2020
@XVincentX XVincentX self-assigned this Jun 30, 2020
@XVincentX XVincentX added the team/platinum-falcons Team Platinum Falcons label Jun 30, 2020
@XVincentX
Copy link
Contributor

@csilcock This is now published in 3.3.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug team/platinum-falcons Team Platinum Falcons
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants