swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Nullable Integer ignores example value "null" and defaults to 0

Open dreis2211 opened this issue 3 years ago • 0 comments

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

dreis2211 avatar Aug 04 '22 05:08 dreis2211