import java.util.Map;
import java.util.Set;
+import org.apache.commons.lang3.BooleanUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
if (node instanceof LeafSchemaNode) {
property = processLeafNode((LeafSchemaNode) node);
} else if (node instanceof ListSchemaNode) {
- property = processListSchemaNode((ListSchemaNode) node, moduleName, models);
+ property = processListSchemaNode((ListSchemaNode) node, moduleName, models, isConfig);
} else if (node instanceof LeafListSchemaNode) {
property = processLeafListNode((LeafListSchemaNode) node);
*
* @param listNode
* @param moduleName
+ * @param isConfig
* @return
* @throws JSONException
* @throws IOException
*/
private JSONObject processListSchemaNode(ListSchemaNode listNode, String moduleName,
- JSONObject models) throws JSONException, IOException {
+ JSONObject models, Boolean isConfig) throws JSONException, IOException {
Set<DataSchemaNode> listChildren = listNode.getChildNodes();
- String fileName = listNode.getQName().getLocalName();
+ String fileName = (BooleanUtils.isNotFalse(isConfig)?OperationBuilder.CONFIG:OperationBuilder.OPERATIONAL) +
+ listNode.getQName().getLocalName();
JSONObject childSchemaProperties = processChildren(listChildren, moduleName, models);
JSONObject childSchema = getSchemaTemplate();
private void processUnionType(UnionTypeDefinition unionType, JSONObject property)
throws JSONException {
- List<TypeDefinition<?>> unionTypes = unionType.getTypes();
- JSONArray unionArray = new JSONArray();
- for (TypeDefinition<?> typeDef : unionTypes) {
- unionArray.put(YANG_TYPE_TO_JSON_TYPE_MAPPING.get(typeDef.getClass()));
+ StringBuilder type = new StringBuilder();
+ for (TypeDefinition<?> typeDef : unionType.getTypes() ) {
+ if( type.length() > 0 ){
+ type.append( " or " );
+ }
+ type.append(YANG_TYPE_TO_JSON_TYPE_MAPPING.get(typeDef.getClass()));
}
- property.put(TYPE_KEY, unionArray);
+
+ property.put(TYPE_KEY, type );
}
/**
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
}
}
+ @Test
+ public void testEdgeCases() throws Exception {
+ Preconditions.checkArgument(helper.getModules() != null, "No modules found");
+
+ for (Entry<File, Module> m : helper.getModules().entrySet()) {
+ if (m.getKey().getAbsolutePath().endsWith("toaster.yang")) {
+ ApiDeclaration doc = generator.getSwaggerDocSpec(m.getValue(),
+ "http://localhost:8080/restconf", "");
+ Assert.assertNotNull(doc);
+
+ //testing bugs.opendaylight.org bug 1290. UnionType model type.
+ String jsonString = doc.getModels().toString();
+ assertTrue(
+ jsonString.contains( "testUnion\":{\"type\":\"integer or string\",\"required\":false}" ) );
+ }
+ }
+ }
+
private void validateToaster(ApiDeclaration doc) throws Exception {
Set<String> expectedUrls = new TreeSet<>(Arrays.asList(new String[] {
"/config/toaster2:toaster/", "/operational/toaster2:toaster/",
expectedConfigMethods.removeAll(actualConfigMethods);
fail("Missing expected method on config API: " + expectedConfigMethods);
}
+
// TODO: we should really do some more validation of the
// documentation...
/**