From c3d15396d264b083c0f8755e289dcdbbc812f22d Mon Sep 17 00:00:00 2001 From: Ilya Igushev Date: Thu, 25 Jun 2020 06:46:02 +0000 Subject: [PATCH] Fix processing of hexadecimal, octal values JSON doesn't support hexadecimal, octal numbers, unlike YANG. Therefore when YANG type definition has hexadecimal,or octal default value of YANG leaf used string JSON format. Change-Id: I95b1756c0092991a591164b3432f7d93214dfe1d JIRA: NETCONF-703 Signed-off-by: illia.ihushev --- .../rest/doc/impl/DefinitionGenerator.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/DefinitionGenerator.java b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/DefinitionGenerator.java index 8013f2a07d..b54cf0b47b 100644 --- a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/DefinitionGenerator.java +++ b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/DefinitionGenerator.java @@ -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 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(); -- 2.36.6