Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mxhxgn opened this issue Aug 16, 2022 · 2 comments · May be fixed by swagger-api/swagger-codegen-generators#1342
Open

Comments

@mxhxgn
Copy link

mxhxgn commented Aug 16, 2022

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)

chrisdrifte added a commit to chrisdrifte/swagger-codegen that referenced this issue Mar 14, 2023
It looks like there's a couple typos that cause compilation to fail. I implemented the first two changes suggested in swagger-api#11870 as that is what allowed me to build in typescript 4.9.5.
@onigoetz
Copy link

onigoetz commented May 8, 2025

I'm encoutering the same issue.

I see that a PR was done for the 2.x branch but not for 3.x.

I would like to make a PR but can't find the templates in the 3.x branch, where are they?

@onigoetz
Copy link

onigoetz commented May 8, 2025

Found it and created a PR: swagger-api/swagger-codegen-generators#1342

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants