-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
[ruby] fix: explode object query parameters #24869
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,7 +180,23 @@ module {{moduleName}} | |
| query_params[:'{{{baseName}}}'] = {{{paramName}}}.to_json | ||
| {{/queryIsJsonMimeType}} | ||
| {{^queryIsJsonMimeType}} | ||
| {{#isMap}} | ||
| {{#isExplode}} | ||
| {{^isDeepObject}} | ||
| # form style, explode: one query parameter per entry, keyed by the property name; nil is left out | ||
| {{{paramName}}}.compact.each { |name, value| query_params[name.to_s] = value } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The generated client already needs a newer ruby than that: master's
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed. will file a pr to update ruby to newer version instead. |
||
| {{/isDeepObject}} | ||
| {{#isDeepObject}} | ||
| query_params[:'{{{baseName}}}'] = {{{paramName}}} | ||
| {{/isDeepObject}} | ||
| {{/isExplode}} | ||
| {{^isExplode}} | ||
| query_params[:'{{{baseName}}}'] = {{{paramName}}} | ||
| {{/isExplode}} | ||
| {{/isMap}} | ||
| {{^isMap}} | ||
| query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}} | ||
| {{/isMap}} | ||
| {{/queryIsJsonMimeType}} | ||
| {{/required}} | ||
| {{/queryParams}} | ||
|
|
@@ -190,7 +206,23 @@ module {{moduleName}} | |
| query_params[:'{{{baseName}}}'] = opts[:'{{{paramName}}}'].to_json if !opts[:'{{{paramName}}}'].nil? | ||
| {{/queryIsJsonMimeType}} | ||
| {{^queryIsJsonMimeType}} | ||
| {{#isMap}} | ||
| {{#isExplode}} | ||
| {{^isDeepObject}} | ||
| # form style, explode: one query parameter per entry, keyed by the property name; nil is left out | ||
| opts[:'{{{paramName}}}'].compact.each { |name, value| query_params[name.to_s] = value } if !opts[:'{{{paramName}}}'].nil? | ||
| {{/isDeepObject}} | ||
| {{#isDeepObject}} | ||
| query_params[:'{{{baseName}}}'] = opts[:'{{{paramName}}}'] if !opts[:'{{{paramName}}}'].nil? | ||
| {{/isDeepObject}} | ||
| {{/isExplode}} | ||
| {{^isExplode}} | ||
| query_params[:'{{{baseName}}}'] = opts[:'{{{paramName}}}'] if !opts[:'{{{paramName}}}'].nil? | ||
| {{/isExplode}} | ||
| {{/isMap}} | ||
| {{^isMap}} | ||
| query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{{paramName}}}'].nil? | ||
| {{/isMap}} | ||
| {{/queryIsJsonMimeType}} | ||
| {{/required}} | ||
| {{/queryParams}} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| openapi: 3.0.3 | ||
| info: | ||
| title: Exploded object query parameters | ||
| description: > | ||
| Object typed query parameters under form/explode (as a free-form object and as a typed map), deepObject, and form without explode. The free-form variant matters because it is flagged isMap but not isContainer. | ||
| version: 1.0.0 | ||
| servers: | ||
| - url: localhost:8080 | ||
| paths: | ||
| /items: | ||
| get: | ||
| operationId: listItems | ||
| parameters: | ||
| # style and explode both left out, so the form/true defaults apply: every entry | ||
| # becomes its own parameter, keyed by the property name alone. | ||
| - in: query | ||
| name: filter | ||
| schema: | ||
| type: object | ||
| # the same, but declared as a map rather than as a free-form object | ||
| - in: query | ||
| name: typedFilter | ||
| schema: | ||
| type: object | ||
| additionalProperties: | ||
| type: string | ||
| # deepObject nests each entry under the parameter name: deepFilter[key]=value | ||
| - in: query | ||
| name: deepFilter | ||
| style: deepObject | ||
| explode: true | ||
| schema: | ||
| type: object | ||
| # form without explode keeps a single parameter carrying the whole object | ||
| - in: query | ||
| name: flatFilter | ||
| style: form | ||
| explode: false | ||
| schema: | ||
| type: object | ||
| responses: | ||
| '200': | ||
| description: a list of items | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: array | ||
| items: | ||
| type: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: A required exploded map passed as
nilwithclient_side_validationdisabled now raisesNoMethodErrorbefore the request is sent. Add the same nil guard used by the optional branch.Prompt for AI agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but it only arises for a required parameter passed as
nilwithclient_side_validationturned off, which is a caller error the validation exists to catch. With validation on (the default) the call fails earlier with the usual "Missing the required parameter" message. I have left it rather than add a nil guard to the required branch, since a guard there would silently send the request without a required parameter.