@@ -25,19 +25,18 @@ import scala.collection.JavaConverters._
2525class OpenAPIScalaCustomizer (components : Components ) extends OpenApiCustomizer {
2626
2727 override def customise (openAPIOutOfSync : OpenAPI ): Unit = {
28- // this is needed as for some reason springdoc-openapi cache the `OpenAPI` at the beginning
29- // and newly added `Components` are not taken into account on JSON/YAML generation
30- openAPIOutOfSync.setComponents(components)
28+ // Serialize the customized Components object to a JSON string.
29+ val jsonRepresentation = Json .pretty(components)
3130
32- fixResponsesReturningUnit(openAPIOutOfSync)
33-
34- val jsonRepresentation = Json .pretty(openAPIOutOfSync)
31+ // Deserialize the JSON string back into a new Components object to iron out any issues.
32+ val newComponents = Json .mapper().readValue(jsonRepresentation, classOf [Components ])
3533
36- // Deserialize the JSON string back into a new OpenAPI object
37- val newOpenAPI = Json .mapper().readValue(jsonRepresentation, classOf [OpenAPI ])
34+ // Finally replace the Components object in the OpenAPI instance.
35+ // This is needed as for some reason springdoc-openapi cache the `OpenAPI` at the beginning
36+ // and newly added `Components` are not taken into account on JSON/YAML generation.
37+ openAPIOutOfSync.setComponents(newComponents)
3838
39- // Replace the root by copying properties from the new OpenAPI object
40- openAPIOutOfSync.setComponents(newOpenAPI.getComponents)
39+ fixResponsesReturningUnit(openAPIOutOfSync)
4140 }
4241
4342 private def fixResponsesReturningUnit (openAPI : OpenAPI ): Unit = {
0 commit comments