Skip to content

Assign query keys matching patternProperties to exploded object params - #526

Open
chuvayva wants to merge 1 commit into
interagent:masterfrom
chuvayva:pattern-properties-query-keys
Open

chuvayva wants to merge 1 commit into
interagent:masterfrom
chuvayva:pattern-properties-query-keys

Conversation

@chuvayva

Copy link
Copy Markdown

Closes #525.

A form-exploded object query parameter can describe its keys with patternProperties instead of properties. No query key was assigned to such a parameter, so strict_query_params reported every key as unknown, and without strict mode the keys were never validated against the patterns.

Now a query key goes into that parameter when it matches one of its patternProperties. openapi_parser then validates and coerces it against the matching schema, and the key no longer counts as unknown.

The rule stays narrow, as proposed in the issue:

  • Only keys that match a pattern are assigned. A key that matches nothing stays unknown.
  • A key that names another parameter, or a property of any exploded object, keeps its current meaning.
  • A key that matches the patterns of two parameters is assigned to neither.
  • Non-exploded objects and deepObject keys are unchanged.

With the repro from the issue:

?page=1&score_gteq=50       => 200 {"page" => 1, "filters" => {"score_gteq" => 50}}
?page=1&score_gteq=50&foo=1 => Unknown query parameter(s): foo

A form-exploded object parameter with patternProperties received no query
keys, so strict_query_params reported them as unknown and they were never
validated. Assign a key to the parameter when it matches one of its
patterns and nothing else declares it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# @param [Array<OpenAPIParser::Schemas::Parameter>] params_for_location
# @param [Hash] raw_params
# @return [Hash{String => Array}] parameter name → assigned raw keys
def pattern_property_keys(params_for_location, raw_params)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (blocking): the new pattern matching also runs on header parameters. Matching request headers are moved into the object parameter.

deserialize_headers uses the same deserialize_params_by_location path. exploded_form_object? treats style: nil as form, but the default style for headers is simple. I ran this case against this branch: a header parameter X-Meta with an object schema and the pattern ^X-.

deserialize_headers({ 'X-Request-Id' => 'abc', 'Accept' => 'json' })
# => {"X-Meta" => {"X-Request-Id" => "abc"}, "Accept" => "json"}

X-Request-Id no longer appears at the top level of committee.headers. The declared-properties branch already had this mismatch, but this PR spreads it to any header that matches a regex. That is a much wider net. The PR description limits the change to query keys, so the simplest fix is to guard on location:

def pattern_property_keys(params_for_location, raw_params, location)
  return {} unless location == 'query'
  ...

A better fix is to make exploded_form_object? resolve the style with the existing default_style(location) helper, so nil doesn't always mean form. That would fix the older properties case as well. Please add a header test either way.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ from a claude code session, so do let me know if anything seems off (seemed reasonable/accurate to me)

@geemus geemus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds and looks good overall, just one gotcha around headers for you to please resolve and I think it should be good.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exploded query object with patternProperties: keys are reported as unknown parameters

2 participants