openapi-generator: [BUG][typescript-fetch] Output is now nested in a "src" folder which breaks typescript package references

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

Changes in this commit introduced several related bugs.

  1. Output is now partially nested within a new src folder.
  2. package.json.mustache was not updated to reflect this change
  3. breaks anyone who was using local npm package references with typescript to avoid creating a separate /dist folder for the generated client code.
openapi-generator version

v4.0.3 => v4.1.0

Suggest a fix
  • Revert the folder name change.
  • Add a flag to opt in or out of the new src folder
  • Update the mustache templates accordingly.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 25 (24 by maintainers)

Most upvoted comments

I wanted to revisit this, we want to switch to this generator, but we are generating as a sub-folder within a larger npm package. This means we can’t use the typescript-fetch generator because it hard codes the src path when the right home for this code in our package is src/gen/...

Can we add a flag to opt out of this path somehow?

@fuzzzerd May I suggest we close this issue and continue this conversation in the chat room. Core members, template generator and users should be able to answer your questions.

https://join.slack.com/t/openapi-generator/shared_invite/enQtNzAyNDMyOTU0OTE1LTY5ZDBiNDI5NzI5ZjQ1Y2E5OWVjMjZkYzY1ZGM2MWQ4YWFjMzcyNDY5MGI4NjQxNDBiMTlmZTc5NjY2ZTQ5MGM

I think your main problem is not an OpenApi Generator but a comprehension one. There are multiple options for the fetch client, check the “samples” here: https://github.com/OpenAPITools/openapi-generator/tree/master/samples/client/petstore/typescript-fetch/builds

Unless I’m mistaken, you are generating the default one (without any special parameters). This usually means that you should simply copy it in a folder in your project and import it like any other class in your project. You don’t need a “node_module” folder, you don’t need to add anything to your package.json.

But just the fact that you have a package.json let me think that you are dealing with a node project so you should consider using the npm version with the appropriate generator options. But if you use it that way, you should publish it to be able to import it. We use Verdaccio where I work as a repository.

Again, don’t worry, I have been there not so long ago 😃 Explore the different options of the fetch generator and find the one for you. Don’t hesitate to ask for help in the official chat room.

I may have spoke out of turn. I am not able to reproduce my issue of having /dist/src/... in the output.

I think my issue might be related to adding of the sub folder src and me not knowing that happened, so running subsequent updates still had my old generated client. Let me do more a bit more digging and see if I can’t get it working with a clean slate.

I’ll close the issue if its an issue on my end or update with what I did and what I got that isn’t working.

@macjohnny I’m no expert in typescript/npm but I did these changes to fix the npm version that wasn’t working at all when it was time to publish (there was no compiled code in resulting npm package).

I don’t mind of the folder structure in the end. That was done to follow good practice in typescript npm package.

So, if the new PR still provide a valid output when publishing npm package, that’s good for me. Simply reverting #3403 will break the npm publishing so it’s not a valid solution.

Let me know when the PR is ready, I will gladly test it.