[BUG] [typescript-angular]: objects as query parameters break when fields are null
Created by: daniel-frak
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output?
Description
When using the "objects as query parameter" support introduced in #4407, NULL fields cause an exception TypeError: Cannot convert undefined or null to object
in the addToHttpParamsRecursive
function of the generated service.
openapi-generator version
4.2.3
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: Test API
version: v0.0.1
servers:
- url: http://localhost:8080
paths:
"/myobjects/filtered":
get:
operationId: findAllByFilter
parameters:
- name: filter
in: query
required: true
schema:
"$ref": "#/components/schemas/MyObjectFilter"
responses:
'200':
description: default response
content:
"*/*":
schema:
type: "string"
components:
schemas:
MyObjectFilter:
type: object
properties:
query:
type: string
type:
type: string
enum:
- TYPE1
- TYPE2
Command line used for generation
openapi-generator generate -g typescript-angular -o .generated -i .swagger-spec.json
Steps to reproduce
- Generate the code and copy it to an Angular application
- Create a new MyObjectFilter with
query==null
:
const filter = {
query: null,
type: "TYPE1"
};
- Try to use the service:
this.myObjectService.findAllByFilter(myObjectFilter)
Related issues/PRs
None found.
Suggest a fix
I have found that adding a NULL-check in the generated addToHttpParamsRecursive method seems to fix the issue:
private addToHttpParamsRecursive(httpParams: HttpParams, value: any, key?: string): HttpParams {
if(value == null) {
return httpParams;
}
// Original code starts here...
}