Fix processing of hexadecimal, octal values
[netconf.git] / restconf / sal-rest-docgen / src / main / java / org / opendaylight / netconf / sal / rest / doc / impl / DefinitionGenerator.java
index 8013f2a07d57a1259033bcf810dacca0e22fb490..b54cf0b47b0b89e5b7f97e7107526e9827f0d466 100644 (file)
@@ -713,7 +713,11 @@ public class DefinitionGenerator {
                         setDefaultValue(property, new BigDecimal(stringDefaultValue));
                     } else if (leafTypeDef instanceof RangeRestrictedTypeDefinition) {
                         //uint8,16,32 int8,16,32,64
-                        setDefaultValue(property, Long.valueOf(stringDefaultValue));
+                        if (isHexadecimalOrOctal((RangeRestrictedTypeDefinition)leafTypeDef)) {
+                            setDefaultValue(property, stringDefaultValue);
+                        } else {
+                            setDefaultValue(property, Long.valueOf(stringDefaultValue));
+                        }
                     } else {
                         setDefaultValue(property, stringDefaultValue);
                     }
@@ -841,6 +845,10 @@ public class DefinitionGenerator {
         final Optional<Number> maybeLower = ((RangeRestrictedTypeDefinition<?, ?>) leafTypeDef).getRangeConstraint()
                 .map(RangeConstraint::getAllowedRanges).map(RangeSet::span).map(Range::lowerEndpoint);
 
+        if (isHexadecimalOrOctal(leafTypeDef)) {
+            return STRING_TYPE;
+        }
+
         if (leafTypeDef instanceof DecimalTypeDefinition) {
             maybeLower.ifPresent(number -> setDefaultValue(property, (BigDecimal) number));
             return NUMBER_TYPE;
@@ -865,6 +873,15 @@ public class DefinitionGenerator {
         return INTEGER_TYPE;
     }
 
+    private boolean isHexadecimalOrOctal(RangeRestrictedTypeDefinition typeDef) {
+        final Optional<?> optDefaultValue = typeDef.getDefaultValue();
+        if (optDefaultValue.isPresent()) {
+            final String defaultValue = ((String)optDefaultValue.get());
+            return defaultValue.startsWith("0") || defaultValue.startsWith("-0");
+        }
+        return false;
+    }
+
     private String processInstanceIdentifierType(final DataSchemaNode node, final ObjectNode property,
                                                  final SchemaContext schemaContext) {
         SchemaPath path = node.getPath();