Skip to content

Commit

Permalink
GH-234 Kotlin + Maven example
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Dec 9, 2024
1 parent 350ff9b commit 5364296
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/javalin-maven-kotlin/.mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED
12 changes: 12 additions & 0 deletions examples/javalin-maven-kotlin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# javalin-maven-kotlin

This is a simple example of a Javalin application using Maven and Kotlin.
In order to generate OpenAPI specification with Maven, run the following command:

```shell
$ mvn clean compile
```

Once the command is executed, the OpenAPI annotation processor will generate output files in the `target/classes/openapi-plugin` directory.
These files will be picked up by the OpenAPI plugin and hosted at `http://localhost:8080/openapi`.
You can also access the Swagger UI at `http://localhost:8080/swagger-ui`.
126 changes: 126 additions & 0 deletions examples/javalin-maven-kotlin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.javalin.community.openapi.examples</groupId>
<artifactId>javalin-apptest</artifactId>
<version>1.0.0</version>

<properties>
<javalin.version>6.3.0</javalin.version>
<javalin.openapi.version>6.3.0</javalin.openapi.version>
<kotlin.version>2.1.0</kotlin.version>
</properties>

<repositories>
<repository>
<id>reposilite-repository</id>
<url>https://maven.reposilite.com/snapshots</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>

<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>${javalin.version}</version>
</dependency>
<dependency>
<groupId>io.javalin.community.openapi</groupId>
<artifactId>javalin-openapi-plugin</artifactId>
<version>${javalin.openapi.version}</version>
</dependency>
<dependency>
<groupId>io.javalin.community.openapi</groupId>
<artifactId>javalin-swagger-plugin</artifactId>
<version>${javalin.openapi.version}</version>
</dependency>
<dependency>
<groupId>io.javalin.community.openapi</groupId>
<artifactId>javalin-redoc-plugin</artifactId>
<version>${javalin.openapi.version}</version>
</dependency>
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>redoc</artifactId>
<version>2.0.0-rc.56</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-api</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-impl</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>slf4j-tinylog</artifactId>
<version>2.4.1</version>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>2.1.0</version>

</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>kapt</id>
<goals>
<goal>kapt</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>src/main/kotlin</sourceDir>
</sourceDirs>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>io.javalin.community.openapi</groupId>
<artifactId>openapi-annotation-processor</artifactId>
<version>${javalin.openapi.version}</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</execution>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.javalin.openapi.plugin.test

import io.javalin.Javalin
import io.javalin.openapi.HttpMethod
import io.javalin.openapi.OpenApi
import io.javalin.openapi.plugin.OpenApiPlugin
import io.javalin.openapi.plugin.swagger.SwaggerPlugin

@OpenApi(
description = "Test description",
summary = "Test summary",
tags = ["test-tag"],
methods = [HttpMethod.GET],
path = "/"
)
fun main() {
Javalin.createAndStart { config ->
config.registerPlugin(
OpenApiPlugin {
it.documentationPath = "/openapi"
}
)

config.registerPlugin(
SwaggerPlugin {
it.uiPath = "/swagger"
it.documentationPath = "/openapi"
}
)
}
}
11 changes: 11 additions & 0 deletions examples/javalin-maven-kotlin/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="STDOUT"/>
</root>
</configuration>

0 comments on commit 5364296

Please sign in to comment.