Skip to content
Merged
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The library has springdoc-openapi as a provided dependency,
thus users of the library have to include that dependency in their projects:
- for springdoc-openapi 1.x versions `1.6.7` up to `1.7.0` (including) of
`"org.springdoc" % "springdoc-openapi-webmvc-core"` are supported
- for springdoc-openapi 2.x versions `2.0.0` up to `2.3.0` (including) of
- for springdoc-openapi 2.x versions `2.0.0` up to `2.8.9` (including) of
`"org.springdoc" % "springdoc-openapi-starter-webmvc-api"` are supported

### Add library dependency to SBT/Maven
Expand Down
2 changes: 1 addition & 1 deletion examples/springdoc-openapi-scala-2/simple/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ lazy val root = (project in file("."))
.settings(
libraryDependencies ++= Seq(
"za.co.absa" %% "springdoc-openapi-scala-2" % `springdoc-openapi-scala-2-version`,
"org.springdoc" % "springdoc-openapi-starter-webmvc-api" % "2.3.0",
"org.springdoc" % "springdoc-openapi-starter-webmvc-api" % "2.8.9",
"org.springframework.boot" % "spring-boot-starter-web" % "3.2.0",
"org.playframework" %% "play-json" % "3.0.1"
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package za.co.absa.springdocopenapiscala

import io.swagger.v3.core.util.Json
import io.swagger.v3.oas.models.{Components, OpenAPI}
import za.co.absa.springdocopenapiscala.SpringdocOpenAPIVersionSpecificTypes.OpenApiCustomizer

Expand All @@ -24,9 +25,16 @@ import scala.collection.JavaConverters._
class OpenAPIScalaCustomizer(components: Components) extends OpenApiCustomizer {

override def customise(openAPIOutOfSync: OpenAPI): Unit = {
// this is needed as for some reason springdoc-openapi cache the `OpenAPI` at the beginning
// and newly added `Components` are not taken into account on JSON/YAML generation
openAPIOutOfSync.setComponents(components)
// Serialize the customized Components object to a JSON string.
val jsonRepresentation = Json.pretty(components)

// Deserialize the JSON string back into a new Components object to iron out any issues.
val newComponents = Json.mapper().readValue(jsonRepresentation, classOf[Components])

// Finally replace the Components object in the OpenAPI instance.
// This is needed as for some reason springdoc-openapi cache the `OpenAPI` at the beginning
// and newly added `Components` are not taken into account on JSON/YAML generation.
openAPIOutOfSync.setComponents(newComponents)

fixResponsesReturningUnit(openAPIOutOfSync)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,6 @@ class OpenAPIScalaCustomizerSpec extends AnyFlatSpec {

behavior of "customise"

it should "set `components` of its argument OpenAPI object to one injected via DI to the class" in {
val components = new Components().addSchemas("a", new Schema)
val openAPIScalaCustomizer = new OpenAPIScalaCustomizer(components)

val openAPI = initializeOpenAPI

openAPIScalaCustomizer.customise(openAPI)

assert(openAPI.getComponents === components)
}

it should "convert all responses returning Unit (BoxedUnit reference) to empty response" in {
val components = new Components()
val openAPIScalaCustomizer = new OpenAPIScalaCustomizer(components)
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object Dependencies {

def springdocOpenapi(majorVersion: Int): String = majorVersion match {
case 1 => "[1.6.7,1.7.0]"
case 2 => "[2.0.0,2.3.0]"
case 2 => "[2.0.0,2.8.9]"
}
}

Expand Down