OpenAPITools / OpenAPITools/openapi-generator

[BUG] Cannot generate Typescript fetch index.ts supporting files independently

Open
#10,302 7 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
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

For the Typescript Fetch generator, I need to be able to generate index.ts files inside the models directory without having to generate apis at all. Currently this is not possible because of what seems to be an oversight or a bug.

openapi-generator version

5.2.1

OpenAPI declaration file content or url

Irrelevant.

Generation Details
openApiGenerate {
    generatorName = "typescript-fetch"
    inputSpec = "foo/bar.yml"
    outputDir = "$projectDir/src"
    configOptions = [
            supportsES6: "true",
            typescriptThreePlus: "true"
    ]
    globalProperties = [
            apis: "",
            models: "",
            supportingFiles: "index.ts"
    ]
}
Steps to reproduce

Use the above configuration in Gradle to generate Typescript fetch code. This works beautifully but generates both the apis and models directory. I don't want the former, so I delete apis: "" from the configuration above and the nested index.ts file inside models fails to generate properly.

Related issues/PRs

Haven't seen any.

Suggest a fix

Pretty sure I see what the problem is:

The index.ts file I'm after is being generated by method TypeScriptFetchClientCodegen::postProcessOperationsWithModels.
This method is only invoked by the parent class DefaultGenerator here. Unfortunately this method is skipped if we indicate that we don't want to generate apis here. This seems to create this coupling between the generation of the apis and models index.ts supporting file.

Sponsorship

I'd be happy to sponsor this fix for $100 @wing328

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

Start in TypeScriptFetchClientCodegen.java at postProcessOperationsWithModels and trace the DefaultGenerator paths referenced in the issue, especially the condition that skips processing when APIs are disabled. Reproduce the Gradle configuration with globalProperties for models and supportingFiles, then verify that the models index.ts is generated without an apis directory.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.