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
  • #2870
Closed
Open
Issue created May 11, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][typescript-fetch] Typescript error in generated code for endpoint returning type boolean

Created by: matthewbpt

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? 4.0.0-beta3 from npm
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

When generating the typescript api client, the generated client has type errors for any methods returning a boolean.

export class UserApi extends runtime.BaseAPI {

    async userEmailExistsRaw(requestParameters: UserEmailExistsRequest): Promise<runtime.ApiResponse<boolean>> {
        if (requestParameters.email === null || requestParameters.email === undefined) {
            throw new runtime.RequiredError('email','Required parameter requestParameters.email was null or undefined when calling userEmailExists.');
        }

        const queryParameters: runtime.HTTPQuery = {};

        const headerParameters: runtime.HTTPHeaders = {};

        const response = await this.request({
            path: `/api/1.0/users/userExists/{email}`.replace(`{${"email"}}`, encodeURIComponent(String(requestParameters.email))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        });

        return new runtime.TextApiResponse(response);
    }

    async userEmailExists(requestParameters: UserEmailExistsRequest): Promise<boolean> {
        const response = await this.userEmailExistsRaw(requestParameters);
        return await response.value();
    }
}

The return statement from userEmailExistsRaw has error:

Type 'TextApiResponse' is not assignable to type 'ApiResponse<boolean>'.
  Types of property 'value' are incompatible.
    Type '() => Promise<string>' is not assignable to type '() => Promise<boolean>'.
      Type 'Promise<string>' is not assignable to type 'Promise<boolean>'.
        Type 'string' is not assignable to type 'boolean'.ts(2322)
openapi-generator version

4.0.0-beta3 from npm

OpenAPI declaration file content or url
---
swagger: '2.0'
info:
  description: Operations related to the API
  version: '1.0'
  title: API
host: api.example.com
basePath: "/"
tags:
- name: User
  description: All apis relating to Users
schemes:
- http
- https
produces:
- application/xml
- application/json
paths:
  "/api/1.0/users/userExists/{email}":
    get:
      tags:
      - User
      operationId: userEmailExists
      parameters:
      - name: email
        in: path
        description: email
        required: true
        type: string
      responses:
        '200':
          description: Successfully retrieved result!
          schema:
            type: boolean
  "/api/1.0/users/id/{id}":
    get:
      tags:
      - User
      summary: Get specific User by id
      operationId: findUserById
      parameters:
      - name: id
        in: path
        description: id
        required: true
        type: integer
        format: int64
      responses:
        '200':
          description: Successfully retrieved result!
          schema:
            "$ref": "#/definitions/UserDto"
definitions:
  UserDto:
    type: object
    required:
    - id
    - email
    - firstName
    - lastName
    properties:
      id:
        type: integer
        format: int64
      email:
        type: string
      firstName:
        type: string
      lastName:
        type: string
    title: UserDto
Command line used for generation

openapi-generator generate --additional-properties supportsES6=true -i ./openapi.yaml -g typescript-fetch -o out/typescript-fetch

Steps to reproduce

Save yaml to openapi.yaml in current directory and run the command above.

Suggest a fix

Since true and false are both valid json responses, should the return statement simple be return new runtime.JSONApiResponse(response); (This also satisfies the typechecker)

Assignee
Assign to
Time tracking