Skip to content

Principled code generation from OpenAPI specifications

License

Notifications You must be signed in to change notification settings

mberndt123/sbt-guardrail

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sbt-guardrail sbt-guardrail | Join the chat at https://gitter.im/guardrail-dev/guardrail

An SBT plugin for adding clients and servers generated by guardrail to your service.

Installation

Check out the docs

project/plugins.sbt

addSbtPlugin("dev.guardrail" % "sbt-guardrail" % "<Please use the latest available release!>")

build.sbt

/* Available arguments:
    specPath: java.io.File
    pkg: String
    dto: String
    framework: String
    modules: List[String]
    tracing: Boolean
    imports: List[String]
    encodeOptionalAs: Option[CodingConfig]
    decodeOptionalAs: Option[CodingConfig]
*/
guardrailTasks in Compile := List(
  ScalaClient(file("petstore.yaml")),
  ScalaClient(file("github.yaml"), pkg="com.example.clients.github"),
  ScalaClient(file("github.yaml"), pkg="com.example.clients.github", 
              encodeOptionalAs = codingOptional,
              decodeOptionalAs = codingRequiredNullable),
  ScalaServer(file("myserver.yaml"), pkg="com.example.server", tracing=true),
  ScalaModels(file("myserver.yaml"), pkg="com.example.models"),
  JavaClient(file("github.yaml"), pkg="com.example.clients.github")
  ...
)

Alternatively use the guardrailDiscoveredOpenApiFiles setting to automatically discover OpenAPI spec files under src/main/openapi or src/test/openapi (see the test for full example):

Compile / guardrailTasks := (Compile / guardrailDiscoveredOpenApiFiles).value.flatMap { openApiFile =>
  List(          
    ScalaClient(openApiFile.file, pkg = openApiFile.pkg, framework = "http4s"),
    ScalaServer(openApiFile.file, pkg = openApiFile.pkg, framework = "http4s")
  )
}

About

Principled code generation from OpenAPI specifications

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Scala 58.6%
  • Shell 41.4%