Skip to content

v3.2: Add in: "querystring" parameter location treating the entire query string as one chunk of content #4590

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

Open
wants to merge 7 commits into
base: v3.2-dev
Choose a base branch
from

Conversation

handrews
Copy link
Member

@handrews handrews commented May 15, 2025

NOTE: This change was tentativley approved for 3.2 a long time ago, then punted to 3.3 when we thought we'd need to defer larger data modeling changes to that release. However, several things have changed that makes this suitable for 3.2 now:

  • All this really does is allow using the Encoding Object in a new place, which we are already doing with PRs v3.2 Respect encoding in all Media Type Objects #4559 and v3.2: Support ordered multipart including streaming #4589. We should really include all of the "use the Encoding Object in more places" changes in one release!
  • We already decided to add the media type registry in 3.2, when at one point we weren't going to do that until 3.3
  • I realized that limiting in: querystring to using content avoids all of the confusing problems of how to deal with the Parameter Object's style/explode/etc. in an environment where they do not make sense (and duplicate the fields in the Encoding Object)


This allows treating the entire query string as a single parameter, which for application/x-www-form-urlencoded results in it being handled exactly as request bodies of that media type are handled.

Only one in: "querystring" is allowed per operation, and if it is present, no in: "query" parameters are allowed.

The content field MUST be used for in: "querystring", as the style and related fields are handled in the Encoding Object.

This also includes a recommendation that implementors design media types for complex query string formats such as those defined by various frameworks, and register a procedure for supporting them in our media type registry. This is intended to address a slow but steady trickle of requests to support various complex and often contradictory query string formats.

  • schema changes are included in this pull request
  • schema changes are needed for this pull request but not done yet
  • no schema changes are needed for this pull request

This allows treating the entire query string as a single parameter,
which for `application/x-www-form-urlencoded` results in it being
handled exactly as request bodies of that media type are handled.

Only one `in: "querystring"` is allowed per operation, and if it
is present, no `in: "query"` parameters are allowed.

The `content` field MUST be used for `in: "querystring"`, as the
`style` and related fields are handled in the Encoding Object.

This also includes a recommendation that implementors design
media types for complex query string formats such as those defined
by various frameworks, and register a procedure for supporting
them in our media type registry.  This is intended to address
a slow but steady trickle of requests to support various complex
and often contradictory query string formats.
@handrews handrews added this to the v3.2.0 milestone May 15, 2025
@handrews handrews requested review from a team as code owners May 15, 2025 21:36
@handrews handrews added enhancement param serialization Issues related to parameter and/or header serialization media and encoding Issues regarding media type support and how to encode data (outside of query/path params) labels May 15, 2025
@handrews handrews changed the title Add in: "querystring" parameter location treating the entire query string as one chunk of content v3.2: Add in: "querystring" parameter location treating the entire query string as one chunk of content May 15, 2025
@davebelais
Copy link

davebelais commented May 16, 2025

@handrews : I just want to confirm my understanding—so that I can plan for related tooling: when we have a parameter which has a in="querystring"—that operation shouldn't have any other parameters which have a in="query", right?

@handrews
Copy link
Member Author

@davebelais replace style with in and then yes. Because querystring consumes the entire part of the URL between ? and # (or the end if no # is present). Trying to come up with rules for how in: querystring and in: query would share that space is way too complex. Plus in: querystring plus the Encoding Object can do everything that a set of in: query parameters can do and more, I believe.

lornajane
lornajane previously approved these changes May 21, 2025
Copy link
Contributor

@lornajane lornajane left a comment

Choose a reason for hiding this comment

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

I LOVE this addition!

Co-authored-by: Lorna Jane Mitchell <[email protected]>
Replace "no defined mapping" with "no registered mapping" and
link to the section about the registry.
@handrews
Copy link
Member Author

This latest commit replaces "no defined mapping" with "no registered mapping" (linking to the section on the registry) in the JSONPath example. It also adds a serialized form to the JSON in: querystring example. (@lornajane I figured your approval got cleared anyway and needs re-adding, so I might as well tweak these).

miqui
miqui previously approved these changes May 24, 2025
@miqui
Copy link
Contributor

miqui commented May 24, 2025

