Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #5174
Closed
Open
Issue created Jan 31, 2020 by Administrator@rootContributor5 of 5 checklist items completed5/5 checklist items

[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
  1. Generate the code and copy it to an Angular application
  2. Create a new MyObjectFilter with query==null:
const filter = {
  query: null,
  type: "TYPE1"
};
  1. 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...
}
Assignee
Assign to
Time tracking