Skip to content

Commit

Permalink
Merge pull request #38 from rami2076/feature/15
Browse files Browse the repository at this point in the history
open-apiでコード生成に利用するyamlを定義する
  • Loading branch information
rami2076 authored Oct 5, 2023
2 parents 9236d1a + 4f44099 commit ac903f2
Show file tree
Hide file tree
Showing 39 changed files with 1,896 additions and 421 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Comma-separated list of rules to disable
# Note that rules in any ruleset other than the standard ruleset will need to be prefixed
# by the ruleset identifier.
# ref: https://pinterest.github.io/ktlint/0.49.1/rules/configuration-ktlint/

# Cause: Imports must be ordered in lexicographic order without any empty lines in-between with "java", "javax", "kotlin" and aliases in the end (import-ordering)
# I'm Not Adjust Rule. Because, disabled it.
# Actual:https://github.com/rami2076/kotlin-on-spring-boot/actions/runs/6417868641/job/17424476230?pr=38
[*.{kt,kts}]
ktlint_disabled_rules = import-ordering
36 changes: 30 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ Sample of Kotlin on Spring Boot.

### Build

`gradlew build` is deprecate. Instead of `gradlew build -x runKtlintCheckOverMainSourceSet -x test`
Cause: gradle-ktlint has bug.
`gradlew build` is deprecate.
Instead of `gradlew clean build -x runKtlintCheckOverMainSourceSet -x test`.
Cause: `gradle-ktlint` has bug.
Issue: https://github.com/JLLeitschuh/ktlint-gradle/issues/579
Note:
To save time, test step excluded from the build task.
If other tasks also fail related to ktlint, use the -x option to exclude them.
If other tasks also fail related to `ktlint`, use the `-x` option to exclude them.

```shell
gradlew build -x runKtlintCheckOverMainSourceSet -x test
gradlew clean build -x runKtlintCheckOverMainSourceSet -x test
```

### Formatter
Expand All @@ -27,7 +28,13 @@ Set kotlin formatter for IntelliJ.
gradlew ktlintApplyToIdea
```

### Up Container
### Format

```shell
gradlew ktlintFormat
```

### Up Container

Init datasource.

Expand All @@ -37,20 +44,37 @@ docker-compose -f docker-compose.yaml -p kotlin-on-spring-boot up -d

### Check

If only ktlintCheck is used, it succeeds.
If only `ktlintCheck` is used, it succeeds.

```shell
gradlew ktlintCheck
```

### Test

#### For Test File

Case Windows: Use git-bash.

```shell
touch $HOME/.testcontainers.properties
echo "testcontainers.reuse.enable=true" > $HOME/.testcontainers.properties
```

#### Execute

When not work test, then run build command.

```shell
gradlew test
```

### Run command

```shell
gradlew bootRun
```

### Down Container

```shell
Expand Down
60 changes: 44 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ plugins {
id 'org.jetbrains.kotlin.plugin.spring' version '1.8.22'
id "org.jlleitschuh.gradle.ktlint" version '11.6.0'
id "org.jlleitschuh.gradle.ktlint-idea" version '11.6.0'

id "org.openapi.generator" version "7.0.1"
}

ext {
mybatisSpringBootStarterVersion = "3.0.2"
springModulithBomVersion = "1.0.1"
archunitVersion = '1.1.0'
springdocVersion = '2.2.0'
mockitoKotlinVersion = '5.1.0'
}


Expand Down Expand Up @@ -45,14 +46,15 @@ dependencies {
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
implementation 'org.springframework.modulith:spring-modulith-starter-core'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:${springdocVersion}"


//container
developmentOnly 'org.springframework.boot:spring-boot-docker-compose'

//web
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'

//data
implementation "org.mybatis.spring.boot:mybatis-spring-boot-starter:${mybatisSpringBootStarterVersion}"
Expand All @@ -69,6 +71,8 @@ dependencies {
testImplementation "org.mybatis.spring.boot:mybatis-spring-boot-starter-test:${mybatisSpringBootStarterVersion}"
testImplementation 'org.springframework.boot:spring-boot-starter-webflux'
testImplementation "com.tngtech.archunit:archunit-junit5:${archunitVersion}"
testImplementation "org.mockito.kotlin:mockito-kotlin:${mockitoKotlinVersion}"


//kotlin-module
implementation 'org.jetbrains.kotlin:kotlin-reflect'
Expand Down Expand Up @@ -102,27 +106,51 @@ jar {
}

openApiValidate {
inputSpec.set("$rootDir/specs/petstore.yaml")
inputSpec.set("$rootDir/specs/openApiMain.yaml")
}

//https://openapi-generator.tech/docs/generators/kotlin-spring/
openApiGenerate {
outputDir.set("$rootDir/generated")
generatorName.set("kotlin-spring")
inputSpec.set("$rootDir/specs/petstore.yaml")
outputDir.set("$rootDir/build/generated")
apiPackage.set("com.example.kotlinonspringboot.presentation.api")
modelPackage.set("com.example.kotlinonspringboot.presentation.model")
inputSpec.set("$rootDir/specs/openApiMain.yaml")
configOptions.set([
useSpringBoot3 : "true",
delegatePattern : "false",
documentationProvider: "springdoc",
enumPropertyNaming : "camelCase",
exceptionHandler : "false",
interfaceOnly : "true",
modelMutable : "false",
serverPort : "8080",
"useTags" : "true"
additionalModelTypeAnnotations : "null",
annotationLibrary : "swagger2",
apiPackage : "com.example.kotlinonspringboot.presentation.api",
apiSuffix : "Api",
artifactId : "openapi-spring",
artifactVersion : "1.0.0",
basePackage : "com.example.kotlinonspringboot.presentation.openapitools",
beanQualifiers : "false",
configPackage : "com.example.kotlinonspringboot.presentation.config",
delegatePattern : "false",
documentationProvider : "springdoc",
enumPropertyNaming : "camelCase",
exceptionHandler : "false",
gradleBuildFile : "false",
groupId : "org.openapitools",
interfaceOnly : "true",
library : "spring-boot",
modelMutable : "false",
modelPackage : "com.example.kotlinonspringboot.presentation.model",
packageName : "org.openapitools",
parcelizeModels : "null",
reactive : "false",
serializableModel : "null",
serverPort : "8080",
serviceImplementation : "false",
serviceInterface : "false",
skipDefaultInterface : "false",
sortModelPropertiesByRequiredFlag: "null",
sortParamsByRequiredFlag : "null",
sourceFolder : "src/main/kotlin",
title : "OpenAPI Kotlin Spring",
useBeanValidation : "true",
useFeignClientUrl : "true",
useSpringBoot3 : "true",
useSwaggerUI : "true",
useTags : "true"
])
}

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ services:
ports:
- "3306:3306"
volumes:
- ./datasource/init.sql:/docker-entrypoint-initdb.d/init.sql
- ./src/test/resources/datasource/init_ddl.sql:/docker-entrypoint-initdb.d/init.sql
Loading

0 comments on commit ac903f2

Please sign in to comment.