This latest commit replaces "no defined mapping" with "no registered mapping" (linking to the section on the registry) in the JSONPath example. It also adds a serialized form to the JSON in: querystring example. (@lornajane I figured your approval got cleared anyway and needs re-adding, so I might as well tweak these).

@handrews Hi. When I follow the click path (under the overall media type reg section) with respect to the media registry, I end up with this URL: https://spec.openapis.org/registry/media-type/ which is broken (404).

@lornajane lornajane self-requested a review May 24, 2025 16:35
lornajane
lornajane previously approved these changes May 24, 2025
@handrews
Copy link
Member Author

@miqui yeah we still need to put the registry up. It will be published along with 3.2 and 3.1.2, so it's expected to be broken for now.

@karenetheridge
Copy link
Member

Also worth noting -- this solves the "how do I indicate a relationship or dependency between query parameters" usecase -- as this allows for declaring all query parameters as being decoded to a json object, to let us use more complicated json schema constructs e.g. minProperties, if/then/else, anyOf etc.

Note -- We already could do that today, if you squint at the specification the right way, by specifying the right combination of style, explode, and schema/type, but it's not explicitly spelled out in the spec and probably a lot of implementations don't support that right now. This new mechanism makes the implementation much more explicit, and it is also more adaptable to other serialization styles than just application/x-www-form-urlencoded.

Copy link
Member

@karenetheridge karenetheridge left a comment

Choose a reason for hiding this comment

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

A few comments, questions and spelling fixes.

src/oas.md Outdated
Two avenues are available for supporting such formats with `in: "querystring"`:

* Use `content` and `text/plain` with a schema of `type: "string"` and define the format outside of OpenAPI. While this requires more work to document and construct or parse the format, which is seen as a plain string from the OpenAPI perspective, it provides the easiest flexible option
* Define a media type (which need not necessarily be [IANA-registered](https://www.rfc-editor.org/rfc/rfc6838.html)) and submit a registration for how it can be supported (using `in: "querystring"` and the `content` field) to the OpenAPI Initiative's [Media Type Registry](#media-type-registry).
Copy link
Member

Choose a reason for hiding this comment

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

This implies that submitting an entry to the Media Type Registry is required. It of course is not; an implementation could invent its own media type and only support it locally. This would not be interoperable outside of the scope of where the media type is defined, but I could easily see an application or company doing this for "internal" interfaces.

Can we modify this to simply recommend that new media types be submitted to the registry, to facilitate interoperability?

src/oas.md Outdated
Comment on lines 1115 to 1118
example: {
"numbers": [1, 2],
"flag": null
}
Copy link
Member

Choose a reason for hiding this comment

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

I would think this should more properly be:

  example: '{"numbers": [1, 2], "flag": null }'

..as the actual content of the querystring value is a literal json string, not a json object.

@handrews handrews dismissed stale reviews from lornajane and miqui via ebf9a44 May 27, 2025 19:59
It is not necessary to register a media type to use it with
the `content` field.
@handrews
Copy link
Member Author

@karenetheridge great catches here! I have updated accordingly- see if this language about the registry works for you. I am happy to try again if it doesn't quite capture what you have in mind.

karenetheridge
karenetheridge previously approved these changes May 27, 2025
Copy link
Member

@karenetheridge karenetheridge left a comment

Choose a reason for hiding this comment

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

LGTM!

@handrews
Copy link
Member Author

@lornajane @miqui can you re-approve after these fixes of things that @karenetheridge found?

miqui
miqui previously approved these changes May 28, 2025
@handrews
Copy link
Member Author

@karenetheridge now that I am thinking more about this, I think the change to example was incorrect, as JSON/YAML examples do not need to be encoded. And in fact just look like strings if they are. It would be shown as a string if we could use the example field next to content one level up.

I'm going to change that one part back. There's a lot of additional debate around examples right now. so we may need to do a follow-up. I'd like to not hold this up on our example confusion if at all possible, as that applies to many things, and if we need to fix it, we can fix it here along with everywhere else if this PR is already merged.

This is at the Media Type Object level, and JSON examples are
to be written as inline JSON/YAML.  If we were at the Parameter
Object level, we would use the URI percent-encoded string form,
but the example field is not allowed with the content field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement media and encoding Issues regarding media type support and how to encode data (outside of query/path params) param serialization Issues related to parameter and/or header serialization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants