Tegral OpenAPI
Tegral OpenAPI is a collection of libraries that allow you to:
- Create OpenAPI definitions using a Kotlin DSL.
- Define and parse
*.openapi.kts
scripts that embed said DSL and convert them to JSON or YAML using a CLI. - Define OpenAPI details of Ktor endpoints and serve OpenAPI and Swagger from Ktor applications.
- Integrate OpenAPI support in Tegral Web applications.
Tegral OpenAPI provides a concise Kotlin syntax for (most of) your OpenAPI needs.
Example
Here's an example of using the Tegral OpenAPI toolchain. Using tegral-openapi-dsl
and tegral-openapi-scriptdef
, we can write the following script file...
myapi.openapi.kts
title = "My API document"
version = "1.0.0"
"/hello" get {
description = "Returns a greeting"
200 response {
plainText { schema("Hello World!") }
}
}
... which we can then turn into a JSON or YAML file using tegral-openapi-cli
and tegral-openapi-scripthost
:
$ ./tegral-openapi-cli myapi.openapi.kts -f yaml -o myapi.yaml
[i] openapi.dump - Compiling script...
[i] openapi.dump - Evaluating script...
[i] openapi.dump - Output written to myapi.yaml
... which gives us the following output:
openapi: 3.0.1
info:
title: My API document
version: 1.0.0
paths:
/hello:
get:
description: Returns a greeting
responses:
"200":
description: A greeting
content:
text/plain:
schema:
type: string
example: Hello World!
Packages
Package information
Package name | Catalog dependency | Full Gradle name |
---|---|---|
tegral-openapi-cli | tegralLibs.openapi.cli | guru.zoroark.tegral:tegral-openapi-cli:VERSION |
tegral-openapi-dsl | tegralLibs.openapi.dsl | guru.zoroark.tegral:tegral-openapi-dsl:VERSION |
tegral-openapi-feature | tegralLibs.openapi.feature | guru.zoroark.tegral:tegral-openapi-feature:VERSION |
tegral-openapi-ktor | tegralLibs.openapi.ktor | guru.zoroark.tegral:tegral-openapi-ktor:VERSION |
tegral-openapi-ktor-resources | tegralLibs.openapi.ktor.resources | guru.zoroark.tegral:tegral-openapi-ktor-resources:VERSION |
tegral-openapi-ktorui | tegralLibs.openapi.ktorui | guru.zoroark.tegral:tegral-openapi-ktorui:VERSION |
tegral-openapi-scriptdef | tegralLibs.openapi.scriptdef | guru.zoroark.tegral:tegral-openapi-scriptdef:VERSION |
tegral-openapi-scripthost | tegralLibs.openapi.scripthost | guru.zoroark.tegral:tegral-openapi-scripthost:VERSION |