Closed faragos closed 2 years ago
@faragos Can you please provide a copy of TimeTrackAPI.json
?
I put the JSON into a .txt because GitHub doesn't support .json files.
Is there any update on issue? I'm getting the same error, here's the json file I'm trying to generate on https://yawa-pick-test.azurewebsites.net/swagger/v1/swagger.json
I'm sorry, I'm just hopelessly swamped with other work :disappointed:
I have plans on getting the open issues some attention and get this whole repo over into https://github.com/reduxjs/redux-toolkit, but at the moment it seems like there are always coming things in between :confused:
Thank you for quick response @phryneas . Could you please give me a how to debug this issue. Maybe I can send a fix about it. Is there any contribution or any guideline that i can follow
The error message seems very strange to me as for me it reads like that error seems to appear during printing the code (I assume somewhere in the call stack it will finally end up in https://github.com/rtk-incubator/rtk-query-codegen/blob/next/src/generate.ts#L138, but the trace is cut off so I can't say for sure), which would mean that somewhere an AST node has gotten some seriously weird content.
I would honestly not really know where to start other than connecting the node debugger and breaking on exception, in the hopes of finding the exact AST node that's failing that way.
any updates?
@phryneas if you could give me a hint how to start a debugging session in vscode with my own openapi.json than I could take a look into how to fix this. I'm not a big pro when it comes to nodejs debugging, yet.
@theZieger there is a .vscode/launch.json
in this project, although I think the project has since seen some refactoring.
You theoretically should be able to open src/bin/cli.ts
, set a breakpoint and then just do a "Run and Debug" -> "Current TS File".
I encountered this same issue when trying to convert one of our APIs. For completeness the API docs are from C# generated by Swashbuckle to Swagger and from there we grab the OpenAPI JSON spec.
So I spent a while on this and I think I've found the issue for this which is related specifically to int enums, e.g. "enum": [0,1,2]
.
RTKQ generate.ts
has a method generateEndPoint()
which calls out to another library's (oazapfts) method, getTypeFromResponse
on line 188. On line 404 of the oazapfts library there is a call to createStringLiteral
from the TypeScript library. It is this last method, createStringLiteral
, which is expecting a string value as per the implementation.
So the RTKQ codegen tool fails because it supplies a non string value, which in this case is an int.
Not sure if the fix here is something RTK wants to handle by casting from int to string or if responsibility lies in one of the dependencies. I think it may be eventually situated with the oazapfts repo which already has an issue https://github.com/cellular/oazapfts/issues/45. Although it might be something fixed sooner if implemented in this codegen repo.
A fix that enabled the me to verify the codegen tool was able to complete was by modifying .\node_modules\oazapfts\lib\codegen\generate.js:351
to convert the number to a string with this replacement line: return typescript_1.factory.createLiteralTypeNode(typescript_1.factory.createStringLiteral(String(s)));
. Not a great solution (for short or long term because node_modules shouldn't be modified) but proves the point.
I was able to arrive at this point by tinkering and eventually realised that commenting out ...apiGen['aliases'], got the tool to function. From there is was down a rabbit hole to see where it leads.
@theZieger it's not elegant but my method of debugging was to modify .vscode/launch.json
on line for args
to the following "args": ["${relativeFile}", "test/fixtures/petstore.json", "--file", "test/fixtures/generated.ts", "-h"],
. You could change the file references to something that suits better, but for ease I just replaced the petstore.json
file contents. When launching/restarting the debugger make sure you have open and focused the file src/bin/cli.ts
as @phryneas mentioned. You should hit breakpoints now.
@ashnewport great analysis! I think this should be fixed over in oazapfts - could you please file a PR over there and let me know when it is merged?
@ashnewport thanks for the digging and explanation around debugging. Since I discovered the issue we changed our openapi to use strings instead of integers. Would also prefer seeing this fixed in the library instead having a workaround that must be removed later on again.
@phryneas and @theZieger this has been fixed in the oazapfts repo and the PR is now merged, https://github.com/cellular/oazapfts/pull/169
@phryneas and @theZieger this has been fixed in the oazapfts repo and the PR is now merged, cellular/oazapfts#169
Great, I'll bump the dependency in the upcoming 1.0 beta
The codegen is now published as @rtk-query/codegen-openapi
and the code has moved over to the Redux Toolkit monorepo.
As usage has changed as well, please read the new documentation.
The new release references the new version of oazapfts, so this should be resolved.
When I try to generate an APi with an enum in it it fails. Example enum in a OpenAPI.json:
My call:
The error:
EDIT: it looks like it only happens with int enums :)