Skip to content

Commit 120da66

Browse files
authored
#25 Cross build the project for springdoc-openapi v2.x (#27)
1 parent d3443cd commit 120da66

File tree

31 files changed

+640
-75
lines changed

31 files changed

+640
-75
lines changed

.github/workflows/ci_code_coverage.yml

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,49 @@ jobs:
1414
- name: Setup Scala
1515
uses: olafurpg/setup-scala@v14
1616
with:
17-
java-version: "adopt@1.8"
18-
- name: Build, run tests, and generate Jacoco code coverage report
19-
run: sbt ++2.12.18 jacoco
20-
- name: Add coverage to PR
21-
id: jacoco
17+
java-version: "openjdk@1.17.0"
18+
- name: Build, run tests, and generate Jacoco code coverage report for springdoc-openapi-scala (all subversions)
19+
run: sbt jacoco
20+
- name: Add coverage to PR for springdoc-openapi-scala-1
21+
id: jacoco1
2222
uses: madrapps/[email protected]
2323
with:
2424
paths: >
25-
${{ github.workspace }}/target/scala-2.12/jacoco/report/jacoco.xml
25+
${{ github.workspace }}/library/target/1-jvm-2.12/jacoco/report/jacoco.xml
2626
token: ${{ secrets.GITHUB_TOKEN }}
2727
min-coverage-overall: 0.0
2828
min-coverage-changed-files: 80.0
29-
title: JaCoCo code coverage report - springdoc-openapi-scala
29+
title: JaCoCo code coverage report - springdoc-openapi-scala-1
3030
update-comment: true
3131
debug-mode: true
32-
- name: Get the Coverage info
32+
- name: Add coverage to PR for springdoc-openapi-scala-2
33+
id: jacoco2
34+
uses: madrapps/[email protected]
35+
with:
36+
paths: >
37+
${{ github.workspace }}/library/target/2-jvm-2.12/jacoco/report/jacoco.xml
38+
token: ${{ secrets.GITHUB_TOKEN }}
39+
min-coverage-overall: 0.0
40+
min-coverage-changed-files: 80.0
41+
title: JaCoCo code coverage report - springdoc-openapi-scala-2
42+
update-comment: true
43+
debug-mode: true
44+
- name: Get the Coverage info for springdoc-openapi-scala-1
45+
run: |
46+
echo "Total coverage ${{ steps.jacoco1.outputs.coverage-overall }}"
47+
echo "Changed Files coverage ${{ steps.jacoco1.outputs.coverage-changed-files }}"
48+
- name: Get the Coverage info for springdoc-openapi-scala-2
3349
run: |
34-
echo "Total coverage ${{ steps.jacoco.outputs.coverage-overall }}"
35-
echo "Changed Files coverage ${{ steps.jacoco.outputs.coverage-changed-files }}"
36-
- name: Fail PR if changed files coverage is less than 80%
37-
if: ${{ steps.jacoco.outputs.coverage-changed-files < 80.0 }}
50+
echo "Total coverage ${{ steps.jacoco2.outputs.coverage-overall }}"
51+
echo "Changed Files coverage ${{ steps.jacoco2.outputs.coverage-changed-files }}"
52+
- name: Fail PR if changed files coverage is less than 80% for springdoc-openapi-scala-1
53+
if: ${{ steps.jacoco1.outputs.coverage-changed-files < 80.0 }}
54+
uses: actions/[email protected]
55+
with:
56+
script: |
57+
core.setFailed('Changed files coverage is less than 80%!')
58+
- name: Fail PR if changed files coverage is less than 80% for springdoc-openapi-scala-2
59+
if: ${{ steps.jacoco2.outputs.coverage-changed-files < 80.0 }}
3860
uses: actions/[email protected]
3961
with:
4062
script: |

.github/workflows/ci_tests.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,13 @@ on:
2323
jobs:
2424
tests:
2525
runs-on: ubuntu-latest
26-
strategy:
27-
fail-fast: false
28-
matrix:
29-
scala: [2.12.18, 2.13.12]
30-
name: Scala ${{matrix.scala}}
3126
steps:
3227
- name: Checkout code
3328
uses: actions/[email protected]
3429
- uses: coursier/cache-action@v6
3530
- name: Setup Scala
3631
uses: olafurpg/setup-scala@v14
3732
with:
38-
java-version: "adopt@1.8"
33+
java-version: "openjdk@1.17.0"
3934
- name: Build and run tests
40-
run: sbt ++${{matrix.scala}} clean test
35+
run: sbt clean test

README.md

Lines changed: 143 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,45 @@ This library aims to avoid pollution of the model by custom annotations and depe
2424

2525
## Usage
2626

27+
springdoc-openapi-scala supports two major versions of springdoc-openapi: 1.x and 2.x.
28+
2729
### Provided dependencies
28-
The library has `"org.springdoc" % "springdoc-openapi-webmvc-core"` as a provided dependency,
29-
thus users of the library have to include that dependency in their projects.
30-
Versions `1.6.7` up to `1.7.0` (including) are supported.
30+
The library has springdoc-openapi as a provided dependency,
31+
thus users of the library have to include that dependency in their projects:
32+
- for springdoc-openapi 1.x versions `1.6.7` up to `1.7.0` (including) of
33+
`"org.springdoc" % "springdoc-openapi-webmvc-core"` are supported
34+
- for springdoc-openapi 2.x versions `1.6.7` up to `1.7.0` (including) of
35+
`"org.springdoc" % "springdoc-openapi-starter-webmvc-api"` are supported
3136

3237
### Add library dependency to SBT/Maven
33-
SBT:
38+
#### SBT
39+
If you want to use the library with springdoc-openapi 1.x, add:
40+
```sbt
41+
libraryDependencies ++= Seq("za.co.absa" %% "springdoc-openapi-scala-1" % VERSION)
42+
```
43+
if with springdoc-openapi 2.x, add:
3444
```sbt
35-
libraryDependencies ++= Seq("za.co.absa" %% "springdoc-openapi-scala" % VERSION)
45+
libraryDependencies ++= Seq("za.co.absa" %% "springdoc-openapi-scala-2" % VERSION)
3646
```
3747

38-
Maven:
48+
#### Maven
49+
If you want to use the library with springdoc-openapi 1.x, add:
50+
```xml
51+
<dependency>
52+
<groupId>za.co.absa</groupId>
53+
<artifactId>springdoc-openapi-scala-1_{scala_binary_version}</artifactId>
54+
<version>${version}</version>
55+
</dependency>
56+
```
57+
if with springdoc-openapi 2.x, add:
3958
```xml
4059
<dependency>
4160
<groupId>za.co.absa</groupId>
42-
<artifactId>springdoc-openapi-scala_{scala_binary_version}</artifactId>
61+
<artifactId>springdoc-openapi-scala-2_{scala_binary_version}</artifactId>
4362
<version>${version}</version>
4463
</dependency>
4564
```
65+
4666
where `scala_binary_version` is either `2.12` or `2.13`.
4767

4868
### Create custom OpenAPI Spring Configuration
@@ -102,13 +122,13 @@ class ExampleController @Autowired()(openAPIModelRegistration: OpenAPIModelRegis
102122

103123
## Examples
104124

105-
### Simple example
106-
Can be found in this repo: [link](examples/simple). It generates the following OpenAPI JSON doc:
125+
### Simple example for springdoc-openapi-scala-1
126+
Can be found in this repo: [link](examples/springdoc-openapi-scala-1/simple). It generates the following OpenAPI JSON doc:
107127
```json
108128
{
109129
"openapi": "3.0.1",
110130
"info": {
111-
"title": "Example API",
131+
"title": "Example API with springdoc-openapi v1.x",
112132
"version": "1.0.0"
113133
},
114134
"servers": [
@@ -192,3 +212,116 @@ Can be found in this repo: [link](examples/simple). It generates the following O
192212
}
193213
}
194214
```
215+
216+
### Simple example for springdoc-openapi-scala-2
217+
Can be found in this repo: [link](examples/springdoc-openapi-scala-2/simple). It generates the following OpenAPI JSON doc:
218+
```json
219+
{
220+
"openapi": "3.0.1",
221+
"info": {
222+
"title": "Example API with springdoc-openapi v2.x",
223+
"version": "1.0.0"
224+
},
225+
"servers": [
226+
{
227+
"url": "http://localhost:8080",
228+
"description": "Generated server url"
229+
}
230+
],
231+
"paths": {
232+
"/api/v1/example/some-endpoint": {
233+
"post": {
234+
"tags": [
235+
"example-controller"
236+
],
237+
"operationId": "someEndpoint",
238+
"requestBody": {
239+
"content": {
240+
"application/json": {
241+
"schema": {
242+
"$ref": "#/components/schemas/ExampleModelRequest"
243+
}
244+
}
245+
},
246+
"required": true
247+
},
248+
"responses": {
249+
"200": {
250+
"description": "OK",
251+
"content": {
252+
"application/json": {
253+
"schema": {
254+
"$ref": "#/components/schemas/ExampleModelResponse"
255+
}
256+
}
257+
}
258+
}
259+
}
260+
}
261+
},
262+
"/api/v1/example/empty-endpoint": {
263+
"post": {
264+
"tags": [
265+
"example-controller"
266+
],
267+
"operationId": "emptyEndpoint",
268+
"responses": {
269+
"204": {
270+
"description": "No Content"
271+
}
272+
}
273+
}
274+
}
275+
},
276+
"components": {
277+
"schemas": {
278+
"ExampleModelRequest": {
279+
"required": [
280+
"a",
281+
"b",
282+
"d"
283+
],
284+
"properties": {
285+
"a": {
286+
"type": "integer",
287+
"format": "int32"
288+
},
289+
"b": {
290+
"type": "string"
291+
},
292+
"c": {
293+
"type": "integer",
294+
"format": "int32"
295+
},
296+
"d": {
297+
"type": "string",
298+
"enum": [
299+
"OptionC",
300+
"OptionB",
301+
"OptionA"
302+
]
303+
}
304+
}
305+
},
306+
"ExampleModelResponse": {
307+
"required": [
308+
"d",
309+
"e"
310+
],
311+
"properties": {
312+
"d": {
313+
"type": "array",
314+
"items": {
315+
"type": "integer",
316+
"format": "int32"
317+
}
318+
},
319+
"e": {
320+
"type": "boolean"
321+
}
322+
}
323+
}
324+
}
325+
}
326+
}
327+
```

build.sbt

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17+
import SpringdocOpenAPIVersionAxis._
1718
import Dependencies._
18-
import com.github.sbt.jacoco.report.JacocoReportSettings
1919

2020
ThisBuild / organization := "za.co.absa"
2121
ThisBuild / scalaVersion := Versions.scala212
2222
ThisBuild / versionScheme := Some("early-semver")
2323

2424
lazy val supportedScalaVersions = List(Versions.scala212, Versions.scala213)
2525

26-
lazy val commonJacocoReportSettings: JacocoReportSettings = JacocoReportSettings(
27-
formats = Seq(JacocoReportFormats.HTML, JacocoReportFormats.XML)
28-
)
29-
30-
lazy val commonJacocoExcludes: Seq[String] = Seq(
31-
// "za.co.absa.springdocopenapiscala.*"
32-
)
33-
34-
lazy val root = (project in file("."))
35-
.settings(
36-
name := "springdoc-openapi-scala",
37-
libraryDependencies ++= libraryDependencyList(scalaVersion.value),
38-
crossScalaVersions := supportedScalaVersions,
39-
jacocoReportSettings := commonJacocoReportSettings.withTitle(s"SpringDoc OpenApi - scala:${scalaVersion.value}"),
40-
jacocoExcludes := commonJacocoExcludes
41-
)
42-
43-
lazy val simpleExample = (project in file("examples/simple"))
26+
lazy val `springdoc-openapi-scala` = (projectMatrix in file("library"))
4427
.settings(
45-
libraryDependencies ++= exampleProjectsDependencyList,
46-
webappWebInfClasses := true,
47-
inheritJarManifest := true
28+
name := "springdoc-openapi-scala"
4829
)
49-
.enablePlugins(TomcatPlugin)
50-
.dependsOn(root)
30+
.row(SpringdocOpenAPIVersionAxis(1), supportedScalaVersions)
31+
.row(SpringdocOpenAPIVersionAxis(2), supportedScalaVersions)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2023 ABSA Group Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
ThisBuild / scalaVersion := "2.12.18"
18+
19+
lazy val `springdoc-openapi-scala-1-version`: String = ??? // specify version of the library, for example "0.2.0"
20+
21+
lazy val root = (project in file("."))
22+
.settings(
23+
libraryDependencies ++= Seq(
24+
"za.co.absa" %% "springdoc-openapi-scala-1" % `springdoc-openapi-scala-1-version`,
25+
"org.springdoc" % "springdoc-openapi-webmvc-core" % "1.7.0",
26+
"org.springframework.boot" % "spring-boot-starter-web" % "2.6.6"
27+
),
28+
webappWebInfClasses := true,
29+
inheritJarManifest := true
30+
)
31+
.enablePlugins(TomcatPlugin)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version = 1.9.7
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2023 ABSA Group Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.2.4")

examples/simple/src/main/scala/za/co/absa/springdocopenapiscala/examples/simple/OpenAPIConfiguration.scala renamed to examples/springdoc-openapi-scala-1/simple/src/main/scala/za/co/absa/springdocopenapiscala/examples/simple/OpenAPIConfiguration.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class OpenAPIConfiguration {
3030
Seq((openAPI: OpenAPI) =>
3131
openAPI.setInfo(
3232
new Info()
33-
.title("Example API")
33+
.title("Example API with springdoc-openapi v1.x")
3434
.version("1.0.0")
3535
)
3636
)

0 commit comments

Comments
 (0)