Skip to content

[typescript-fetch] result does not compile in typescript 4.7.3 #11870

@mxhxgn

Description

@mxhxgn

Q&A (please complete the following information)

  • OS: [Windows10]
  • Browser: [Firefox]
  • Version: [102.0.1]
  • Method of installation: [npm]
  • Swagger-Editor version: [4.3.0]
  • Swagger/OpenAPI version: [OpenAPI 3.0.0]

  • Visual Studio Code version[1.70.1]
  • nodejs version[16.13.2]
  • npm version[8.1.4]
  • swagger-codegen [3.0.35]
  • Typescript version [4.7.3]

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.0.0
info:
  version: 2022.2.2
  title: a title
  description: a description
servers:
  - url: https://some_url.com
paths:
  /api/x/y:
    post:
      tags:
        - hallo
      description: hallo
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/a'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/a'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/a'
components:
  schemas:
    a:
      type: object
      required:
        - parameters
      properties:
        parameters:
          type: array
          items:
            type: object
            required:
              - name
            properties:
              name:
                type: string
          minItems: 1

Describe the bug you're encountering

The code produced by typescript-fetch does not compile (Typescript check fails) with the following errors:
"Property 'configuration' has no initializer and is not definitely assigned in the constructor."
"Property 'name' has no initializer and is not definitely assigned in the constructor."
"The operand of a 'delete' operator must be optional."

To make it compile, I had to change the following:

In class BaseAPI :
protected configuration: Configuration; is replaced by
protected configuration?: Configuration;

in class RequiredError:
name: "RequiredError" is replaced by
name= "RequiredError"

in classes *ApiFetchParamCreator :
delete localVarUrlObj.search; is replaced by
localVarUrlObj.search=null;

To reproduce...

Steps to reproduce the behavior:

  1. open node_modules/swagger-editor-dist/index.html
  2. load the open api definition provided here
  3. press Generate-Client/typescript-fetch
  4. add the generated code to a nodejs project

Expected behavior

The generated code does not exhibit errors (typescript check does not fail)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions