prism icon indicating copy to clipboard operation
prism copied to clipboard

Accept array parameters in request body regardless of name convention

Open CristhianMotoche opened this issue 11 months ago • 2 comments

Accept array parameters with our without [] in the variable name.

Context

Accept requests where the parameters in the body are defined with [] or without it.

Current Behavior

Given a schema like this:

/v1/pet:
  servers:
  - url: https://pets.example.com
  description: Testing
  post:
    description: Create pet.
    responses:
      '201':
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/pet'
        description: Created
    requestBody:
      content:
        application/x-www-form-urlencoded:
          schema:
            type: object
            title: Body
            properties:
              NickNames:
                type: array
                items:
                  type: string
                description: List of nick names.

Prism won't complain if the request looks like this:

curl -X POST "https://pets.example.com/v1/pet" \
--data-urlencode "NickNames[]=Courage" \
--data-urlencode "NickNames[]=Stupid dog"

Note the parameter is NickName[].

However, the following request will fail:

curl -X POST "https://pets.example.com/v1/pet" \
--data-urlencode "NickNames=Courage" \
--data-urlencode "NickNames=Stupid dog"

Prism mock server will respond with something like:

⬤  debug     < Body: NickNames=Courage&NickNames=Stupid dog
ℹ  info      Request contains an accept header: */*
⚠  warning   Request did not pass the validation rules
✖  error     Request body property NickNames must be array
⬤  debug     Unable to find a 422 response definition
⬤  debug     Unable to find a 400 response definition
⬤  debug     Unable to find a 'default' response definition

Expected Behavior

The request will succeed regardless of the way in which the parameters are coming since I think there isn't a standard way to handle the request parameters for x-www-form-urlencoded requests. FWIW, I looked for this in the W3 Org.

Possible Solution(s)

Identify the request validator and modify it to accept these type of requests.

CristhianMotoche avatar Mar 06 '24 22:03 CristhianMotoche

This ticket has been labeled jira. A tracking ticket in Stoplight's Jira (STOP-345) has been created.

github-actions[bot] avatar Mar 08 '24 17:03 github-actions[bot]

@brendarearden is there any update of this bug? 👀

lopenchi avatar May 29 '24 21:05 lopenchi