kubernetes-client / gen

Common generator scripts for all client libraries
Apache License 2.0
150 stars 147 forks source link

Typescript generator config class name is possibly outdated #238

Closed michael-valdron closed 1 year ago

michael-valdron commented 1 year ago

While working on a fix for devfile/api#1036 that includes the fix for #236, I came across the following error:

Error:  
org.openapitools.codegen.GeneratorNotFoundException: Can't load config class with name 'typescript'
Available:
ada
ada-server
android
apache2
apex
aspnetcore
bash
c
clojure
cwiki
cpp-qt5-client
cpp-qt5-qhttpengine-server
cpp-pistache-server
cpp-restbed-server
cpp-restsdk
cpp-tizen
csharp
csharp-netcore
csharp-dotnet2
csharp-nancyfx
dart
dart-jaguar
eiffel
elixir
elm
erlang-client
erlang-proper
erlang-server
flash
go
go-experimental
go-server
go-gin-server
graphql-schema
graphql-nodejs-express-server
groovy
kotlin
kotlin-server
kotlin-spring
haskell-http-client
haskell
java
jaxrs-cxf-client
java-inflector
java-msf4j
java-pkmst
java-play-framework
java-undertow-server
java-vertx
jaxrs-cxf
jaxrs-cxf-extended
jaxrs-cxf-cdi
jaxrs-jersey
jaxrs-resteasy
jaxrs-resteasy-eap
jaxrs-spec
javascript
javascript-flowtyped
javascript-closure-angular
jmeter
lua
mysql-schema
nodejs-server-deprecated
objc
openapi
openapi-yaml
perl
php
php-laravel
php-lumen
php-slim
php-silex
php-symfony
php-ze-ph
powershell
python
python-experimental
python-flask
python-aiohttp
python-blueplanet
r
ruby
ruby-on-rails
ruby-sinatra
rust
rust-server
scalatra
scala-akka
scala-finch
scala-httpclient-deprecated
scala-gatling
scala-lagom-server
scala-play-server
scalaz
spring
dynamic-html
html
html2
swift2-deprecated
swift3-deprecated
swift4
typescript-angular
typescript-angularjs
typescript-aurelia
typescript-axios
typescript-fetch
typescript-inversify
typescript-jquery
typescript-node
typescript-rxjs
fsharp-giraffe-server

    at org.openapitools.codegen.CodegenConfigLoader.forName (CodegenConfigLoader.java:48)
    at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput (CodegenConfigurator.java:528)
    at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:670)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.lang.ClassNotFoundException: typescript
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass (SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass (ClassRealm.java:271)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass (ClassRealm.java:247)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass (ClassRealm.java:239)
    at java.lang.Class.forName0 (Native Method)
    at java.lang.Class.forName (Class.java:264)
    at org.openapitools.codegen.CodegenConfigLoader.forName (CodegenConfigLoader.java:46)
    at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput (CodegenConfigurator.java:528)
    at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:670)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.045 s
[INFO] Finished at: 2023-02-28T20:19:14Z
[INFO] ------------------------------------------------------------------------
Error:  Failed to execute goal org.openapitools:openapi-generator-maven-plugin:4.0.3:generate (default) on project client-typescript: Code generation failed. See above for the full exception. -> [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: Process completed with exit code 1.

It seems that the name for typescript is missing from the generators list and possibly outdated. I have created a folk https://github.com/michael-valdron/kubernetes-client-gen/tree/ts-class-fix that changes the config class name from typescript to typescript-node, this seems to have worked in my use case.

If this is an appropriate fix for this I can create a PR from this folk.

brendandburns commented 1 year ago

Hrm, what commit are you running for the openapi generator? The code seems to still be there at HEAD:

https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/typescript

Though it is possible that something has changed.

Switching generators generally involves major API changes which don't work for our library. We're in the midst of switching to typescript-fetch anyway.

michael-valdron commented 1 year ago

Hrm, what commit are you running for the openapi generator? The code seems to still be there at HEAD:

https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/typescript

Though it is possible that something has changed.

We were running off of a3aef4de7a1d5dab72021aa282fffd8bc8a022ca for a while now, since late 2021, but now we are trying to update to the latest commit, currently b32dcd6dc9c1c0c4fcf227c9539ae9ff0530b936, to apply the fix for #236. This change is what produced the error in this issue.

Switching generators generally involves major API changes which don't work for our library. We're in the midst of switching to typescript-fetch anyway.

I did try to switch the script to use typescript-fetch.sh but as of writing this script does not yet build our generated typescript classes successfully.

brendandburns commented 1 year ago

There should be two commits, one for this repo (which should be safe to update) and one for the openapi repo, e.g. this is our settings file for the main client:

https://github.com/kubernetes-client/javascript/blob/master/settings#L33

Admitedly I haven't regenerated in a while, so I should test that and make sure it's still working.

michael-valdron commented 1 year ago

Thanks @brendandburns for your help! I did some further investigating using what you have provided me here and found the culprit to be the opposite of what I first thought.

It seems that before v5.x of the openapi generator typescript did not exist in the resources directory . The default revision in typescript.sh is v4.0.3 which explains the build error I got.

Setting OPENAPI_GENERATOR_COMMIT in our automation to the latest one with a change v6.3.0 seems to have worked for us.

Should there be a bump in the default revision within typescript.sh since typescript did not exist till v5.0.0?

brendandburns commented 1 year ago

Glad you got it working! Yes, we'd gladly take a PR to bump the revision in typescript.sh so that someone doesn't hit this again in the future.