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
  • #3709
"www.w3.org/TR/page-visibility" did not exist on "main"
Closed
Open
Issue created Aug 20, 2019 by Administrator@rootContributor

[BUG] [typescript-fetch] Correctly handle number response

Created by: deluksic

When generating code from a path like this:

    get:
      operationId: getSlider
      description: Gets the slider value
      responses:
        200:
          description: Successfully returned slider location
          content:
            application/json:
              schema:
                type: number
                format: float

A type checking error is encountered:

Type 'TextApiResponse' is not assignable to type 'ApiResponse<number>'.
  Types of property 'value' are incompatible.
    Type '() => Promise<string>' is not assignable to type '() => Promise<number>'.
      Type 'Promise<string>' is not assignable to type 'Promise<number>'.
        Type 'string' is not assignable to type 'number'.  TS2322

    77 |         });
    78 | 
  > 79 |         return new runtime.TextApiResponse(response);
       |         ^
    80 |     }
    81 | 
    82 |    /**

Suggest adding a response handler, something like this to runtime.ts:

export class NumberApiResponse {
    constructor(public raw: Response) { }

    async value() {
        const rawText = await this.raw.text();
        const response = JSON.parse(rawText);
        if (typeof response !== 'number') {
            // this check might be unnecessary
            throw new Error(`Expected response of type 'number', got ${rawText}`)
        }
        return response;
    };
}
Assignee
Assign to
Time tracking