OpenAPITools / OpenAPITools/openapi-generator

[BUG] [javascript] Generates incorrect code: `Identifier <name> has already been declared.`

Open
#21,195 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • all checked including master build
Description

javascript generator -> incorrect code

generated/javascript-client/src/model/PersonDTO.js: Identifier 'PersonDTO' has already been declared. (22:6)
  15 |  import PersonDTO from './PersonDTO';
....
  20 |  * @version 0.1.0
  21 |  */
> 22 | class PersonDTO {
     |       ^
  23 |     /**
  24 |      * Constructs a new <code>PersonDTO</code>.
  25 |      * @alias module:model/PersonDTO 
openapi-generator version
plugins {
    id("org.openapi.generator") version "7.13.0"
}
OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: person contract
  version: 0.1.0
paths:
  /person/{id}:
    parameters:
      - name: id
        in: path
        description: ID of the person
        required: true
        schema:
          type: integer
          format: int64
    get:
      tags:
        - person
      summary: Get a person by id
      operationId: getPerson
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PersonDTO'
components:
  schemas:
    PersonDTO:
      type: object
      required:
        - id
      oneOf:
        - required: [dob]
        - required: [lastName, fullName]
      properties:
        id:
          type: integer
          format: int64
          minimum: 1
        dob:
          type: string
        firstName:
          type: string
          maxLength: 25
          minLength: 5
        lastName:
          type: string
          maxLength: 25
          minLength: 5
        fullName:
          type: string
          maxLength: 25
          minLength: 5
        friend:
          $ref: '#/components/schemas/PersonDTO'

Generation Details
tasks.register<GenerateTask>("generateJsClient") {
    generatorName.set("javascript")
    inputSpec.set(contractPath)
    outputDir.set(jsClientOutputDir)
    additionalProperties.put("usePromises", true)
}

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

Reproduce the issue with the OpenAPI declaration and the generateJsClient Gradle task, then inspect generated/javascript-client/src/model/PersonDTO.js and the JavaScript generator's model and import handling. Done means the generated PersonDTO.js parses successfully without the duplicate Identifier declaration, with coverage for this self-referential oneOf schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.