Replies: 6 comments 8 replies
-
Hey @Quafadas, thank you for your interest in smithy4s and your willingness to contribute! We actually have an example of a mill plugin for smithy4s that we can provide you. We may end up providing a mill plugin as part of the library down the road, but that has yet to be decided/mapped out. So in the meantime, you should be able to copy this one and modify it if need be to suit your needs. And of course, don't hesitate to reach out if you have questions along the way! import $ivy.`com.disneystreaming.smithy4s::smithy4s-codegen:0.12.16`
import coursier.maven.MavenRepository
import mill._
import mill.api.PathRef
import mill.scalalib._
import os.Path
import smithy4s.codegen.{Codegen => Smithy4s}
import smithy4s.codegen.CodegenArgs
import scala.util._
trait Smithy4sModule extends ScalaModule {
/** Input directory for .smithy files */
protected def smithy4sInputDir: T[PathRef] = T.input {
PathRef(millSourcePath / "smithy")
}
private def smithy4sCodegen: T[(PathRef, PathRef)] = T {
val specFiles = if (os.exists(smithy4sInputDir().path)) {
os.walk(smithy4sInputDir().path, skip = _.ext != "smithy")
} else Seq.empty
val scalaOutput = T.ctx().dest / "scala"
val openapiOutput = T.ctx().dest / "openapi"
val args = CodegenArgs(
specs = specFiles.toList,
output = scalaOutput,
openapiOutput = openapiOutput,
skipScala = false,
skipOpenapi = false,
allowedNS = None,
repositories = List.empty,
dependencies = List.empty,
transformers = List.empty
)
Smithy4s.processSpecs(args)
(PathRef(scalaOutput), PathRef(openapiOutput))
}
override def generatedSources: T[Seq[PathRef]] = T {
val (scalaOutput, _) = smithy4sCodegen()
scalaOutput +: super.generatedSources()
}
// Considering the openapi output as localclasspath so that
// its contents can be served by http servers
override def localClasspath: T[Seq[PathRef]] = T {
val (_, openapiOutput) = smithy4sCodegen()
openapiOutput +: super.localClasspath()
}
} |
Beta Was this translation helpful? Give feedback.
-
Er, wow. Thanks! I shall ruthlessly copy paste this where it's needed :-). I'll link to this in the mill discussions forum as well, so the knowledge exists over there too... Thanks again, I'm really looking forward to trying this. |
Beta Was this translation helpful? Give feedback.
-
May I suggest the use of /** Input directory for .smithy files */
protected def smithy4sInputDir: Source = T.source(millSourcePath / "smithy") |
Beta Was this translation helpful? Give feedback.
-
I found I had to modify the module slightly, to include two extra params in the codgen args, (the bottom two) otherwise it grumbled.
But, I believe this works otherwise as intended. Which is really cool Thankyou! |
Beta Was this translation helpful? Give feedback.
-
I had a crack at writing a Mill plugin (before I saw this discussion). My first attempt was with a totally separate codebase, and I quickly ended up in class loader hell. The user should specify the versions of Scala and smithy4s, so the plugin has to load My second attempt was with a module in the smithy4s codebase. Seems OK, but I don't know how to write automated tests for this. See this branch. |
Beta Was this translation helpful? Give feedback.
-
Happy to let you know that mill support is out and you're invited to test it out. https://disneystreaming.github.io/smithy4s/docs/overview/installation#mill |
Beta Was this translation helpful? Give feedback.
-
My situation is that I can't really use SBT at work (for dumb reasons, but that is out of my control).
I can however, use mill.
Now, I am not an expert on build tools, or build tool plugins, but from what I see here,
https://github.com/disneystreaming/smithy4s/blob/main/modules/codegen-plugin/src/smithy4s/codegen/CodegenPlugin.scala
The Smithy4s codegen plugin (which produces the key parts an application would wish to consume?), is
The task
CodeGen
args.I believe that smithy library is also published for scala 2.13.8?
First question : is all of the above, reasonably correct? Any material complexity I'm missing?
Because if that's all right, it looks like a tilt at a mill plugin, might be within my own (limited :-)!) skillz - finickity, but not "complex" per se... and with no knowledge needed beyond blindly translating the CLI / sbt plugin tasks...
Second question : if all of the above is right and I did have a go, are you interested in the outcome (if it were to work, that is, if I were to fail miserably, I likely wouldn't post that up :-)... ) ?
Beta Was this translation helpful? Give feedback.
All reactions