Skip to content

Commit 59bb9c0

Browse files
committed
initial commit to finalize a blog post
0 parents  commit 59bb9c0

16 files changed

Lines changed: 534 additions & 0 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# API first Spring Boot Service (WIP)
2+
3+
This Spring Boot Service will be created by the API first approach and tested with [Karate](https://intuit.github.io/karate/). Due to missing capability of OpenAPI Generator in Version 5.0.0 the direct download of the API spec is not possible at the moment. So we will rely on using [Gradle Download Task](https://github.com/michel-kraemer/gradle-download-task). There is also already [bug report](https://github.com/OpenAPITools/openapi-generator/issues/8255) written by [joschi](https://github.com/joschi).
4+
5+
At the moment the blog post can be finalized with the workaround in mind. Also a good idea to test the "update feature" on the codecentric blog next year.

build.gradle

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
plugins {
2+
id 'org.springframework.boot' version '2.3.5.RELEASE'
3+
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
4+
id 'org.openapi.generator' version '4.3.1'
5+
id 'de.undercouch.download' version '4.1.1'
6+
id 'org.asciidoctor.convert' version '1.5.8'
7+
id 'org.jetbrains.gradle.plugin.idea-ext' version '0.5'
8+
id 'java'
9+
}
10+
11+
group = 'de.codecentric'
12+
version = '0.0.2-SNAPSHOT'
13+
sourceCompatibility = '11'
14+
15+
configurations {
16+
developmentOnly
17+
runtimeClasspath {
18+
extendsFrom developmentOnly
19+
}
20+
compileOnly {
21+
extendsFrom annotationProcessor
22+
}
23+
}
24+
25+
repositories {
26+
mavenCentral()
27+
}
28+
29+
ext {
30+
set('snippetsDir', file("build/generated-snippets"))
31+
}
32+
33+
dependencies {
34+
implementation 'org.springframework.boot:spring-boot-starter-actuator'
35+
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
36+
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
37+
implementation 'org.springframework.boot:spring-boot-starter-web'
38+
implementation 'junit:junit:4.12'
39+
40+
//compile 'io.springfox:springfox-swagger-ui:3.0.0'
41+
//needed for swagger code generation
42+
compile "io.springfox:springfox-swagger2:3.0.0"
43+
compile "org.openapitools:jackson-databind-nullable:0.1.0"
44+
45+
compileOnly 'org.projectlombok:lombok'
46+
developmentOnly 'org.springframework.boot:spring-boot-devtools'
47+
runtimeOnly 'com.h2database:h2'
48+
49+
50+
testImplementation('org.springframework.boot:spring-boot-starter-test') {
51+
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
52+
}
53+
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
54+
testCompile('com.intuit.karate:karate-junit5:0.9.6')
55+
testCompile('com.intuit.karate:karate-apache:0.9.6')
56+
testCompile('net.masterthought:cucumber-reporting:3.8.0')
57+
58+
59+
60+
}
61+
62+
test {
63+
useJUnitPlatform()
64+
systemProperty('karate.options', System.properties.getProperty('karate.options'))
65+
systemProperty('karate.env', System.properties.getProperty('karate.env'))
66+
outputs.upToDateWhen { false }
67+
}
68+
69+
task downloadFile(type: Download) {
70+
src "https://raw.githubusercontent.com/codecentric/api-showcases/main/specs/news.yaml"
71+
dest buildDir
72+
onlyIfModified true
73+
useETag true
74+
}
75+
76+
openApiValidate {
77+
inputSpec = "$buildDir/news.yaml"
78+
}
79+
80+
openApiGenerate {
81+
generatorName = "spring"
82+
library = "spring-boot"
83+
inputSpec = "$buildDir/news.yaml"
84+
configFile = "${projectDir}/openapi-generator-config.json"
85+
outputDir = "${buildDir}/generated/open-api"
86+
}
87+
88+
tasks.openApiGenerate.dependsOn tasks.downloadFile
89+
90+
idea.project.settings {
91+
taskTriggers {
92+
beforeBuild tasks.openApiGenerate
93+
beforeRebuild tasks.openApiGenerate
94+
afterSync tasks.openApiGenerate
95+
beforeSync tasks.openApiGenerate
96+
}
97+
}
98+
99+
sourceSets {
100+
main {
101+
java {
102+
srcDir "${buildDir.absolutePath}/generated/open-api/src/main/java"
103+
}
104+
}
105+
106+
test {
107+
resources {
108+
srcDir file('src/test/java')
109+
exclude '**/*.java'
110+
}
111+
}
112+
}
113+
114+
compileJava {
115+
dependsOn tasks.openApiGenerate
116+
source "${buildDir}/generated/open-api/src/main/java"
117+
}
118+
119+
springBoot {
120+
mainClassName = "de.codecentric.apifirstspringboot.ApifirstSpringbootApplication"
121+
}
122+
123+
asciidoctor {
124+
inputs.dir snippetsDir
125+
dependsOn test
126+
}

gradle/wrapper/gradle-wrapper.jar

57.8 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

gradlew

Lines changed: 185 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)