@@ -25,19 +25,18 @@ import scala.collection.JavaConverters._
25
25
class OpenAPIScalaCustomizer (components : Components ) extends OpenApiCustomizer {
26
26
27
27
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)
31
30
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 ])
35
33
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)
38
38
39
- // Replace the root by copying properties from the new OpenAPI object
40
- openAPIOutOfSync.setComponents(newOpenAPI.getComponents)
39
+ fixResponsesReturningUnit(openAPIOutOfSync)
41
40
}
42
41
43
42
private def fixResponsesReturningUnit (openAPI : OpenAPI ): Unit = {
0 commit comments