Generated AAI Swagger file has schema violations
[aai/schema-service.git] / aai-schema-gen / src / main / java / org / onap / aai / schemagen / genxsd / XSDElement.java
index bbdcd70..7cddc7b 100644 (file)
 package org.onap.aai.schemagen.genxsd;
 
 import com.google.common.base.Joiner;
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.StringTokenizer;
 import java.util.Vector;
+
 import org.apache.commons.lang3.StringUtils;
 import org.onap.aai.setup.SchemaVersion;
 import org.w3c.dom.Attr;
@@ -131,9 +133,9 @@ public class XSDElement implements Element {
                 .equals(this.xmlElementElement.getAttribute("name"))) {
                 continue;
             }
-//      This stopped working, replaced with above - should figure out why...
-//      if ( !xmlPropElement.getParentNode().isSameNode(this.xmlElementElement))
-//        continue;
+            // This stopped working, replaced with above - should figure out why...
+            // if ( !xmlPropElement.getParentNode().isSameNode(this.xmlElementElement))
+            // continue;
             NodeList childNodes = xmlPropElement.getElementsByTagName("xml-property");
 
             for (int j = 0; j < childNodes.getLength(); ++j) {
@@ -158,7 +160,7 @@ public class XSDElement implements Element {
             }
         }
         if (pathDescriptionProperty != null) {
-            //suppress non-printable characters in a description
+            // suppress non-printable characters in a description
             String replaceDescription = pathDescriptionProperty.replaceAll("[^\\p{ASCII}]", "");
             return replaceDescription;
         }
