summaryrefslogtreecommitdiffstats
path: root/aai-schema-gen/src/main/java/org
diff options
context:
space:
mode:
authorJames Forsyth <jf2512@att.com>2019-08-05 13:25:15 +0000
committerGerrit Code Review <gerrit@onap.org>2019-08-05 13:25:15 +0000
commit127b1c09eb66ff7f9273e1e79d283e94bd731b14 (patch)
treed4df68de7e204d633f6bb567bb1d19ce2b6eb060 /aai-schema-gen/src/main/java/org
parent7d3e532f6b3120996b78da36ef859028de8b9818 (diff)
parent21b104df3c85d99917719768323c1745e2607f49 (diff)
Merge "Replace relationship array with object in generated swagger"
Diffstat (limited to 'aai-schema-gen/src/main/java/org')
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/NodesYAMLfromOXM.java63
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/YAMLfromOXM.java36
2 files changed, 82 insertions, 17 deletions
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/NodesYAMLfromOXM.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/NodesYAMLfromOXM.java
index e28c127..a491872 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/NodesYAMLfromOXM.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/NodesYAMLfromOXM.java
@@ -175,10 +175,38 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
if (namespaceFilter != null && (!namespaceFilter.contains(entry.getKey()))) {
continue;
}
+ logger.debug(
+ "Key: " + entry.getKey() + "Test: " + (entry.getKey() == "relationship-dict"));
+ if (entry.getKey().matches("relationship-dict")) {
+ String jb = entry.getValue();
+ logger.debug("Value: " + jb);
+ int ndx = jb.indexOf("related-to-property:");
+ if (ndx > 0) {
+ jb = jb.substring(0, ndx);
+ jb = jb.replaceAll(" +$", "");
+ }
+ logger.debug("Value-after: " + jb);
+ sb.append(jb);
+ continue;
+ }
sb.append(entry.getValue());
}
return sb.toString();
}
+
+ private String getDictionary(String resource) {
+ StringBuffer dictSb = new StringBuffer();
+ dictSb.append(" " + resource + ":\n");
+ dictSb.append(" description: |\n");
+ dictSb.append(" dictionary of " + resource + "\n");
+ dictSb.append(" type: object\n");
+ dictSb.append(" properties:\n");
+ dictSb.append(" " + resource + ":\n");
+ dictSb.append(" type: array\n");
+ dictSb.append(" items:\n");
+ dictSb.append(" $ref: \"#/definitions/" + resource + "-dict\"\n");
+ return dictSb.toString();
+ }
private String processJavaTypeElementSwagger(String javaTypeName, Element javaTypeElement,
StringBuffer pathSb, StringBuffer definitionsSb, String path, String tag, String opId,
@@ -304,6 +332,7 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
// pathParams.toString())+sbParameters.toString()); //cp8128 don't append the pathParams
// to sbParameters so that child nodes don't contain the parameters from parent
StringBuffer newPathParams = new StringBuffer(sbParameters.toString());
+ String useName;
for (int k = 0; addTypeV != null && k < addTypeV.size(); ++k) {
String addType = addTypeV.elementAt(k);
namespaceFilter.add(getXmlRootElementName(addType));
@@ -324,9 +353,15 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
} else if (getItemName == null) {
++propertyCnt;
sbProperties.append(" " + getXmlRootElementName(addType) + ":\n");
- sbProperties.append(" type: array\n items:\n");
- sbProperties.append(" $ref: \"#/definitions/"
+ if ( "RelationshipList".equals(addType)) {
+ sbProperties.append(" type: object\n");
+ sbProperties.append(" $ref: \"#/definitions/"
+ + itemName + "\"\n");
+ } else {
+ sbProperties.append(" type: array\n items:\n");
+ sbProperties.append(" $ref: \"#/definitions/"
+ (itemName == "" ? "aai-internal" : itemName) + "\"\n");
+ }
if (StringUtils.isNotEmpty(elementDescription)) {
sbProperties
.append(" description: " + elementDescription + "\n");
@@ -347,10 +382,16 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
processJavaTypeElementSwagger(addType, getJavaTypeElementSwagger(addType),
pathSb, definitionsSb, path, tag == null ? useTag : tag, useOpId, null,
newPathParams, validEdges);
- sbProperties.append(" " + getXmlRootElementName(addType) + ":\n");
- sbProperties.append(" type: array\n items: \n");
- sbProperties.append(" $ref: \"#/definitions/"
- + getXmlRootElementName(addType) + "\"\n");
+ useName = getXmlRootElementName(addType);
+ sbProperties.append(" " + useName + ":\n");
+ if ( "relationship".equals(useName)) {
+ sbProperties.append(" type: object\n");
+ sbProperties.append(" $ref: \"#/definitions/relationship\"\n");
+ } else {
+ sbProperties.append(" type: array\n items: \n");
+ sbProperties.append(" $ref: \"#/definitions/"
+ + getXmlRootElementName(addType) + "\"\n");
+ }
if (StringUtils.isNotEmpty(elementDescription)) {
sbProperties
.append(" description: " + elementDescription + "\n");
@@ -403,6 +444,7 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
return null;
}
boolean processingInventoryDef = false;
+ String dict = null;
if (xmlRootElementName.equals("inventory")) {
// inventory properties for each oxm to be concatenated
processingInventoryDef = true;
@@ -412,7 +454,10 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
definitionsLocalSb.append(" " + xmlRootElementName + ":\n");
definitionsLocalSb.append(" properties:\n");
}
-
+ } else if (xmlRootElementName.equals("relationship")) {
+ definitionsSb.append(" " + "relationship-dict" + ":\n");
+ definitionsLocalSb.append(" " + "relationship-dict" + ":\n");
+ dict = getDictionary(xmlRootElementName);
} else {
definitionsSb.append(" " + xmlRootElementName + ":\n");
definitionsLocalSb.append(" " + xmlRootElementName + ":\n");
@@ -539,6 +584,10 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
if (xmlRootElementName.equals("inventory")) {
// will add to javaTypeDefinitions at end
inventoryDefSb.append(definitionsLocalSb.toString());
+ } else if (xmlRootElementName.equals("relationship")) {
+ javaTypeDefinitions.put(xmlRootElementName, dict);
+ javaTypeDefinitions.put(xmlRootElementName + "-dict",
+ definitionsLocalSb.toString());
} else {
javaTypeDefinitions.put(xmlRootElementName, definitionsLocalSb.toString());
}
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/YAMLfromOXM.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/YAMLfromOXM.java
index 45e2ea3..ee5fa36 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/YAMLfromOXM.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/YAMLfromOXM.java
@@ -319,7 +319,7 @@ public class YAMLfromOXM extends OxmFileProcessor {
+ appliedPaths.containsKey(path));
appliedPaths.put(path, xmlRootElementName);
}
-
+
Vector<String> addTypeV = null;
for (int i = 0; i < xmlElementNodes.getLength(); ++i) {
XSDElement xmlElementElement = new XSDElement((Element) xmlElementNodes.item(i));
@@ -367,6 +367,7 @@ public class YAMLfromOXM extends OxmFileProcessor {
StringBuffer newPathParams = new StringBuffer(
(pathParams == null ? "" : pathParams.toString()) + sbParameters.toString());
+ String useName;
for (int k = 0; addTypeV != null && k < addTypeV.size(); ++k) {
String addType = addTypeV.elementAt(k);
namespaceFilter.add(getXmlRootElementName(addType));
@@ -389,9 +390,18 @@ public class YAMLfromOXM extends OxmFileProcessor {
} else if (getItemName == null) {
++propertyCnt;
sbProperties.append(" " + getXmlRootElementName(addType) + ":\n");
- sbProperties.append(" type: array\n items:\n");
- sbProperties.append(" $ref: \"#/definitions/"
+ if ( "RelationshipList".equals(addType)) {
+ sbProperties.append(" type: object\n");
+ sbProperties.append(" $ref: \"#/definitions/"
+ + itemName + "\"\n");
+ } else {
+ if ( "relationship".equals(itemName) ) {
+ System.out.println(v + "-relationship added as array for getItemName null");
+ }
+ sbProperties.append(" type: array\n items:\n");
+ sbProperties.append(" $ref: \"#/definitions/"
+ (itemName == "" ? "inventory-item-data" : itemName) + "\"\n");
+ }
if (StringUtils.isNotEmpty(elementDescription)) {
sbProperties
.append(" description: " + elementDescription + "\n");
@@ -408,13 +418,19 @@ public class YAMLfromOXM extends OxmFileProcessor {
processJavaTypeElementSwagger(addType, getJavaTypeElementSwagger(addType),
pathSb, definitionsSb, path, tag == null ? useTag : tag, useOpId, null,
newPathParams, validEdges);
- sbProperties.append(" " + getXmlRootElementName(addType) + ":\n");
- sbProperties.append(" type: array\n items: \n");
- sbProperties.append(" $ref: \"#/definitions/"
- + getXmlRootElementName(addType) + "\"\n");
- if (StringUtils.isNotEmpty(elementDescription)) {
- sbProperties
- .append(" description: " + elementDescription + "\n");
+ useName = getXmlRootElementName(addType);
+ sbProperties.append(" " + useName + ":\n");
+ if ( "relationship".equals(useName)) {
+ sbProperties.append(" type: object\n");
+ sbProperties.append(" $ref: \"#/definitions/relationship\"\n");
+ } else {
+ sbProperties.append(" type: array\n items: \n");
+ sbProperties.append(" $ref: \"#/definitions/"
+ + getXmlRootElementName(addType) + "\"\n");
+ if (StringUtils.isNotEmpty(elementDescription)) {
+ sbProperties
+ .append(" description: " + elementDescription + "\n");
+ }
}
} else {