swagger-api / swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
http://swagger.io
Apache License 2.0
7.38k stars 2.18k forks source link

Bug in swagger-core-2.1.2, @Schema(implementation = Map.class) causes NPE #3534

Open a11970 opened 4 years ago

a11970 commented 4 years ago

Sample code to reproduce to problem:

  @GET
    @Path("path")
    @Operation(summary = "A summary.",
            description = "A description.",
            responses = {@ApiResponse(responseCode = "200",
                    content = @Content(schema = @Schema(implementation = Map.class)))
            }
    )
    public Map<String, String> getMapping() {
        return null;
    }

The NPE occurs in the class io.swagger.v3.core.util.AnnotationsUtils, method resolveSchemaFromType because Swagger doesn't resolve any schema implementation for Map.class. This line:

...
                 if (StringUtils.isNotBlank(resolvedSchema.schema.getName())) {
...
strangelookingnerd commented 4 years ago

I found that List.class is causing the same issue. Seems to be related to the class being an Interface.

Santobert commented 4 years ago

The same error occurs when using hash maps. Is there a known workaround?