Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ class OpenAPIScalaCustomizer(components: Components) extends OpenApiCustomizer {
allOperations.foreach { case (_, operation) =>
val responses = operation.getResponses.asScala
responses.foreach { case (_, response) =>
val isReturningUnit = response.getContent.asScala.exists(
_._2.getSchema.get$ref == "#/components/schemas/BoxedUnit"
)
if (isReturningUnit) response.setContent(None.orNull)
val contentOpt = Option(response.getContent)
contentOpt.map(_.asScala.foreach { case (_, mediaType) =>
val schemaOpt = Option(mediaType.getSchema)
schemaOpt.map { schema =>
val isReturningUnit = schema.get$ref == "#/components/schemas/BoxedUnit"
if (isReturningUnit) response.setContent(None.orNull)
}
})
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,72 @@ class OpenAPIScalaCustomizerSpec extends AnyFlatSpec {
)
}

it should "do nothing if a response doesn't have content" in {
val components = new Components()
val openAPIScalaCustomizer = new OpenAPIScalaCustomizer(components)

val openAPI = new OpenAPI()
.paths(
new Paths()
.addPathItem(
"/api/endpoint",
new PathItem()
.delete(
new Operation()
.responses(
new ApiResponses()
.addApiResponse(
"204",
new ApiResponse()
.description("No Content")
)
)
)
)
)

openAPIScalaCustomizer.customise(openAPI)

assert(
Option(openAPI.getPaths.get("/api/endpoint").getDelete.getResponses.get("204").getContent).isEmpty
)
}

it should "do nothing if a response doesn't have a schema" in {
val components = new Components()
val openAPIScalaCustomizer = new OpenAPIScalaCustomizer(components)

val openAPI = new OpenAPI()
.paths(
new Paths()
.addPathItem(
"/api/endpoint",
new PathItem()
.delete(
new Operation()
.responses(
new ApiResponses()
.addApiResponse(
"204",
new ApiResponse()
.content(
new Content()
.addMediaType(
"*/*",
new MediaType()
)
)
)
)
)
)
)

openAPIScalaCustomizer.customise(openAPI)

assert(
Option(openAPI.getPaths.get("/api/endpoint").getDelete.getResponses.get("204").getContent).isDefined
)
}

}