swagger-api / swagger-api/swagger-codegen

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

Open
#11,870 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect the typescript-fetch templates behind BaseAPI, RequiredError, and *ApiFetchParamCreator; first reproduce generation with the supplied OpenAPI definition and TypeScript 4.7.3. Done means the generated client passes TypeScript checking without the reported initializer or delete-operator errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.