-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Closed
Labels
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When using queryParamObjectFormat=json with query param of type array I would expect the request url to look something like
https://example.com/pizzas?sorting=[{"name": 1}, {"price": -1}]
Instead ofhttps://example.com/pizzas?sorting={"name": 1}&sorting={"price": -1}orhttps://example.com/pizzas?sorting={"name": 1},{"price": -1}
openapi-generator version
v5.0.0-beta2
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: 'Sample-API'
version: '1.1.0'
paths:
/pizzas:
get:
parameters:
- name: filter
in: query
content:
application/json:
schema:
$ref: '#/components/schemas/PizzaFilter'
- name: sorting
in: query
content:
application/json:
schema:
$ref: '#/components/schemas/PizzaSorting'
responses:
200:
description: Delicious pizzas
content:
application/json:
schema:
type: array
items:
type: string
components:
schemas:
PizzaFilter:
type: object
additionalProperties: true
PizzaSorting:
type: array
items:
type: object
minProperties: 0
maxProperties: 1
additionalProperties:
type: integer
enum:
- 1
- -1Generation Details
Steps to reproduce
npx @openapitools/openapi-generator-cli version-manager set 5.0.0-beta2
npx @openapitools/openapi-generator-cli generate -i spec.yaml -g typescript-angular -o ./generated --additional-properties=queryParamObjectFormat=jsonRelated issues/PRs
Suggest a fix
I think isQueryParamObjectFormatJson should be checked here
Lines 177 to 198 in d8ba49b
| {{#queryParams}} | |
| {{#isListContainer}} | |
| if ({{paramName}}) { | |
| {{#isCollectionFormatMulti}} | |
| {{paramName}}.forEach((element) => { | |
| queryParameters = this.addToHttpParams(queryParameters, | |
| <any>element, '{{baseName}}'); | |
| }) | |
| {{/isCollectionFormatMulti}} | |
| {{^isCollectionFormatMulti}} | |
| queryParameters = this.addToHttpParams(queryParameters, | |
| {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}']), '{{baseName}}'); | |
| {{/isCollectionFormatMulti}} | |
| } | |
| {{/isListContainer}} | |
| {{^isListContainer}} | |
| if ({{paramName}} !== undefined && {{paramName}} !== null) { | |
| queryParameters = this.addToHttpParams(queryParameters, | |
| <any>{{paramName}}, '{{baseName}}'); | |
| } | |
| {{/isListContainer}} | |
| {{/queryParams}} |
Maybe something like this could work:
{{#queryParams}}
{{#isListContainer}}
if ({{paramName}}) {
{{#isQueryParamObjectFormatJson}}
queryParameters = this.addToHttpParams(queryParameters,
<any>{{paramName}}, '{{baseName}}');
{{/isQueryParamObjectFormatJson}}
{{^isQueryParamObjectFormatJson}}
{{#isCollectionFormatMulti}}
{{paramName}}.forEach((element) => {
queryParameters = this.addToHttpParams(queryParameters,
<any>element, '{{baseName}}');
})
{{/isCollectionFormatMulti}}
{{^isCollectionFormatMulti}}
queryParameters = this.addToHttpParams(queryParameters,
{{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}']), '{{baseName}}');
{{/isCollectionFormatMulti}}
{{/isQueryParamObjectFormatJson}}
}
{{/isListContainer}}
{{^isListContainer}}
if ({{paramName}} !== undefined && {{paramName}} !== null) {
queryParameters = this.addToHttpParams(queryParameters,
<any>{{paramName}}, '{{baseName}}');
}
{{/isListContainer}}
{{/queryParams}}Reactions are currently unavailable