55import org .springdoc .core .customizers .OpenApiCustomizer ;
66
77import java .util .ArrayList ;
8+ import java .util .Map ;
89
910public class NullableCustomizer implements OpenApiCustomizer {
1011 @ Override
@@ -15,18 +16,32 @@ public void customise(OpenAPI openApi) {
1516 }
1617 openApi .getComponents ().getSchemas ().values ()
1718 .forEach (schema -> {
19+ var requiredProperties = new ArrayList <String >();
1820 if (((Schema <?>) schema ).getProperties () != null ) {
19- var requiredProperties = new ArrayList <String >();
20- ((Schema <?>) schema ).getProperties ().forEach ((propertyName , property ) -> {
21- if (property .getTitle () == null || !property .getTitle ().equals ("NULLABLE" )) {
22- requiredProperties .add (propertyName );
23- }
24- if (property .getTitle () != null && property .getTitle ().equals ("NULLABLE" )) {
25- property .setTitle (null );
21+ var properties = ((Schema <?>) schema ).getProperties ();
22+ processProperties (properties , requiredProperties );
23+ }
24+ if (schema .getAllOf () != null ) {
25+ schema .getAllOf ().forEach (allOfSchema -> {
26+ var allOfSchemaTyped = (Schema <?>) allOfSchema ;
27+ if (allOfSchemaTyped .getProperties () != null ) {
28+ var properties = allOfSchemaTyped .getProperties ();
29+ processProperties (properties , requiredProperties );
2630 }
2731 });
28- schema .setRequired (requiredProperties );
2932 }
33+ schema .setRequired (requiredProperties );
3034 });
3135 }
36+
37+ private static void processProperties (Map <String , Schema > properties , ArrayList <String > requiredProperties ) {
38+ properties .forEach ((propertyName , property ) -> {
39+ if (property .getTitle () == null || !property .getTitle ().equals ("NULLABLE" )) {
40+ requiredProperties .add (propertyName );
41+ }
42+ if (property .getTitle () != null && property .getTitle ().equals ("NULLABLE" )) {
43+ property .setTitle (null );
44+ }
45+ });
46+ }
3247}
0 commit comments