Sbt
Last updated
Last updated
Spec scala code generation is packaged in form of SBT plugins. Add sbt-specgen
plugin library into the sbt project using following line in the plugins.sbt
:
Instead of <version>
use latest available from Maven Central Repository.
Spec code generation has full support for Scala Play applications. Models, controllers, services traits and services scaffolded implementations are generated by SpecPlay
plugin.
To enable server side code generation from spec enable SpecPlay
plugin in your build.sbt
:
Following dependencies are defined in SpecPlay
and should be added into libraryDependencies
:
Specgen plugin generates router that should be pluged into conf/routes
:
Here are SpecPlay
settings that allow customization of code generation:
Setting | Default | Description |
---|---|---|
Default settings are aligned with the standard Play application layout.
Generated swagger (OpenAPI) documentation could be hosted. Following routes should be added to conf/routes
:
This setup above hosts swagger documentation at /docs
route of the Play application.
Spec code generation can generate HTTP client in Scala based on spec. The generated client is using sttp client under the hood with provided ability to plugin backend of your taste.
To enable client code generation from spec enable SpecSttp
plugin in your build.sbt
:
Following dependencies are defined in SpecSttp
and should be added into libraryDependencies
:
Here are SpecSttp
settings that allow customization of code generation:
Spec code generation can generate only (de)serializable to JSON circe models without any application specifics.
To enable models generation from spec enable SpecCirce
plugin in your build.sbt
:
Following dependencies are defined in SpecCirce
and should be added into libraryDependencies
:
Here are SpecCirce
settings that allow customization of code generation:
All specgen SBT plugins are running specgen command line tool. The specgen command line tool binaries are packaged as a resource into sbt-specgen
plugin jar. On any sbt-specgen
plugin execution it unpacks specgen
binaries from itself and executing commands using those binaries.
Setting | Default | Description |
---|---|---|
Setting | Default | Description |
---|---|---|
specFile
spec.yaml
Path to service specification file; relative to project folder
specSwagger
public/swagger.yaml
Path to generated OpenAPI/Swagger specification file
specGeneratePath
target/scala/src_managed/main/spec
Path to generate source code into
specServicesPath
app/services
Path to scaffolded services files; these services are scaffolded only if they do not exist
specFile
spec.yaml
Path to spec file relative to project folder
specGeneratePath
target/scala/src_managed/main/spec
Path to generated code is placed
specFile
spec.yaml
Path to spec file relative to project folder
specGeneratePath
target/scala/src_managed/main/spec
Path to generated code is placed