Skip to content

fixResponsesReturningUnit throws NullPointerExceptions for empty schemas #33

@kevinwallimann

Description

@kevinwallimann

Description

The method isReturningUnit in OpenAPIScalaCustomizer can throw a NullPointerException

Case 1: No Content object
Error messsage

java.lang.NullPointerException: Cannot invoke "scala.collection.IterableLike.exists(scala.Function1)" because the return value of "scala.collection.convert.Decorators$AsScala.asScala()" is null
	at za.co.absa.ingestionaas.configservice.configuration.springdocopenapiscala.OpenAPIScalaCustomizer.$anonfun$fixResponsesReturningUnit$4(OpenAPIScalaCustomizer.scala:26)

Can happen for

  @Operation(summary = "Delete entity", tags = Array("entities"))
  @ApiResponses(
    Array(
      new ApiResponse(responseCode = "204", description = "No Content")
    )
    def deleteEntity(@PathVariable id: Long): CompletableFuture[Void]

Case 2: Existing Content, but no schema
One could argue that in this case, a schema should be added, but I think a NPE should still not be thrown
Error message:

java.lang.NullPointerException: Cannot invoke "io.swagger.v3.oas.models.media.Schema.get$ref()" because the return value of "io.swagger.v3.oas.models.media.MediaType.getSchema()" is null
	at za.co.absa.ingestionaas.configservice.configuration.springdocopenapiscala.OpenAPIScalaCustomizer.$anonfun$fixResponsesReturningUnit$4(OpenAPIScalaCustomizer.scala:26)

Can happen for the following ApiResponse (Note: the example is shortened, but it doesn't matter if there's another ApiResponse that contains a schema)

  @Operation(summary = "Get entity", tags = Array("entities"))
  @ApiResponses(
    Array(
        new ApiResponse(
          responseCode = "401",
          description = "Unauthorized",
          content = Array(new Content(examples = Array(new ExampleObject(value = """{
             "error": "Unauthorized"
           }"""))))
        )
    )
    def getEntity(@PathVariable id: Long): CompletableFuture[Entity]

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions