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

Support nested arrays of primitive values inside of objects #120

Merged
merged 2 commits into from
Oct 3, 2024

Conversation

czechboy0
Copy link
Collaborator

Motivation

It's a useful pattern to define a single JSON schema for all your (e.g. query) parameters, and handle them as a single object in your code.

In OpenAPI, that'd be expressed like this, for example:

# parameter
name: myParams
in: query
explode: true
style: form
schema:
  $ref: '#/components/schemas/QueryObject'

# schema
QueryObject:
  type: object
  properties:
    myString:
      type: string
    myList:
      type: array
      items:
      	type: string

Until now, the myList property would not be allowed, and would fail to serialize and parse, as arrays within objects were not allowed for form style parameters (used by query items, by default).

Modifications

This PR extends the support of the form style to handle single nesting in the top level objects. It does not add support for arbitrarily deep nesting.

As part of this work, we also now allow the deepObject style to do the same - use arrays nested in an object.

Result

The useful pattern of having an array within a "params" object works correctly now.

Test Plan

Added unit tests for all 4 components: encoder, decoder, serializer, and parser.

Copy link
Collaborator

@simonjbeaumont simonjbeaumont left a comment

Choose a reason for hiding this comment

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

Thanks! One question about whether we need to break out this type.

@czechboy0 czechboy0 merged commit da2e5b8 into apple:main Oct 3, 2024
18 checks passed
@czechboy0 czechboy0 deleted the hd-support-nested-arrays-in-params branch October 3, 2024 15:17
@czechboy0 czechboy0 added the semver/patch No public API change. label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants