Skip to content

Repository files navigation

mill-zio-http-gen

CI passing badge Maven Central version badge Scaladoc badge Scala Steward helping badge GitHub stars badge

A zio-http-gen plugin for Mill build tool.

Usage

build.mill:

//| mvnDeps:
//| - org.scalateams::mill-zio-http-gen::0.1.5
import mill.scalalib.*
import org.scalateams.mill.zio.http.gen.ZioHttpGenModule

object project extends ScalaModule with ZioHttpGenModule {

  def mvnDeps      = super.mvnDeps() ++ Seq(mvn"dev.zio::zio-http:3.11.3")
  def scalaVersion = "3.3.8"

  object openapi extends OpenAPIModule {

    def packagePrefix = Task { Seq("com", "example") }
  }
}
> mill project.compile
Generated 2 file(s) from .../openapi/openapi.yaml in package com.example
Compiling compiler interface...
...
done compiling

Overriding default configuration

build.mill:

object openapi extends OpenAPIModule {

  import org.scalateams.mill.zio.http.gen.parsers.Parser
  import zio.http.gen.openapi.Config
  
  def config        = Task { Config.default.copy(commonFieldsOnSuperType = true) }
  def packagePrefix = Task { Seq("com", "example") }
  def parsers       = Task { Map("yaml" -> ParserRef.of[Parser.yaml]) }
  def sources       = Task.Sources("openapi")
}

Providing specification dynamically

object openapi extends OpenAPIModule {

  import mill.*

  def packagePrefix    = Task { Seq("com", "example") }
  def specification    = Task {
    """openapi: 3.1.0
      |info:
      |  title: User API
      |  version: 1.0.0
      |paths:""".stripMargin
  }
  def generatedSources = Task {
    val content = specification() // think of downloading etc.
    os.write.over(Task.dest / Path("openapi.yaml"), content, createFolders = true)
    Seq(PathRef(Task.dest))
  }
}

Multiple generators

object project extends ScalaModule with ZioHttpGenModule { self =>

  object openapi extends OpenAPIModule {

    def packagePrefix = Task { Seq("com", "example") }
  }

  object openapi_internal extends OpenAPIModule {

    import mill.*

    def packagePrefix = openapi.packagePrefix() ++ Seq("internal")
    def sources       = Task.Sources(self.moduleDir / "internal" / "openapi")
  }
}

Related projects

Contributing

Before committing run:

$ ./mill __.style + __.test + __.publishLocal

All contributions are welcome!

About

A zio-http-gen plugin for Mill build tool.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Contributors

Languages