@@ -189,8 +191,8 @@ public class XSDElement implements Element {
                     }
                     if (needValue == VALUE_INDEXED_PROPS && attrValue.equals("indexedProps")) {
                         useValue = VALUE_INDEXED_PROPS;
-                    } else if (needValue == VALUE_DSLSTARTNODE &&
-                        attrValue.equals("dslStartNodeProps")) {
+                    } else if (needValue == VALUE_DSLSTARTNODE
+                        && attrValue.equals("dslStartNodeProps")) {
                         useValue = VALUE_DSLSTARTNODE;
                     }
                     if (useValue != VALUE_NONE && attrName.equals("value")) {
@@ -262,12 +264,10 @@ public class XSDElement implements Element {
         StringBuilder sbParameter = new StringBuilder();
         sbParameter.append("        - name: ").append(this.getAttribute("name")).append("\n");
         sbParameter.append(("          in: query\n"));
-        if (this.getAttribute("description") != null &&
-            this.getAttribute("description").length() > 0) {
+        if (this.getAttribute("description") != null
+            && this.getAttribute("description").length() > 0) {
             sbParameter.append("          description: ").append(this.getAttribute("description"))
                 .append("\n");
-        } else {
-            sbParameter.append(("          description: n/a\n"));
         }
         sbParameter.append(("          required: false\n"));
         if (("java.lang.String").equals(this.getAttribute("type"))) {
@@ -281,6 +281,14 @@ public class XSDElement implements Element {
             sbParameter.append("          type: integer\n");
             sbParameter.append("          format: int32\n");
         }
+        if (("java.lang.Float").equals(this.getAttribute("type"))) {
+            sbParameter.append("          type: number\n");
+            sbParameter.append("          format: float\n");
+        }
+        if (("java.lang.Double").equals(this.getAttribute("type"))) {
+            sbParameter.append("          type: number\n");
+            sbParameter.append("          format: double\n");
+        }
         if (("java.lang.Boolean").equals(this.getAttribute("type"))) {
             sbParameter.append("          type: boolean\n");
         }
@@ -314,13 +322,17 @@ public class XSDElement implements Element {
             sbParameter.append("          type: integer\n");
             sbParameter.append("          format: int32\n");
         }
+        if (("java.lang.Float").equals(this.getAttribute("type"))) {
+            sbParameter.append("          type: number\n");
+            sbParameter.append("          format: float\n");
+        }
+        if (("java.lang.Double").equals(this.getAttribute("type"))) {
+            sbParameter.append("          type: number\n");
+            sbParameter.append("          format: double\n");
+        }
         if (("java.lang.Boolean").equals(this.getAttribute("type"))) {
             sbParameter.append("          type: boolean\n");
         }
-        if (StringUtils.isNotBlank(this.getAttribute("name"))) {
-            sbParameter.append("          example: " + "__")
-                .append(this.getAttribute("name").toUpperCase()).append("__").append("\n");
-        }
         return sbParameter.toString();
     }
 
@@ -330,8 +342,9 @@ public class XSDElement implements Element {
         String elementType = this.getAttribute("type");
         String elementContainerType = this.getAttribute("container-type");
         String elementIsRequired = this.getAttribute("required");
-        String addType = elementType.contains("." + v.toString() + ".") ?
-            elementType.substring(elementType.lastIndexOf('.') + 1) : null;
+        String addType = elementType.contains("." + v.toString() + ".")
+            ? elementType.substring(elementType.lastIndexOf('.') + 1)
+            : null;
 
         if (addType != null) {
             sbElement.append("        <xs:element ref=\"tns:")
@@ -348,6 +361,12 @@ public class XSDElement implements Element {
         if (elementType.equals("java.lang.Integer")) {
             sbElement.append(" type=\"xs:int\"");
         }
+        if (elementType.equals("java.lang.Float")) {
+            sbElement.append(" type=\"xs:float\"");
+        }
+        if (elementType.equals("java.lang.Double")) {
+            sbElement.append(" type=\"xs:double\"");
+        }
         if (elementType.equals("java.lang.Boolean")) {
             sbElement.append(" type=\"xs:boolean\"");
         }
@@ -363,18 +382,18 @@ public class XSDElement implements Element {
             sbElement.append(
                 StringUtils.isNotEmpty(annotation) ? ">" + OxmFileProcessor.LINE_SEPARATOR : "");
             sbElement.append(annotation);
-            sbElement.append(StringUtils.isNotEmpty(annotation) ?
-                "        </xs:element>" + OxmFileProcessor.LINE_SEPARATOR :
-                "/>" + OxmFileProcessor.LINE_SEPARATOR);
+            sbElement.append(StringUtils.isNotEmpty(annotation)
+                ? "        </xs:element>" + OxmFileProcessor.LINE_SEPARATOR
+                "/>" + OxmFileProcessor.LINE_SEPARATOR);
         } else {
             sbElement.append("/>").append(OxmFileProcessor.LINE_SEPARATOR);
         }
         return this.getHTMLElementWrapper(sbElement.toString(), v, useAnnotation);
-//    return sbElement.toString();
+        // return sbElement.toString();
     }
 
     public String getHTMLElementWrapper(String unwrappedElement, SchemaVersion v,
-                                        boolean useAnnotation) {
+        boolean useAnnotation) {
 
         NodeList childNodes = this.getElementsByTagName("xml-element-wrapper");
 
@@ -392,8 +411,9 @@ public class XSDElement implements Element {
         sbElement.append("        <xs:element name=\"").append(xmlElementWrapper).append("\"");
         String elementType = xmlElementElement.getAttribute("type");
         String elementIsRequired = this.getAttribute("required");
-        String addType = elementType.contains("." + v.toString() + ".") ?
-            elementType.substring(elementType.lastIndexOf('.') + 1) : null;
+        String addType = elementType.contains("." + v.toString() + ".")
+            ? elementType.substring(elementType.lastIndexOf('.') + 1)
+            : null;
 
         if (elementIsRequired == null || !elementIsRequired.equals("true") || addType != null) {
             sbElement.append(" minOccurs=\"0\"");
@@ -469,6 +489,12 @@ public class XSDElement implements Element {
         } else if (("java.lang.Integer").equals(this.getAttribute("type"))) {
             sbProperties.append("integer\n");
             sbProperties.append("        format: int32\n");
+        } else if (("java.lang.Float").equals(this.getAttribute("type"))) {
+            sbProperties.append("number\n");
+            sbProperties.append("        format: float\n");
+        } else if (("java.lang.Double").equals(this.getAttribute("type"))) {
+            sbProperties.append("number\n");
+            sbProperties.append("        format: double\n");
         } else if (("java.lang.Boolean").equals(this.getAttribute("type"))) {
             sbProperties.append("boolean\n");
         }
@@ -490,11 +516,6 @@ public class XSDElement implements Element {
                     "          *This property can be used as a filter to find the start node for a dsl query\n");
             }
         }
-        String elementAlsoRequiresProperty = this.getRequiresProperty();
-        if (StringUtils.isNotEmpty(elementAlsoRequiresProperty)) {
-            sbProperties.append("        also requires: ").append(elementAlsoRequiresProperty)
-                .append("\n");
-        }
         return sbProperties.toString();
     }
 
@@ -503,6 +524,8 @@ public class XSDElement implements Element {
             case "java.lang.String":
             case "java.lang.Long":
             case "java.lang.Integer":
+            case "java.lang.Float":
+            case "java.lang.Double":
             case "java.lang.Boolean":
                 return true;
         }
@@ -799,5 +822,4 @@ public class XSDElement implements Element {
         xmlElementElement.setIdAttributeNode(idAttr, isId);
     }
 
-
 }