Nullable Integer ignores example value "null" and defaults to 0 (original) (raw)

Hi,

I was migrating a Spring-Boot app from SpringFox to SpringDoc and noticed that the example value of the Schema annotation for Integer fields is ignored and defaults to 0.

E.g. defining the following has no effect:

    @Schema(nullable = true, example = "null")
    private Integer id;

image

To Reproduce

Steps to reproduce the behaviour:

Spring-Boot 2.7.2 and SpringDoc 1.6.9 are used - and thus Swagger 2.2.0
Checkout https://github.com/dreis2211/swagger-nullable-bug
Run ./gradlew bootRun
Check http://localhost:8080/swagger-ui/index.html#/test-controller/hello

Alternatively, just try this test:

    @Test
    void schemaExample() {
        ResolvedSchema resolvedSchema = ModelConverters.getInstance()
                .resolveAsResolvedSchema(new AnnotatedType(TestData.class));

        Schema<?> testDataSchema = resolvedSchema.referencedSchemas.get("TestData");
        Schema<?> idSchema = testDataSchema.getProperties().get("id");
        assertThat(idSchema.getExampleSetFlag()).isTrue();
    }

    public class TestData {

        @io.swagger.v3.oas.annotations.media.Schema(nullable = true, example = "null")
        private Integer id;

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

    }

Expected behaviour

Primitive wrapper types allow null as example value instead of showing 0.

Cheers,
Christoph