Support map-style query parameters (type: object + additionalProperties)#2144
Open
bkoelman wants to merge 2 commits into
Open
Support map-style query parameters (type: object + additionalProperties)#2144bkoelman wants to merge 2 commits into
bkoelman wants to merge 2 commits into
Conversation
…+ additionalProperties)
Add a Map branch to getSanitizedValues so that plain-object dictionary
query parameters are pre-processed before they reach StdUriTemplate.
Without this change, a Map<String, String> value passed through
addQueryParameters or addQueryParameter falls through to the else-return
branch unchanged. When the map contains a null value the subsequent
call to StdUriTemplate.convertNativeTypes(null) throws a
NullPointerException (null.getClass() is called in the fallback throw).
The fix mirrors the kiota-dotnet SanitizeDictionary approach exactly:
null-valued entries are dropped (RFC 6570 para 2.3 treats undefined
variables as absent), and remaining values are normalised to String via
the existing getSanitizedValues pipeline. The sanitized HashMap<String,
String> is returned so StdUriTemplate.isMap/addMapValue can expand it as
individual key=value pairs for RFC 6570 {?param*} templates.
The @SuppressWarnings("unchecked") annotation suppresses the unavoidable
raw-type cast of Map<Object,Object> -- Java generics are erased at
runtime so the cast to the generic Map type is unverifiable by the
compiler, but safe because the entries are accessed only as Object.
Co-authored-by: Cursor <cursoragent@cursor.com>
baywet
requested changes
Jul 23, 2026
| // the variable expansion results in no output". Use "" to send ?key= (empty value). | ||
| @SuppressWarnings("unchecked") | ||
| final Map<Object, Object> rawMap = (Map<Object, Object>) value; | ||
| final HashMap<String, String> sanitized = new HashMap<>(rawMap.size()); |
Member
There was a problem hiding this comment.
same as dotnet, can we use map string object instead to avoid the call to tostring below?
Member
|
CC @andreaTP |
There was a problem hiding this comment.
Pull request overview
Adds support for “map-style” (object + additionalProperties) query parameters by sanitizing Map values before URI template expansion, preventing NullPointerException when map entries contain null values and enabling RFC 6570 {?param*} exploded expansion.
Changes:
- Add
Maphandling toRequestInformation.getSanitizedValuesthat drops null-valued entries and normalizes remaining values. - Add unit tests covering exploded map query parameter expansion, null-handling, and interaction with scalar query parameters.
- Extend the test query-parameter model (
GetQueryParameters) with aquerymap field and include it intoQueryParameters().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| components/abstractions/src/main/java/com/microsoft/kiota/RequestInformation.java | Adds Map sanitization so {?query*} can expand dictionary entries safely (dropping null values). |
| components/abstractions/src/test/java/com/microsoft/kiota/RequestInformationTest.java | Adds tests to validate exploded map query parameter expansion and null-handling behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+486
to
+492
| for (final Map.Entry<Object, Object> entry : rawMap.entrySet()) { | ||
| if (entry.getValue() != null) { | ||
| sanitized.put( | ||
| entry.getKey().toString(), | ||
| getSanitizedValues(entry.getValue()).toString()); | ||
| } | ||
| } |
Contributor
|
seems like a legit change to me 👍 |
…rameters Address PR feedback by using HashMap<String, Object> instead of HashMap<String, String> when sanitizing map query parameters in RequestInformation. This avoids unnecessary .toString() calls on sanitized values and preserves native object types for StdUriTemplate expansion. Also adds null key checks and tests for varied map value types. Co-authored-by: Cursor <cursoragent@cursor.com>
Author
|
Pushed fixes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contributes to microsoft/kiota#3800.
Add a Map branch to getSanitizedValues so that plain-object dictionary query parameters are pre-processed before they reach StdUriTemplate.
Without this change, a Map<String, String> value passed through addQueryParameters or addQueryParameter falls through to the else-return branch unchanged. When the map contains a null value the subsequent call to StdUriTemplate.convertNativeTypes(null) throws a NullPointerException (null.getClass() is called in the fallback throw).
The fix mirrors the kiota-dotnet SanitizeDictionary approach exactly: null-valued entries are dropped (RFC 6570 para 2.3 treats undefined variables as absent), and remaining values are normalised to String via the existing getSanitizedValues pipeline. The sanitized HashMap<String, String> is returned so StdUriTemplate.isMap/addMapValue can expand it as individual key=value pairs for RFC 6570 {?param*} templates.
The @SuppressWarnings("unchecked") annotation suppresses the unavoidable raw-type cast of Map<Object,Object> -- Java generics are erased at runtime so the cast to the generic Map type is unverifiable by the compiler, but safe because the entries are accessed only as Object.