deepObject passes validation when it's an array

Open
#484 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
ruby
Domain
api

Research direction

The bug is in OpenapiParameters::Query#parse_deep_object, where prop_regx fails to match keys like filters and filters[], so the property key becomes nil. Start by reproducing the schema from the issue as a request spec and confirming that filters=foo and filters[]=1&filters[]=2 both pass. Done means both requests fail validation against the object-typed filters parameter, with existing deepObject specs still passing.

Written by the indexing model from the issue text.

Description

I am not sure whether that's on purpose or whether that's a bug, but I've just spotted a (imo) surprising behaviour during deep object validation. Given schema definition like this:

paths:
  /foo:
    get:
      parameters:
        - name: filters
          in: query
          required: false
          style: deepObject
          explode: true
          schema:
            type: object
            properties:
              first:
                type: array
                items:
                  type: string
              second:
                type: array
                items:
                  type: string

When making a request with following params:

  • filters=foo
  • filters[]=1&filters[]=2
    the validation passed.

This surprised me because I'd expect it to fail as neither string nor array should be allowed, should they? Since in rails app you can then access the params[:filters] and it's a string or an array (respectively) it creates a risky precedence.

It's caused by the OpenapiParameters::Query#parse_deep_object where prop_key = key.match(prop_regx)&.[](1) returns nil because the regex won't match keys like filters nor filters[].

Dominant language
Ruby
Stars
222
Forks
27
Avg merge
17h 15m
Merged PRs (30d)
6

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ahx/openapi_first

All issues in ahx/openapi_first

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.