indiscriminatecoding / api4s

Derive Scala code for your HTTP API from swagger!

GitHub

api4s - HTTP API in Scala

Description

Document your HTTP API with swagger and generate Scala code from it.

Uses http4s and circe for autogenerated code.

Usage

The simplest way to use this library is via sbt plugin. Add following line to project/plugins.sbt:

addSbtPlugin("com.github.IndiscriminateCoding" % "api4s-sbt" % "0.2.0")

Also you need to enable plugin usage in build.sbt:

lazy val root = (project in file("."))
  .enablePlugins(Api4s)
  .settings(
    libraryDependencies += "com.github.IndiscriminateCoding" %% "api4s-core" % "0.2.0",
    api4sSources := Seq(Api4s.Src(
      file = sourceDirectory.value / "main" / "swagger" / "my-specification.yaml",
      pkg = "com.example",
      server = true,
      client = true
    ))
  )

At this point you can just compile your project and see what is generated by plugin.

Detailed example is here.

Limitations

  • No OpenAPI 3.0 support at this moment; only swagger is supported
  • Specifications in JSON format isn't supported; use YAML instead