@@ -1879,7 +1879,6 @@ public BigDecimal getBigDecimal(String key, ObjectNode node, boolean required, S
1879
1879
return value ;
1880
1880
}
1881
1881
1882
-
1883
1882
public Integer getInteger (String key , ObjectNode node , boolean required , String location , ParseResult result ) {
1884
1883
Integer value = null ;
1885
1884
JsonNode v = node .get (key );
@@ -2747,7 +2746,7 @@ at the moment path passed as string (basePath) from upper components can be both
2747
2746
}
2748
2747
}
2749
2748
schema = items ;
2750
- }else if (itemsNode != null ){
2749
+ } else if (itemsNode != null ) {
2751
2750
Schema items = new Schema ();
2752
2751
if (itemsNode .getNodeType ().equals (JsonNodeType .OBJECT )) {
2753
2752
items .setItems (getSchema (itemsNode , location , result ));
@@ -2905,7 +2904,7 @@ at the moment path passed as string (basePath) from upper components can be both
2905
2904
2906
2905
Map <String , Schema > properties = new LinkedHashMap <>();
2907
2906
ObjectNode propertiesObj = getObject ("properties" , node , false , location , result );
2908
- Schema property = null ;
2907
+ Schema property ;
2909
2908
2910
2909
Set <String > keys = getKeys (propertiesObj );
2911
2910
for (String name : keys ) {
@@ -2925,10 +2924,24 @@ at the moment path passed as string (basePath) from upper components can be both
2925
2924
schema .setProperties (properties );
2926
2925
}
2927
2926
2927
+ bool = getBoolean ("nullable" , node , false , location , result );
2928
+ if (bool != null ) {
2929
+ schema .setNullable (bool );
2930
+ }
2931
+
2928
2932
//sets default value according to the schema type
2929
2933
if (node .get ("default" ) != null && result .isInferSchemaType ()) {
2934
+ boolean nullable = schema .getNullable () == null || schema .getNullable ();
2935
+ boolean isDefaultNodeTypeNull = node .get ("default" ) != null && node .get ("default" ).isNull ();
2930
2936
if (!StringUtils .isBlank (schema .getType ())) {
2931
- if (schema .getType ().equals ("array" )) {
2937
+ if (isDefaultNodeTypeNull ) {
2938
+ if (nullable ) {
2939
+ schema .setDefault (null );
2940
+ } else {
2941
+ String expectedType = String .format ("non-null %s" , schema .getType ());
2942
+ result .invalidType (location , "default" , expectedType , node );
2943
+ }
2944
+ } else if (schema .getType ().equals ("array" )) {
2932
2945
ArrayNode array = getArray ("default" , node , false , location , result );
2933
2946
if (array != null ) {
2934
2947
schema .setDefault (array );
@@ -2975,15 +2988,10 @@ at the moment path passed as string (basePath) from upper components can be both
2975
2988
if (defaultObject != null ) {
2976
2989
schema .setDefault (defaultObject );
2977
2990
}
2978
- }else {
2991
+ } else {
2979
2992
schema .setDefault (null );
2980
2993
}
2981
2994
2982
- bool = getBoolean ("nullable" , node , false , location , result );
2983
- if (bool != null ) {
2984
- schema .setNullable (bool );
2985
- }
2986
-
2987
2995
Map <String , Object > extensions = getExtensions (node );
2988
2996
if (extensions != null && extensions .size () > 0 ) {
2989
2997
schema .setExtensions (extensions );
0 commit comments