From fb8ca5fb66755734d8095b0bbb0a9d9e7dfda54c Mon Sep 17 00:00:00 2001 From: Andreas Hufler Date: Tue, 25 Feb 2025 08:34:44 +0100 Subject: [PATCH 1/2] update spring boot and swagger --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d4daa2c..5bc3090 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 3.3.8 + 3.4.2 @@ -86,7 +86,7 @@ org.springdoc springdoc-openapi-starter-webmvc-ui - 2.6.0 + 2.8.5 From 88cd1c42b8709a59e9f730989527c9f2fa1560be Mon Sep 17 00:00:00 2001 From: Andreas Hufler Date: Tue, 25 Feb 2025 08:35:12 +0100 Subject: [PATCH 2/2] fix nullability hack for new swagger version --- .../customization/default_not_null/NullableCustomizer.java | 5 ++++- .../default_not_null/NullablePropertyCustomizer.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/it/aboutbits/springboot/toolbox/swagger/customization/default_not_null/NullableCustomizer.java b/src/main/java/it/aboutbits/springboot/toolbox/swagger/customization/default_not_null/NullableCustomizer.java index 26a2b53..48574c5 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/swagger/customization/default_not_null/NullableCustomizer.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/swagger/customization/default_not_null/NullableCustomizer.java @@ -18,9 +18,12 @@ public void customise(OpenAPI openApi) { if (((Schema) schema).getProperties() != null) { var requiredProperties = new ArrayList(); ((Schema) schema).getProperties().forEach((propertyName, property) -> { - if (property.getNullable() == null || !property.getNullable()) { + if (property.getTitle() == null || !property.getTitle().equals("NULLABLE")) { requiredProperties.add(propertyName); } + if (property.getTitle() != null && property.getTitle().equals("NULLABLE")) { + property.setTitle(null); + } }); schema.setRequired(requiredProperties); } diff --git a/src/main/java/it/aboutbits/springboot/toolbox/swagger/customization/default_not_null/NullablePropertyCustomizer.java b/src/main/java/it/aboutbits/springboot/toolbox/swagger/customization/default_not_null/NullablePropertyCustomizer.java index a8fdf57..47b0cbf 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/swagger/customization/default_not_null/NullablePropertyCustomizer.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/swagger/customization/default_not_null/NullablePropertyCustomizer.java @@ -31,7 +31,7 @@ public Schema customize(Schema property, AnnotatedType annotatedType) { if (annotatedType.getCtxAnnotations() != null && Arrays.stream(annotatedType.getCtxAnnotations()) .anyMatch(a -> "Nullable".equals(a.annotationType().getSimpleName()))) { - property.setNullable(true); + property.setTitle("NULLABLE"); } return property;