-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Multiple enhancements to typescript fetch generator #145
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
Conversation
It seems it doesn't build into CI but I don't understand why... Any idea guys?
I think shippable fails because the kotlin-server sample is not up-to-date (it fails in the ensure-up-to-date.sh file because regenerating the kotlin-server creates changes in git).
Travis CI (both) fail because typescript-fetch tests are failing: TypeError: fetch is not a function in 24 of 24 test cases.
@TiFu How can I run the test and update them? I don't think there were test before when I was working in swagger-codegen :)
You should be able to run the tests locally with
mvn verify -f samples/client/petstore/typescript-fetch/builds/with-npm-version/pom.xml
You can also check the Travis log for details: https://travis-ci.org/OpenAPITools/openapi-generator/builds/383322883
@JFCote as discussed, the issue probably has to do with TypeScript version update to 2.4. We need to update the Petstore integration tests accordingly.
cc the technical committee to see if anyone has cycle to fix the tests for TS Fetch petstore client.
@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01)
@wing328 I can modify the tests if someone explain me where they are and what they do. Are they unit tests? Do they test the output? Any documentation I can check to update the tests of a generator?
The tests can be found in https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/typescript-fetch/tests/default
Run mvn integration-test in that folder to trigger the test
CI errror log: https://api.travis-ci.org/v3/job/391347920/log.txt
@wing328
When I try to run mvn integration-test in the folder you told me, I get this error:
jcote@MTL3MN7R22-PC MINGW64 /c/dev/openapi-generator/samples/client/petstore/typescript-fetch/tests/default
$ mvn integration-test
[INFO] Scanning for projects...
[INFO]
[INFO] -----------< com.wordnik:TypeScriptFetchPestoreClientTests >------------
[INFO] Building TS Fetch Petstore Test Client 1.0-SNAPSHOT
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:copy-dependencies (default) @ TypeScriptFetchPestoreClientTests ---
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:exec (npm-install) @ TypeScriptFetchPestoreClientTests ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.213 s
[INFO] Finished at: 2018年06月14日T15:20:04-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (npm-install) on project TypeScriptFetchPestoreClientTests: Command execution failed.: Cannot run program "npm" (in directory "C:\dev\openapi-generator\samples\client\petstore\typescript-fetch\tests\default"): CreateProcess error=2, The system cannot find the file specified -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
I don't understand the error with npm since I'm able to run npm install in this folder.
@JFCote what about running the following commands manually in that folder?
npm install
npm test
@wing328 Will try this today and let you know!
@wing328 Didn't have time today, will try in the upcoming days!
msiemens
commented
Jul 17, 2018
I just checked out this PR locally and both mvn verify -f samples/client/petstore/typescript-fetch/builds/with-npm-version/pom.xml and mvn integration-test succeed without errors. Could it be that the tests pass now?
@msiemens 3 of the 5 CI doesn't seems to pass. I will try to resolve the conflict today and see.
# Conflicts: # samples/client/petstore/typescript-fetch/builds/default/.openapi-generator/VERSION # samples/client/petstore/typescript-fetch/builds/es6-target/.openapi-generator/VERSION # samples/client/petstore/typescript-fetch/builds/with-interfaces/.openapi-generator/VERSION # samples/client/petstore/typescript-fetch/builds/with-npm-version/.openapi-generator/VERSION
@msiemens I just fixed the minor conflict with the master with a merge. Let's see how it goes with the CI.
msiemens
commented
Jul 17, 2018
Thanks! Seems to still be failing (at least on Travis, the others are still running). It's strange that I can't reproduce this locally...
@msiemens It seems something is still not working... Don't understand exactly what it is. There is sooooooo much information in the logs I lose myself.
- the shippable build fails because some unrelated files, i.e. the php client samples are outdated: https://app.shippable.com/github/OpenAPITools/openapi-generator/runs/1536/1/console
- the travis build fails with to
TypeError: fetch is not a function, which is strange. maybe an npm package was not correctly installed?
did you re-generate the typescript fetch samples after the merge?
I forgot to actually change the branch when testing on my last try 🙈 Now with the correct branch I can reproduce this locally and it seems like the error comes from changing
import * as portableFetch from "portable-fetch";
to
import portableFetch from "portable-fetch";
They are semantically different in TypeScript, the first one imports all exports from portable-fetch stored in a object called portableFetch, while the second one, imports the default export of portable-fetch, which does not exist. Changing this back in
openapi-generator/modules/openapi-generator/src/main/resources/typescript-fetch/api.mustache
Line 6 in 86c3bc0
@msiemens Can you please write down the exact command you are running to reproduce the error? I'm very new to this concept of testing with typescript / npm and I'm not sure what command to launch and in which folder I need to be.
As soon as I'm able to reproduce the error on my local machine, I will have if fixed very quickly.
Thanks!
msiemens
commented
Jul 17, 2018
@JFCote I just ran mvn verify -Psamples (after commenting out irrelevant tests from pom.xml so I don't have to wait for them too). All I was missing was to run git checkout multiple-typescript-fetch-enhancements
Alternatively, you could run the test setup and execution manually by calling npm run prepublish; npm test in samples/client/petstore/typescript-fetch/tests/default (and I guess the clients have to be built first)
@msiemens I am unable to debug. When I run mvn verify -Psamples
I get this result, with or without the changes you suggested. This is with stuff commented. If I uncomment all test, then they all fail. It seems mvn plugin are not working very well with npm or something... Any ideas ?
[INFO] Reactor Summary:
[INFO]
[INFO] openapi-generator-project 3.1.1-SNAPSHOT ........... SUCCESS [ 2.555 s]
[INFO] openapi-generator (core library) ................... SUCCESS [ 34.528 s]
[INFO] openapi-generator (executable) ..................... SUCCESS [ 20.356 s]
[INFO] openapi-generator (maven-plugin) ................... SUCCESS [ 5.081 s]
[INFO] openapi-generator-gradle-plugin (maven wrapper) .... SUCCESS [ 0.104 s]
[INFO] openapi-generator-online ........................... SUCCESS [ 3.135 s]
[INFO] TS Fetch Default Petstore Client 1.0-SNAPSHOT ...... SUCCESS [ 0.269 s]
[INFO] TS Fetch ES6 Petstore Client 1.0-SNAPSHOT .......... FAILURE [ 0.106 s]
[INFO] TS Fetch Petstore Client (with npm) 1.0-SNAPSHOT ... SKIPPED
[INFO] TS Fetch Petstore Test Client 1.0-SNAPSHOT ......... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:06 min
[INFO] Finished at: 2018年07月17日T11:09:38-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (npm-install) on project TypeScriptAngularBuildES6PestoreClientTests: Command execution failed.: Cannot run program "npm" (in directory "C:\dev\openapi-generator\samples\client\petstore\typescript-fetch\builds\es6-target"): CreateProcess error=2, The system cannot find the file specified -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :TypeScriptAngularBuildES6PestoreClientTests
When I run `npm install" manually in this folder, I have no problem at all.
But when I run the suggested manual call: npm run prepublish; npm test
I get this...
$ npm run prepublish; npm test
npm ERR! missing script: prepublish
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\jcote\AppData\Roaming\npm-cache\_logs2018円-07-17T15_15_10_531Z-debug.log
> @swagger/typescript-fetch-petstore@1.0.0 test C:\dev\openapi-generator\samples\client\petstore\typescript-fetch\builds\with-npm-version
> echo 'Error: no test specified'
'Error: no test specified'
I would like to help but making these test work seems to be VERY complicated.
@wing328 Any ideas why test are not working on my local machine?
msiemens
commented
Jul 17, 2018
But when I run the suggested manual call: npm run prepublish; npm test
I get this...
Are you sure, you're calling this from samples/client/petstore/typescript-fetch/tests/default? The log indicates you are running from samples/client/petstore/typescript-fetch/builds/with-npm-version instead
@msiemens Oups, you are right!
Now when I run this in the right folder, I get this error for all 24 tests
For example:
1) PetApi without custom request options should add and delete Pet:
TypeError: fetch is not a function
at C:\dev\openapi-generator\samples\client\petstore\typescript-fetch\builds\with-npm-version\dist\api.js:457:24
at PetApi.addPet (C:\dev\openapi-generator\samples\client\petstore\typescript-fetch\builds\with-npm-version\dist\api.js:741:73)
at Context.<anonymous> (test\PetApi.ts:18:28)
Is this the "expected" behvior or the error we are talking about?
msiemens
commented
Jul 17, 2018
Yes, this is the error :) If you apply the changes mentioned in #145 (comment), the errors should disappear (after rebuilding the sample client using ./bin/typescript-fetch-petstore-all.sh)
@msiemens Ok I think we have a problem, or maybe my computer is giving me false flags.
When I checkout the Master (without my changes) and do this:
- Compile openapi-generator
- Generate typescript-fetch samples with this command:
./bin/typescript-fetch-petstore-all.sh - Then run the tests by going to this folder:
/samples/client/petstore/typescript-fetch/tests/defaultand I run this command:npm run prepublish; npm test
I still receive the errors like this:
1) PetApi without custom request options should add and delete Pet:
TypeError: fetch is not a function
at C:\dev\openapi-generator\samples\client\petstore\typescript-fetch\builds\with-npm-version\dist\api.js:457:24
at PetApi.addPet (C:\dev\openapi-generator\samples\client\petstore\typescript-fetch\builds\with-npm-version\dist\api.js:741:73)
at Context.<anonymous> (test\PetApi.ts:18:28)
So unless I'm missing something, it seems the test weren't passing even in the master, so it's not related to my changes.
I'm calling for the help of the Typescript technical commitee: @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01)
msiemens
commented
Jul 18, 2018
I just ran everything as you described it on master, and all tests pass without errors. Also, recent commits on master pass all tests, for example https://travis-ci.org/OpenAPITools/openapi-generator/builds/405202474 for 9056c1e
I just ran everything as you described it on master, and all tests pass without errors. Also, recent commits on master pass all tests, for example https://travis-ci.org/OpenAPITools/openapi-generator/builds/405202474 for 9056c1e
After your message, I deleted EVERYTHING and started from scratch and now you are right, it work in master... So much time wasted... There must have been something odd in one of the node_modules...
I'll come back to you later today with a fix
Thanks
msiemens
commented
Jul 18, 2018
After your message, I deleted EVERYTHING and started from scratch and now you are right, it work in master... So much time wasted... There must have been something odd in one of the node_modules...
No worries, stuff like that happens to everyone 🙂 It took me more than one try figure everything out, too
Now it seems to crash because some "pom.xml" files disappeared from the samples. But like I said, I deleted all the fetch samples and re-generated them all... So if the pom.xml wasn't re-generated, maybe this check is not good in the test? @msiemens , any advice?
msiemens
commented
Jul 18, 2018
I don't know why the pom.xml files were removed after re-generating, but I think just adding them back from the previous commit should probably fix everthing. You can just run
git checkout HEAD~1 -- samples/client/petstore/typescript-fetch/builds/default/pom.xml samples/client/petstore/typescript-fetch/builds/es6-target/pom.xml samples/client/petstore/typescript-fetch/builds/with-npm-version/pom.xml
to retrieve the files back and commit the changes.
msiemens
commented
Jul 18, 2018
Yay, everything is finally passing now 🎉
Merged since it has been reviewed by a lot of people :) Thanks everyone.
Derryrover
commented
Aug 29, 2019
Hi,
When using v4.1.1 in a docker (openapitools/openapi-generator-cli) I experience this issue:
swagger-api/swagger-codegen#8180
(Problem with tsconfig.json strict = true)
The issue was fixed in this branch correct?
Is this again a known issue?
kr
@Derryrover can you open a separate issue and add details about the error message? there are many reasons why strict=true may cause a compilation error, so it is important to know which spec produces which code.
Derryrover
commented
Sep 2, 2019
Hi macjohny
Thank you for the reply!
My colleague got it working without the error.
Not sure what I did wrong, but for now it seems no longer an issue.
kr Tom
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\.master.Description of the PR
@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01)
That is a copy from my own PR in swagger-api/swagger-codegen#7914 that has never been merged. @wing328 ask me to redo it here