Fix default value check 22/88922/2
authorMagic_J <panda.magic.j@gmail.com>
Mon, 9 Apr 2018 06:17:44 +0000 (14:17 +0800)
committerRobert Varga <nite@hq.sk>
Tue, 7 Apr 2020 03:34:50 +0000 (03:34 +0000)
TypeDefinition.getDefaultValue() is returning an optional, which
results in it always being non-null. Fix the check for nullness
and make sure we use the correct value.

Change-Id: Id5aba6cd215d4e19f8b583a81e5599daa9bbe12d
Signed-off-by: Magic_J <panda.magic.j@gmail.com>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/ModelGenerator.java

index 3b845f91e672c73363fe88bd4796d634b2b99357..1d03bfb31475c458ca12b611e582fae7f49708b3 100644 (file)
@@ -486,7 +486,8 @@ public class ModelGenerator {
     private String processTypeDef(final TypeDefinition<?> leafTypeDef, final DataSchemaNode node,
                                   final ObjectNode property, final SchemaContext schemaContext) {
         final String jsonType;
-        if (leafTypeDef.getDefaultValue() == null) {
+        final Object defValue = leafTypeDef.getDefaultValue().orElse(null);
+        if (defValue == null) {
             if (leafTypeDef instanceof BinaryTypeDefinition) {
                 jsonType = processBinaryType(property);
 
@@ -527,7 +528,7 @@ public class ModelGenerator {
 
             }
         } else {
-            jsonType = String.valueOf(leafTypeDef.getDefaultValue());
+            jsonType = String.valueOf(defValue);
         }
         putIfNonNull(property, TYPE_KEY, jsonType);
         return jsonType;