Skip to content

Commit 5364296

Browse files
committed
GH-234 Kotlin + Maven example
1 parent 350ff9b commit 5364296

File tree

5 files changed

+182
-0
lines changed

5 files changed

+182
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--add-opens=java.base/java.lang=ALL-UNNAMED
2+
--add-opens=java.base/java.io=ALL-UNNAMED
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# javalin-maven-kotlin
2+
3+
This is a simple example of a Javalin application using Maven and Kotlin.
4+
In order to generate OpenAPI specification with Maven, run the following command:
5+
6+
```shell
7+
$ mvn clean compile
8+
```
9+
10+
Once the command is executed, the OpenAPI annotation processor will generate output files in the `target/classes/openapi-plugin` directory.
11+
These files will be picked up by the OpenAPI plugin and hosted at `http://localhost:8080/openapi`.
12+
You can also access the Swagger UI at `http://localhost:8080/swagger-ui`.

examples/javalin-maven-kotlin/pom.xml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>io.javalin.community.openapi.examples</groupId>
8+
<artifactId>javalin-apptest</artifactId>
9+
<version>1.0.0</version>
10+
11+
<properties>
12+
<javalin.version>6.3.0</javalin.version>
13+
<javalin.openapi.version>6.3.0</javalin.openapi.version>
14+
<kotlin.version>2.1.0</kotlin.version>
15+
</properties>
16+
17+
<repositories>
18+
<repository>
19+
<id>reposilite-repository</id>
20+
<url>https://maven.reposilite.com/snapshots</url>
21+
</repository>
22+
</repositories>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>org.jetbrains.kotlin</groupId>
27+
<artifactId>kotlin-stdlib</artifactId>
28+
<version>${kotlin.version}</version>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>io.javalin</groupId>
33+
<artifactId>javalin</artifactId>
34+
<version>${javalin.version}</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>io.javalin.community.openapi</groupId>
38+
<artifactId>javalin-openapi-plugin</artifactId>
39+
<version>${javalin.openapi.version}</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>io.javalin.community.openapi</groupId>
43+
<artifactId>javalin-swagger-plugin</artifactId>
44+
<version>${javalin.openapi.version}</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>io.javalin.community.openapi</groupId>
48+
<artifactId>javalin-redoc-plugin</artifactId>
49+
<version>${javalin.openapi.version}</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.webjars.npm</groupId>
53+
<artifactId>redoc</artifactId>
54+
<version>2.0.0-rc.56</version>
55+
<exclusions>
56+
<exclusion>
57+
<groupId>*</groupId>
58+
<artifactId>*</artifactId>
59+
</exclusion>
60+
</exclusions>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>org.tinylog</groupId>
65+
<artifactId>tinylog-api</artifactId>
66+
<version>2.4.1</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.tinylog</groupId>
70+
<artifactId>tinylog-impl</artifactId>
71+
<version>2.4.1</version>
72+
</dependency>
73+
<dependency>
74+
<groupId>org.tinylog</groupId>
75+
<artifactId>slf4j-tinylog</artifactId>
76+
<version>2.4.1</version>
77+
</dependency>
78+
</dependencies>
79+
80+
<build>
81+
<pluginManagement>
82+
<plugins>
83+
<plugin>
84+
<artifactId>kotlin-maven-plugin</artifactId>
85+
<groupId>org.jetbrains.kotlin</groupId>
86+
<version>2.1.0</version>
87+
88+
</plugin>
89+
</plugins>
90+
</pluginManagement>
91+
<plugins>
92+
<plugin>
93+
<groupId>org.jetbrains.kotlin</groupId>
94+
<artifactId>kotlin-maven-plugin</artifactId>
95+
<version>${kotlin.version}</version>
96+
<executions>
97+
<execution>
98+
<id>kapt</id>
99+
<goals>
100+
<goal>kapt</goal>
101+
</goals>
102+
<configuration>
103+
<sourceDirs>
104+
<sourceDir>src/main/kotlin</sourceDir>
105+
</sourceDirs>
106+
<annotationProcessorPaths>
107+
<annotationProcessorPath>
108+
<groupId>io.javalin.community.openapi</groupId>
109+
<artifactId>openapi-annotation-processor</artifactId>
110+
<version>${javalin.openapi.version}</version>
111+
</annotationProcessorPath>
112+
</annotationProcessorPaths>
113+
</configuration>
114+
</execution>
115+
<execution>
116+
<id>compile</id>
117+
<phase>compile</phase>
118+
<goals>
119+
<goal>compile</goal>
120+
</goals>
121+
</execution>
122+
</executions>
123+
</plugin>
124+
</plugins>
125+
</build>
126+
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.javalin.openapi.plugin.test
2+
3+
import io.javalin.Javalin
4+
import io.javalin.openapi.HttpMethod
5+
import io.javalin.openapi.OpenApi
6+
import io.javalin.openapi.plugin.OpenApiPlugin
7+
import io.javalin.openapi.plugin.swagger.SwaggerPlugin
8+
9+
@OpenApi(
10+
description = "Test description",
11+
summary = "Test summary",
12+
tags = ["test-tag"],
13+
methods = [HttpMethod.GET],
14+
path = "/"
15+
)
16+
fun main() {
17+
Javalin.createAndStart { config ->
18+
config.registerPlugin(
19+
OpenApiPlugin {
20+
it.documentationPath = "/openapi"
21+
}
22+
)
23+
24+
config.registerPlugin(
25+
SwaggerPlugin {
26+
it.uiPath = "/swagger"
27+
it.documentationPath = "/openapi"
28+
}
29+
)
30+
}
31+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<configuration>
2+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
3+
<encoder>
4+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
5+
</encoder>
6+
</appender>
7+
8+
<root level="info">
9+
<appender-ref ref="STDOUT"/>
10+
</root>
11+
</configuration>

0 commit comments

Comments
 (0)