Openapi-generator: [REQ] sbt plugin for OpenAPI Generator

Created on 15 Aug 2019  路  18Comments  路  Source: OpenAPITools/openapi-generator

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.

Feature OpenAPI Generator SBT Plugin help wanted

Most helpful comment

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

All 18 comments

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

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

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

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

@jimschubert Nope:

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

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

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

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

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.

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?

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

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

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

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

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

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.

Was this page helpful?
0 / 5 - 0 ratings