prism
prism copied to clipboard
Accept array parameters in request body regardless of name convention
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.
This ticket has been labeled jira. A tracking ticket in Stoplight's Jira (STOP-345
) has been created.
@brendarearden is there any update of this bug? 👀