OpenAPITools / OpenAPITools/openapi-generator

[BUG] [typescript-redux-query] index.ts overwrites file generated from type named Index

Open
#6,016 0 comments 1 reaction 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
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
Description

If I have a type named Index, the generated index.ts overwrites Index.ts generated from the type.

openapi-generator version

4.3.0

OpenAPI declaration file content or url
openapi: '3.0.0'
info:
  version: 0.0.0
  title: Bug
paths:
  /bug:
    get:
      responses:
        default:
          $ref: '#/components/responses/Response'
components:
  responses:
    Response:
      description: response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Index'
  schemas:
    Index:
      type: string
      enum:
        - foo
        - bar
Command line used for generation

openapi-generator generate -i bug.yaml -g typescript-redux-query -o bug/

Steps to reproduce
  • Generate code with the above command line
  • Check the generated code with tsc bug/src/index.ts
  • You get
bug/src/apis/DefaultApi.ts:19:5 - error TS2305: Module '"../../../../../../Users/thsoft/Temp/bug/src/models"' has no exported member 'Index'.

19     Index,
       ~~~~~

because models/Index.ts was overwritten by models/index.ts.

Related issues/PRs

I found none.

Suggest a fix

There could be two alternatives:

  • Rename models/Index.ts since the file name is arbitrary.
  • Generate no index.ts since it is just a convention (maybe could be disabled by a generator option).

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 provided OpenAPI declaration and the typescript-redux-query command, then inspect how generated models/Index.ts and models/index.ts are produced. Verify the fix by running tsc bug/src/index.ts and confirming the generated Index export is preserved without overwriting.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.