Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cdimascio/kotlin-spring-mvc-template

12-factor compliant Spring MVC Kotlin template. Features automatic request/response validation and interactive API doc
https://github.com/cdimascio/kotlin-spring-mvc-template

dotenv kotlin openapi3 spring-boot spring-mvc swagger swagger2

Last synced: 3 months ago
JSON representation

12-factor compliant Spring MVC Kotlin template. Features automatic request/response validation and interactive API doc

Awesome Lists containing this project

README

        

# 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



**Features**:

- Automatic request and response validation via atlassian [OpenApi 3.0](https://swagger.io/docs/specification/about/)
- Automatic documentation generation via [Swagger UI](https://swagger.io/tools/swagger-ui/)
- 12 factor compliant configuration via [java-dotenv](https://github.com/cdimascio/java-dotenv)
- Automatic code formatting and linting via [ktlint](https://ktlint.github.io)
- Fully operational sample REST API
- API integration tests with [Unirest](http://unirest.io/java.html) REST client
- Simple HTTP errors via [japi-errors](https://github.com/cdimascio/japi-errors)
- Dockerfile

## Setup

- Clone this repo
- copy `.env.template` to `src/main/resources/.env`

## Build

```shell
./gradlew build
```

## Format/Lint

```shell
./gradlew lintKotlin # see lint errors
./gradlew formatKotlin # attempt to automatically fix lint errors
```

## Run
```shell
./gradlew bootRun
```

## Test

```shell
./gradlew test
```

## Package / Dist

```shell
./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](http://localhost:8080/api_explorer/index.html)

## Validate Example

```shell
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

![](https://raw.githubusercontent.com/cdimascio/kotlin-spring-mvc-template/master/assets/swagger-ui.png)

## License
Apache 2.0