Skip to content
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

Multiple enhancements to typescript fetch generator #145

Merged
merged 7 commits into from
Jul 18, 2018

Conversation

JFCote
Copy link
Member

@JFCote JFCote commented May 24, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if 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\.
  • Filed the PR against the correct branch: Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

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

@JFCote
Copy link
Member Author

JFCote commented May 24, 2018

It seems it doesn't build into CI but I don't understand why... Any idea guys?

@TiFu
Copy link
Contributor

TiFu commented May 24, 2018

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.

@JFCote
Copy link
Member Author

JFCote commented May 25, 2018

@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 :)

@wing328
Copy link
Member

wing328 commented May 25, 2018

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

@wing328
Copy link
Member

wing328 commented Jun 14, 2018

@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)

@JFCote
Copy link
Member Author

JFCote commented Jun 14, 2018

@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?

@wing328
Copy link
Member

wing328 commented Jun 14, 2018

@JFCote
Copy link
Member Author

JFCote commented Jun 14, 2018

@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-14T15: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.

@wing328
Copy link
Member

wing328 commented Jun 20, 2018

@JFCote what about running the following commands manually in that folder?

npm install
npm test

@JFCote
Copy link
Member Author

JFCote commented Jun 20, 2018

@wing328 Will try this today and let you know!

@JFCote
Copy link
Member Author

JFCote commented Jun 20, 2018

@wing328 Didn't have time today, will try in the upcoming days!

@msiemens
Copy link

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?

@JFCote
Copy link
Member Author

JFCote commented Jul 17, 2018

@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
@JFCote
Copy link
Member Author

JFCote commented Jul 17, 2018

@msiemens I just fixed the minor conflict with the master with a merge. Let's see how it goes with the CI.

@msiemens
Copy link

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…

@JFCote
Copy link
Member Author

JFCote commented Jul 17, 2018

@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.

@macjohnny
Copy link
Member

@JFCote

did you re-generate the typescript fetch samples after the merge?

@msiemens
Copy link

msiemens commented Jul 17, 2018

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

fixes the JS error

@JFCote
Copy link
Member Author

JFCote commented Jul 17, 2018

@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
Copy link

@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)

@JFCote
Copy link
Member Author

JFCote commented Jul 17, 2018

@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-17T11: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\_logs\2018-07-17T15_15_10_531Z-debug.log

> @swagger/[email protected] 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
Copy link

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

@JFCote
Copy link
Member Author

JFCote commented Jul 17, 2018

@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
Copy link

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)

@JFCote
Copy link
Member Author

JFCote commented Jul 18, 2018

@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:

  1. Compile openapi-generator
  2. Generate typescript-fetch samples with this command: ./bin/typescript-fetch-petstore-all.sh
  3. Then run the tests by going to this folder: /samples/client/petstore/typescript-fetch/tests/default and 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
Copy link

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

@JFCote
Copy link
Member Author

JFCote 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

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
Copy link

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

@JFCote
Copy link
Member Author

JFCote commented Jul 18, 2018

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
Copy link

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
Copy link

Yay, everything is finally passing now 🎉

@macjohnny
Copy link
Member

macjohnny commented Jul 18, 2018

@wing328 @jmini could you merge this?

@JFCote JFCote merged commit 5344a02 into master Jul 18, 2018
@JFCote JFCote deleted the multiple-typescript-fetch-enhancements branch July 18, 2018 17:38
@JFCote
Copy link
Member Author

JFCote commented Jul 18, 2018

Merged since it has been reviewed by a lot of people :) Thanks everyone.

@wing328 wing328 added this to the 3.1.2 milestone Jul 18, 2018
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
@Derryrover
Copy link

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

@macjohnny
Copy link
Member

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants