Skip to content

Commit d1dccd2

Browse files
Fix example applications (#67)
* Add revolver plugin * Update dependencies to align with library version * Fix example 1 spring boot * wip * Missing dependency * Truncated comment * Update * README files * Fix custom types * Update examples/springdoc-openapi-scala-1/README.md Co-authored-by: Kevin Wallimann <[email protected]> * Update examples/springdoc-openapi-scala-2/simple/README.md Co-authored-by: Kevin Wallimann <[email protected]> * Correction --------- Co-authored-by: Kevin Wallimann <[email protected]>
1 parent ae9c34e commit d1dccd2

File tree

9 files changed

+99
-8
lines changed

9 files changed

+99
-8
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# springdoc-openapi-scala-2 Example Application
2+
3+
This is a simple example application demonstrating the use of springdoc-openapi-scala with Spring Boot 2.x.
4+
5+
## Prerequisites
6+
7+
- JDK 17 or higher
8+
- SBT 1.x
9+
- Scala 2.12.x
10+
11+
## Running the Application
12+
13+
To run the application with hot-reload enabled:
14+
15+
```bash
16+
cd springdoc-openapi-scala/examples/springdoc-openapi-scala-1/simple
17+
sed -i '' 's/`springdoc-openapi-scala-1-version`: String = \?\?\?/`springdoc-openapi-scala-1-version`: String = "0.3.2"/g' build.sbt # Omit '' after the -i flag if not on mac
18+
sbt compile
19+
sbt "~reStart"
20+
```
21+
22+
The `~reStart` command will automatically restart the application when source files change.
23+
24+
## Accessing the API Documentation
25+
26+
Once the application is running, you can access the OpenAPI documentation at:
27+
28+
- OpenAPI JSON: http://localhost:8080/v3/api-docs
29+
30+
## Features Demonstrated
31+
32+
- Integration of springdoc-openapi with Scala classes
33+
- Automatic schema generation for Scala case classes
34+
- Support for complex type hierarchies
35+
- Custom schema customization
36+
37+
## Project Structure
38+
39+
- `src/main/scala/.../Application.scala` - Spring Boot application entry point
40+
- `src/main/scala/.../OpenAPIConfiguration.scala` - OpenAPI configuration
41+
- `src/main/scala/.../controller/` - REST controllers
42+
- `src/main/scala/.../model/` - Data models

examples/springdoc-openapi-scala-1/simple/build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ lazy val root = (project in file("."))
2424
"za.co.absa" %% "springdoc-openapi-scala-1" % `springdoc-openapi-scala-1-version`,
2525
"org.springdoc" % "springdoc-openapi-webmvc-core" % "1.7.0",
2626
"org.springframework.boot" % "spring-boot-starter-web" % "2.6.6",
27-
"com.fasterxml.jackson.core" % "jackson-databind" % "2.16.1"
27+
"com.fasterxml.jackson.core" % "jackson-databind" % "2.16.1",
28+
"org.scala-lang" % "scala-reflect" % scalaVersion.value
2829
),
2930
webappWebInfClasses := true,
3031
inheritJarManifest := true

examples/springdoc-openapi-scala-1/simple/project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
*/
1616

1717
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.2.4")
18+
addSbtPlugin("io.spray" % "sbt-revolver" % "0.10.0")

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package za.co.absa.springdocopenapiscala.examples.simple
1919
import com.fasterxml.jackson.databind.JsonNode
2020
import io.swagger.v3.oas.models.OpenAPI
2121
import io.swagger.v3.oas.models.info.Info
22-
import io.swagger.v3.oas.models.media.Schema
22+
import io.swagger.v3.oas.models.media.StringSchema
2323
import org.springdoc.core.customizers.OpenApiCustomiser
2424
import org.springframework.context.annotation.{Bean, Configuration}
2525
import za.co.absa.springdocopenapiscala.{Bundle, OpenAPIModelRegistration}
@@ -39,8 +39,7 @@ class OpenAPIConfiguration {
3939
),
4040
OpenAPIModelRegistration.ExtraTypesHandling.simpleMapping {
4141
case t if t =:= typeOf[JsonNode] =>
42-
val schema = new Schema
43-
schema.setType("string")
42+
val schema = new StringSchema
4443
schema.setFormat("json")
4544
schema
4645
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# springdoc-openapi-scala-2 Example Application
2+
3+
This is a simple example application demonstrating the use of springdoc-openapi-scala with Spring Boot 3.x.
4+
5+
## Prerequisites
6+
7+
- JDK 17 or higher
8+
- SBT 1.x
9+
- Scala 2.12.x
10+
11+
## Running the Application
12+
13+
To run the application with hot-reload enabled:
14+
15+
```bash
16+
cd springdoc-openapi-scala/examples/springdoc-openapi-scala-2/simple
17+
sed -i '' 's/`springdoc-openapi-scala-2-version`: String = \?\?\?/`springdoc-openapi-scala-2-version`: String = "0.3.2"/g' build.sbt # Omit '' after the -i flag if not on mac
18+
sbt compile
19+
sbt "~reStart"
20+
```
21+
22+
The `~reStart` command will automatically restart the application when source files change.
23+
24+
## Accessing the API Documentation
25+
26+
Once the application is running, you can access the OpenAPI documentation at:
27+
28+
- OpenAPI JSON: http://localhost:8080/v3/api-docs
29+
30+
## Features Demonstrated
31+
32+
- Integration of springdoc-openapi with Scala classes
33+
- Automatic schema generation for Scala case classes
34+
- Support for complex type hierarchies
35+
- Custom schema customization
36+
37+
## Project Structure
38+
39+
- `src/main/scala/.../Application.scala` - Spring Boot application entry point
40+
- `src/main/scala/.../OpenAPIConfiguration.scala` - OpenAPI configuration
41+
- `src/main/scala/.../controller/` - REST controllers
42+
- `src/main/scala/.../model/` - Data models

examples/springdoc-openapi-scala-2/simple/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ lazy val root = (project in file("."))
2323
libraryDependencies ++= Seq(
2424
"za.co.absa" %% "springdoc-openapi-scala-2" % `springdoc-openapi-scala-2-version`,
2525
"org.springdoc" % "springdoc-openapi-starter-webmvc-api" % "2.8.9",
26-
"org.springframework.boot" % "spring-boot-starter-web" % "3.2.0",
26+
"org.springframework.boot" % "spring-boot-starter-web" % "3.4.3",
2727
"org.playframework" %% "play-json" % "3.0.1"
2828
),
2929
webappWebInfClasses := true,

examples/springdoc-openapi-scala-2/simple/project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
*/
1616

1717
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.2.4")
18+
addSbtPlugin("io.spray" % "sbt-revolver" % "0.10.0")

examples/springdoc-openapi-scala-2/simple/src/main/scala/za/co/absa/springdocopenapiscala/examples/simple/OpenAPIConfiguration.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package za.co.absa.springdocopenapiscala.examples.simple
1818

1919
import io.swagger.v3.oas.models.OpenAPI
2020
import io.swagger.v3.oas.models.info.Info
21-
import io.swagger.v3.oas.models.media.Schema
21+
import io.swagger.v3.oas.models.media.StringSchema
2222
import org.springdoc.core.customizers.OpenApiCustomizer
2323
import org.springframework.context.annotation.{Bean, Configuration}
2424
import play.api.libs.json.JsValue
@@ -40,8 +40,7 @@ class OpenAPIConfiguration {
4040
),
4141
OpenAPIModelRegistration.ExtraTypesHandling.simpleMapping {
4242
case t if t =:= typeOf[JsValue] =>
43-
val schema = new Schema
44-
schema.setType("string")
43+
val schema = new StringSchema
4544
schema.setFormat("json")
4645
schema
4746
}

publish.sbt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ ThisBuild / developers := List(
3535
name = "Kevin Wallimann",
3636
email = "[email protected]",
3737
url = url("https://github.com/kevinwallimann")
38+
),
39+
Developer(
40+
id = "AlexGuzmanAtAbsa",
41+
name = "Alejandro Guzman",
42+
email = "[email protected]",
43+
url = url("https://github.com/AlexGuzmanAtAbsa")
3844
)
3945
)
4046

0 commit comments

Comments
 (0)