OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.25k stars 6.43k forks source link

[REQ] sbt plugin for OpenAPI Generator #3650

Open wing328 opened 5 years ago

wing328 commented 5 years ago

We already have maven and gradle plugins. As discussed in in the slack channels, there's also demand for an sbt plugin.

If anyone would like to contribute an sbt plugin for openapi generator, please reply to let us know.

YanDoroshenko commented 5 years ago

I already have a [barely] working prototype, working on improving it.

jimschubert commented 5 years ago

@YanDoroshenko let me know if you need any assistance and I'd be happy to check it out. I have experience writing SBT plugins.

YanDoroshenko commented 5 years ago

@jimschubert Is there a way to define an optional settingKey in SBT?

Example: Api package setting is not mandatory (generator has some default value). I can declare a settingKey[Option[String]] and initialize it to None as a default. Then if it's present, I update the generator setting. But that means that plugin user has to specify it with Option like openapiApiPackage := Some("org.something.api"). Is there a way around it?

Thanks.

jimschubert commented 5 years ago

@YanDoroshenko another way to do this would be to have a string and initialize it to a null. Then when you use the string,

Option(yourKeySetting) match {
  case Some(value) => // set it
  case None => // ignore it
}
YanDoroshenko commented 5 years ago

@jimschubert Nope:

[info] [error] Setting value cannot be null: ProjectRef(uri("file:/tmp/sbt_cf846a14/simple/"), "simple") / modelNameSuffix
jimschubert commented 5 years ago

@YanDoroshenko I could've sworn I had done this with null, but maybe I used an empty string and filtered on nonEmpty values in the past. I don't think the usage of assigning Some(value) is bad, as it clearly indicates that you're setting an optional value. This is done using Option[String] in some plugins (see https://github.com/sbt/sbt-autoversion/blob/2f7798d8de68cf2b5425423b2c9b702df2cdb5f4/src/main/scala/autoversion/Keys.scala#L10).

If it's possible to get the current setting for a property, I guess you could also create a settingKey[String => String] and bind this to the identity function by default.

YanDoroshenko commented 5 years ago

https://github.com/upstart-commerce/sbt-openapi-generator

wing328 commented 4 years ago

@YanDoroshenko is it correct to say that https://github.com/upstart-commerce/sbt-openapi-generator is ready for OpenAPI Generator to try it out and provide feedback?

YanDoroshenko commented 4 years ago

@wing328 Probably. It's just a dumb wrapper so not much can go wrong.

wing328 commented 4 years ago

Sent out a tweet to promote the plugin: https://twitter.com/oas_generator/status/1191349874828038145

Already broadcast in the OpenAPI Generator Slack channel: https://openapi-generator.slack.com/archives/CLSB0U0R5/p1572874959235900

pme123 commented 4 years ago

I am trying the plugin at the moment. I cannot run it for asciidoc:

[error] org.openapitools.codegen.GeneratorNotFoundException: Can't load config class with name 'asciidoc'
[error] Available:
[error] ada
[error] ada-server
...
[error]         at org.openapitools.codegen.CodegenConfigLoader.forName(CodegenConfigLoader.java:48)
[error]         at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:431)
[error]         at org.upstartcommerce.openapi.OpenAPIGeneratorPlugin$.$anonfun$generateTask$1(OpenAPIGeneratorPlugin.scala:113)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:40)
[error]         at sbt.std.Transform$$anon$4.work(System.scala:67)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:269)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]         at sbt.Execute.work(Execute.scala:278)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:269)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]         at java.lang.Thread.run(Thread.java:748)
[error] Caused by: java.lang.ClassNotFoundException: asciidoc
[error]         at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
[error]         at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[error]         at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[error]         at java.lang.Class.forName0(Native Method)
[error]         at java.lang.Class.forName(Class.java:264)
[error]         at org.openapitools.codegen.CodegenConfigLoader.forName(CodegenConfigLoader.java:46)
[error]         at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:431)
[error]         at org.upstartcommerce.openapi.OpenAPIGeneratorPlugin$.$anonfun$generateTask$1(OpenAPIGeneratorPlugin.scala:113)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:40)
[error]         at sbt.std.Transform$$anon$4.work(System.scala:67)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:269)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]         at sbt.Execute.work(Execute.scala:278)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:269)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]         at java.lang.Thread.run(Thread.java:748)
[error] (doc / openapiGenerate) org.openapitools.codegen.GeneratorNotFoundException: Can't load config class with name 'asciidoc'

I check with the terminal and there it works.

By the way scala-play-server works.

UkonnRa commented 4 years ago

Thanks for the great work! But I found that this plugin will JUST generate the files outside the target folder and does not mark it as src_managed?

wing328 commented 4 years ago

I've filed https://github.com/upstart-commerce/sbt-openapi-generator/pull/3 to update openapi-generator-cli to the latest version.

wing328 commented 4 years ago

@UkonnRa I would suggest you open an issue in https://github.com/upstart-commerce/sbt-openapi-generator instead.

YanDoroshenko commented 4 years ago

@wing328 @UkonnRa Thanks for your contributions, all merged.

chameleon82 commented 4 years ago

@wing328 I have finished my own version of plugin https://github.com/adenza/sbt-openapi-generator which use settings similar to gradle plugin. I would like to move it under OpenAPITools to have better support by community and maintain it here.

chameleon82 commented 4 years ago

@YanDoroshenko can we collaborate with your version to integrate sbt-plugin into OpenApiTools?

jimschubert commented 4 years ago

https://github.com/openapitools/sbt-openapi-generator has been created, and initial version 4.3.0 is available via bintray.

Leaving this open to track remaining need of documenting the plugin in our docsite.