Fix OpenAPI array and object parameter serialization - #7
Merged
Conversation
Signed-off-by: Antonio Gamez Diaz <antonio.gamez@suse.com>
Signed-off-by: Antonio Gamez Diaz <antonio.gamez@suse.com>
Member
|
Sorry, this PR has escaped my attention. Much appreciated, thank you! |
Fold the redundant simple-style cases into the trailing default (both comma-join), reuse buildParts() for the matrix object branches, and replace the escapeFn func parameter with an escapePath bool. Behavior unchanged; TestSerializeParameter passes as-is.
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.
Description
This PR fixes the incorrect serialization of array and object parameters in OpenAPI operations by taking into account the
styleandexplodefields. I've tried to follow https://spec.openapis.org/oas/latest.html#parameter-objectLet's assume we have an operation accepting a query parameter (e.g.,
severity=["debug", "info", "warning", "critical"]), the MCP server was incorrectly serializing them using Go's default string formatting, resulting in malformed URLs:Before (incorrect):
GET /foo?severity=%5Bdebug+info+warning+critical%5D, that is,GET/foo?severity=[debug+info+warning+critical], URL-decoded.After (correct):
GET /foo?severity=debug&severity=info&severity=warning&severity=criticalNote: The default serialization method is
style: formandexplode: true. Source,The code was using
fmt.Sprintf("%v", val)to convert parameter values to strings, which works for primitives but produces Go's string representation for arrays ([item1 item2 item3]) and objects (map[key:value]). This doesn't match any valid OpenAPI serialization format.The main changes of this PR are:
formatParameterValue()to accept schema instead of boolean flagserializeParameter()- core serialization logic for all locations (path, query, header, cookie) and styles (simple, label, matrix, form, spaceDelimited, pipeDelimited, deepObject) whether it be with explode set as true or false.serializeQueryParameter(),serializePathParameter(),serializeHeaderParameter(),serializeCookieParameter()TestSerializeParameter()with comprehensive test cases based on Swagger documentation examples