https://github.com/sake92/openapi4s
openapi4s
https://github.com/sake92/openapi4s
incremental openapi openapi-generator openapi3 scala scala3
Last synced: 9 months ago
JSON representation
openapi4s
- Host: GitHub
- URL: https://github.com/sake92/openapi4s
- Owner: sake92
- License: apache-2.0
- Created: 2024-12-21T07:37:30.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-04T17:04:23.000Z (9 months ago)
- Last Synced: 2025-04-04T17:35:30.551Z (9 months ago)
- Topics: incremental, openapi, openapi-generator, openapi3, scala, scala3
- Language: Scala
- Homepage:
- Size: 101 KB
- Stars: 19
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# openapi4s
OpenApi generators for Scala.
Here is a small video demo: https://youtu.be/kf0vGrlKNb8
## Features and Benefits
- incremental generator
- doesn't touch the code that you added manually
- only adds new properties/methods/classes
- lenient parser+generator
- if something is not supported it will still (mostly) work
- you can adapt your openapi spec to work gradually
## Limitations
- JSON only
- only *named* entities, no anonymous objects
---
## Generators
### Sharaf backend
Supports almost all features:
- controllers
- discriminated models (sealed traits)
- enums (scala3 singleton enums)
- validations
- query params
### Http4s backend
Supports some features:
- routes (controllers)
- discriminated models (sealed traits)
- enums (scala3 singleton enums)
TODO: query params, validation..
Contributions welcome!
---
## Plugins
### Mill plugin
```scala
package build
import $ivy.`ba.sake::mill-openapi4s::0.3.0`
import mill._
import mill.scalalib._, scalafmt._
import ba.sake.openapi4s.OpenApiGeneratorModule
object api extends ScalaModule with OpenApiGeneratorModule with ScalafmtModule {
def scalaVersion = "3.6.2"
def ivyDeps = Agg(
// sharaf
ivy"ba.sake::sharaf:0.8.0"
// http4s
//ivy"org.http4s::http4s-ember-server:0.23.29",
//ivy"org.http4s::http4s-circe:0.23.29",
//ivy"org.http4s::http4s-dsl:0.23.29"
)
/* mandatory config */
def openApi4sPackage = "com.example.api"
/* optional config */
//def openApi4sGenerator: T[String] = "sharaf" // or "http4s"
//def openApi4sFile = T.source(PathRef(millSourcePath / "resources" / "openapi.json"))
//def openApi4sTargetDir: T[PathRef] = T(millSourcePath / "src")
}
```
Files will be generated at compile time, whenever the `openapi.json` file changes:
```shell
./mill api.compile
```