-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[BUG][typescript-fetch] Output is now nested in a "src" folder which breaks typescript package references #3694
Comments
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
@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. |
@macjohnny I lack the tooling setup and Java expertise to feel comfortable making sweeping changes to the underlying generator class. I'm just not familiar with the tooling or setup, even if the actual code changes aren't that large. I could work on revising the mustache templates to produce a valid output package. As it is today, the generated package.json has the wrong paths for the /dist files anyway. My current work around is to actually use OAG v4.0.3 with a custom template pulled from the master branch. Something like:
I can work on the templates to make sure they produce a valid npm package. Is it possible to coordinate two PRs that depend on each other if someone else can make the underling generator changes? |
@JFCote Can you go into any more detail about what is/was wrong with the package? Did you expect the output of OpenAPI Generator to produce both the typescript source code for the package as well as the compiled javascript? I think you will always need to run |
@fuzzzerd First, what is As for your question: The problem was that the npm package contained My changes simply:
I followed this article: https://medium.com/cameron-nokes/the-30-second-guide-to-publishing-a-typescript-package-to-npm-89d93ff7bccd You can see there is an |
Sorry: OAG = OpenAPI Generator (updated my post). |
@JFCote your explanation makes sense. I used OpenAPI Generator to produce a folder with the package inside. I called it The changes in the PR effectively break that use case; but I don't have a full grasp of the different ways the npm package references can work, especially with webpack and typescript. I'll do some additional investigative work and see if there's a way to make it work for both use cases. |
@fuzzzerd Like I said earlier, I'm no typescript / npm expert. If I understand correctly, you generate the default fetch-client, not the npm one but you seem to fake an npm import. Maybe that's the problem? Since you don't use npm, why don't you just import the folder with a normal Like this:
Sorry if that doesn't make sense, I'm probably not the best person to help you here :) |
This makes sense and is how I use it in my project if the package is not published. the more I think about it, the more I am in favor of leaving the code as it is now, as the npm package isn't intended to be used as an npm package without compilation, which means, the generated |
To be clear, I am using the generated client as an npm package, just not one that is published to public npm repository. My package.json looks like this:
Having said that, as it stands today in master, the I would love official guidance on how to properly consume the generated typescript-fetch clients, as its entirely possible what I'm doing is off the blessed path. The documentation on the main website is sorely lacking in that department. |
when changing into the generated package and building with
I get
which seems correct. concerning the docs, you are right, documentation of the usage of the generated code could be improved, but please have a look at the generated Readme |
I may have spoke out of turn. I am not able to reproduce my issue of having I think my issue might be related to adding of the sub folder 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 was able to get things working, there were two things I had to change.
With the client as-generated, when I did an This allowed my main project to compile with typescript, but generated a run time error.
This leaves me with two deviations from the as-generated code from v4.1.0. I think the change to |
FWIW: the error I get at run time, is this:
as mentioned above, changing the generated tsconfig.json to |
I also found this: suggesting |
this is the reason why the generated api client should be either
you can also specify the |
@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. 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 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. |
Closing this issue and continuing discussion in chat. If we found a real problem, let's create a new issue with the problem. |
I have run into many issues with this breaking change to openapi-generator typescript-fetch and it seems strongly like #3403 should be reverted.
It is not that simple because typescript-fetch creates a new tsconfig.json file. This typescript generator should not generate a tsconfig.json file. #3403 has changed typescript-fetch to generate both: typescript-fetch should not output code which assumes its going to be used in an NPM package. Not all javascript nor typescript gets put in an NPM package. It especially should not output code which assumes it will be the primary constituent of an NPM package. If people want openapi-generator to also be able generate scaffolding for an NPM package then I would suggest that either: It seems illogical that typescript-fetch is currently outputting typescript code which can only be used to generate Javascript code (throwing away the Typescript code after doing so) to be used as an NPM package. |
@rob-deutsch I agree that this change caused some troubles, which I was already concerned about before it was merged (#3403 (review)) Lines 147 to 149 in 99204ec
@rob-deutsch would you like to implement this? |
@macjohnny I agree, I've come to the same conclusion in another issue but I can't find it right now. It seems I forgot an "if" when I did the PR. I currently don't have the time to do it myself but if @rob-deutsch do it, I'll be happy to review it. |
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 Can we add a flag to opt out of this path somehow? |
Would simply adding a symlink pointing from |
@brendandburns according to this change the |
Bug Report Checklist
Description
Changes in this commit introduced several related bugs.
src
folder./dist
folder for the generated client code.openapi-generator version
v4.0.3 => v4.1.0
Suggest a fix
src
folderThe text was updated successfully, but these errors were encountered: