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

Accept array parameters in request body regardless of name convention #2473

Open
CristhianMotoche opened this issue Mar 6, 2024 · 2 comments

Comments

@CristhianMotoche
Copy link

CristhianMotoche commented Mar 6, 2024

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.

Copy link

github-actions bot commented Mar 8, 2024

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

@lopenchi
Copy link

lopenchi commented May 29, 2024

@brendarearden is there any update of this bug? 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants