Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Issue #18716 Get JSON-Schema for only isRest partent and recursive ch…

…ild 's.
  • Loading branch information...
commit a79c585a7521460a9a0cc345c54deed7e9e4407b 1 parent f831f5d
authored April 11, 2013
38  lib/orm/source/xt/javascript/discovery.sql
@@ -114,14 +114,13 @@ select xt.install_js('XT','Discovery','xtuple', $$
114 114
       }
115 115
     }
116 116
 
117  
-    /* Schema section.
118  
-    discovery.schemas = XT.Discovery.getORMSchemas();
  117
+    /* Schema section. */
  118
+    discovery.schemas = XT.Discovery.getORMSchemas(orms);
119 119
 
120 120
     if (!discovery.schemas) {
121 121
       return false;
122 122
     }
123 123
 
124  
-    */
125 124
 
126 125
     /* Resources section. */
127 126
 
@@ -166,7 +165,7 @@ select xt.install_js('XT','Discovery','xtuple', $$
166 165
   XT.Discovery.getIsRestORMs = function() {
167 166
 
168 167
     /* TODO - Do we need to include "XM" in the propName? */
169  
-    var sql = "select orm_type from xt.orm where orm_rest group by orm_namespace, orm_type order by orm_namespace, orm_type",
  168
+    var sql = "select orm_namespace, orm_type from xt.orm where orm_rest group by orm_namespace, orm_type order by orm_namespace, orm_type",
170 169
         orms = plv8.execute(sql);
171 170
 
172 171
     if (!orms.length) {
@@ -179,10 +178,8 @@ select xt.install_js('XT','Discovery','xtuple', $$
179 178
   /*
180 179
    * Helper function to get a JSON-Schema for all ORM Models.
181 180
    */
182  
-  XT.Discovery.getORMSchemas = function() {
183  
-    var sql = "select orm_namespace, orm_type from xt.orm group by orm_namespace, orm_type order by orm_namespace, orm_type",
184  
-        orms = plv8.execute(sql),
185  
-        schema = {};
  181
+  XT.Discovery.getORMSchemas = function(orms) {
  182
+    var schema = {};
186 183
 
187 184
     if (!orms.length) {
188 185
       return false;
@@ -192,7 +189,32 @@ select xt.install_js('XT','Discovery','xtuple', $$
192 189
     for (var i = 0; i < orms.length; i++) {
193 190
       /* TODO - Do we need to include "XM" in the propName? */
194 191
       var propName = orms[i].orm_type;
  192
+
  193
+      /* Get parent ORM */
195 194
       schema[propName] = XT.Schema.getProperties({"nameSpace": orms[i].orm_namespace, "type": orms[i].orm_type});
  195
+
  196
+      if (!schema[propName] || !schema[propName].properties) {
  197
+        return false;
  198
+      }
  199
+
  200
+      /* Drill down through schema and get all $ref schemas. */
  201
+      for (var prop in schema[propName].properties) {
  202
+        var childProp = schema[propName].properties[prop];
  203
+
  204
+        if (childProp) {
  205
+          if (childProp.items && childProp.items["$ref"]){
  206
+            var childOrm = childProp.items["$ref"];
  207
+          } else if (childProp["$ref"]){
  208
+            var childOrm = childProp["$ref"];
  209
+          }
  210
+
  211
+          /* Only get this child schema if we don't already have it. */
  212
+          if (childOrm && !schema[childOrm]) {
  213
+            /* Recusing into children. */
  214
+            schema = XT.extend(schema, XT.Discovery.getORMSchemas([{ "orm_namespace": "XM", "orm_type": childOrm }]));
  215
+          }
  216
+        }
  217
+      }
196 218
     }
197 219
 
198 220
     return schema;

0 notes on commit a79c585

Please sign in to comment.
Something went wrong with that request. Please try again.