Description
Description
I wanted to generate just model classes in Scala from an Swagger/OpenAPI definition, in a place which is not a whole maven/sbt/... project, but just some folder generated during a build.
The Scala generators I found (ScalaClientCodegen (scala
), ScalatraServerCodegen (scalatra
), AkkaScalaClientCodegen (akka-scala
) and AsyncScalaClientCodegen (async-scala
)) all put the output into
outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
(or apiPackage
for the API files), where the sourceFolder
is hardcoded to "src/main/scala"
, and cannot be changed by parameters (neither of the CLI, web app nor maven plugin).
Swagger-codegen version
This happens in 2.2.1, and is the same in current master.
Command line used for generation
java -DmodelPackage=example -DsourceFolder=bla -Dmodels \
-jar ../swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar \
generate -i code/swagger.yaml -l scala -o sample
Output:
[main] INFO io.swagger.parser.Swagger20Parser - reading from code/swagger.yaml
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/paulo/projektoj/swagger-codegen-bugreports/sample/src/main/scala/io/swagger/client/model/MDCTrace.scala
Suggest a Fix
The Java codegens have a setter for this sourceFolder
property, and set it from additionalProperties in AbstractJavaCodegen.processOpts(). This could be done here too.
This might be an opportunity to see whether there is some common code between all the Scala codegens which could be extracted into a super class (though I guess most duplication is between the template files, which can't be easily shared – correct me if I'm wrong).