Awesome
kotlin-spring-mvc-template
Spring 5 MVC template with Kotlin and OpenAPI 3.0. (Also Supports Swagger 2.0)
Features automatic request/response validation and interactive API doc
<p align="left"> <img src="https://raw.githubusercontent.com/cdimascio/kotlin-spring-mvc-template/master/assets/spring-mvc-openapi.png" width="600"/> </p>Features:
- Automatic request and response validation via atlassian OpenApi 3.0
- Automatic documentation generation via Swagger UI
- 12 factor compliant configuration via java-dotenv
- Automatic code formatting and linting via ktlint
- Fully operational sample REST API
- API integration tests with Unirest REST client
- Simple HTTP errors via japi-errors
- Dockerfile
Setup
- Clone this repo
- copy
.env.template
tosrc/main/resources/.env
Build
./gradlew build
Format/Lint
./gradlew lintKotlin # see lint errors
./gradlew formatKotlin # attempt to automatically fix lint errors
Run
./gradlew bootRun
Test
./gradlew test
Package / Dist
./gradlew jar
# Run the dist
java -jar ./build/libs/example-service-1.0.0.jar
Try It
Navigate to http://localhost:8080/api_explorer/index.html
Validate Example
curl -X POST "http://localhost:8080/users" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"me\":\"carmine\"}"
{
"error": " Object instance has properties which are not allowed by the schema: [\"me\"]",
"code": 400
}
Interactive Api doc
License
Apache 2.0