Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open-apiでコード生成に利用するyamlを定義し、コントローラ部のUTと実装まで行う #38

Merged
merged 42 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
0b2ca09
TODOを更新
rami2076 Oct 4, 2023
35b63f5
設定をgradleに全て転記
rami2076 Oct 4, 2023
5f33975
openapiのyamlを設定して5つの正常形が動作するように変更する
rami2076 Oct 4, 2023
5f394c8
TODOの修正
rami2076 Oct 4, 2023
5b95336
TODOの修正フォーマットの修正
rami2076 Oct 4, 2023
1a274c6
IT用のyamlを追加
rami2076 Oct 4, 2023
c5d8021
employeeのgetメソッドのテストをイニシャルコミット
rami2076 Oct 4, 2023
31884b4
パッケージの説明を追加
rami2076 Oct 4, 2023
2853eff
itのtodoを記載中
rami2076 Oct 4, 2023
f0e6741
generatedフォルダの出力先が間違っていたので修正
rami2076 Oct 4, 2023
66c3826
specファイルの名前を変更
rami2076 Oct 4, 2023
2b3eb15
runコマンドの追加
rami2076 Oct 4, 2023
e1235be
database接続情報を追加
rami2076 Oct 4, 2023
630aefd
containerの参照先の変更とテスト用コンテナの作成
rami2076 Oct 4, 2023
a63cb12
pathにversionを追加
rami2076 Oct 4, 2023
0af97c9
全権検索コントローラ部の作成とIT試験を追加
rami2076 Oct 4, 2023
2d7954f
ファイル名の誤りを修正
rami2076 Oct 4, 2023
19e9c6c
全権検索の試験であるということを明示
rami2076 Oct 4, 2023
9341ad7
フォーマットの適用
rami2076 Oct 4, 2023
efd0e3c
社員のコントローラの実装とITの実装
rami2076 Oct 4, 2023
6bc45d4
検証:Actionsでのみ失敗する試験の名称を変更
rami2076 Oct 4, 2023
4bc71d9
検証:Profileを変更
rami2076 Oct 4, 2023
d81e9d2
検証:Disable
rami2076 Oct 4, 2023
e3c3f78
不要な生成を除去
rami2076 Oct 4, 2023
7ed6e3a
妥当性の基準をspecに記述
rami2076 Oct 4, 2023
9494ce5
400系、PK検索のテストを追加
rami2076 Oct 4, 2023
eec4a3b
validが動作していないので検証
rami2076 Oct 4, 2023
9160120
validation用の依存を追加
rami2076 Oct 5, 2023
96e798e
ドメインオブジェクトを追加
rami2076 Oct 5, 2023
52be2a2
ExceptionHandlerを追加
rami2076 Oct 5, 2023
7e40ff5
なぜかGiHub Actionsで動作しないためIgnore
rami2076 Oct 5, 2023
207e0b9
PK検索の実装とUTを対応また、使用するユースケースの仮組を対応
rami2076 Oct 5, 2023
d7a287f
specに足りていない箇所がったので修正
rami2076 Oct 5, 2023
535c7f8
全権検索のコントローラの実装/UT
rami2076 Oct 5, 2023
d559d8c
KP削除処理のコントローラの実装とUTを対応
rami2076 Oct 5, 2023
0cd81f9
KP削除処理UTを追加
rami2076 Oct 5, 2023
81f44b2
登録処理のコントローラ部とUTを追加
rami2076 Oct 5, 2023
aa84113
importフォーマット崩れ対応
rami2076 Oct 5, 2023
29b1e3d
importフォーマット崩れ対応
rami2076 Oct 5, 2023
2838bea
対応ができないのでインポート順のルールを無視
rami2076 Oct 5, 2023
3e09a90
コメントの追加
rami2076 Oct 5, 2023
4f44099
todoの修正
rami2076 Oct 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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