-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Description
Description
With the Typescript-angular generator, JSON query parameters are not serialized as JSON.
Instead each field of the object is added independently.
Example (see OpenAPI specification below),
For the following call
const filter = {name: 'John', age: 37};
service.search(filter).subscribe();
I expect a request to http://localhost/search?filter=%7B%22name%22%3A%22John%22%2C%22age%22%3A37%7D
(URL encoded JSON)
But instead it requests http://localhost/search?name=John&age=37
On this branch, I've started to implement tests showing the issue and trying to implement a solution.
openapi-generator version
7.15.0 (was working with 7.4.0, I do not know in which version it stopped to work).
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: query-param-json
version: 1.0.0
paths:
/search:
get:
operationId: search
parameters:
- in: query
name: filter
description: Filter
required: false
content:
application/json:
schema:
$ref: '#/components/schemas/Filter'
responses:
'200':
description: Ok
content:
application/json:
schema:
$ref: '#/components/schemas/Response'
components:
schemas:
Item:
type: object
required:
- name
- age
properties:
name:
type: string
description: The name
age:
type: integer
minimum: 0
default: 5
nullable: false
description: The age
Response:
type: object
required:
- items
properties:
items:
type: array
description: Array of items.
nullable: false
items:
$ref: '#/components/schemas/Item'
Filter:
type: object
properties:
name:
type: string
description: The name
age:
type: integer
minimum: 0
default: 5
nullable: false
description: The age
Generation Details
Typescript-angular
Steps to reproduce
Generate and call the search operation of the service, query params will not be JSON
Related issues/PRs
One must be careful, there seems to have been already several issues regarding the serialization of query parameters for this generator.
A few recent
- [typescript-angular] fix: correctly serialize query params objects #20850
- [Feat][Typescript Angular] Implement deepObject query params (OAS3.0) #21108
Suggest a fix
The issue is that when the method addToHttpParams()
of the file modules/openapi-generator/src/main/resources/typescript-angular/api.base.service.mustache
is called, we have already lost the information that the parameter must be in JSON.
In some way, this must be provided from `modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache``
I've started to implement a fix in master...VladimirSvoboda:openapi-generator:AngularJsonQueryParam
However, due to the lack of tests regarding all the kind of different query parameters serialization, there is a risk that I introduce other regressions.
The fix is not ready yet as I have observed a regression.