{"action":"created","issue":{"url":"https://api.github.com/repos/Textalk/angular-schema-form/issues/69","labels_url":"https://api.github.com/repos/Textalk/angular-schema-form/issues/69/labels{/name}","comments_url":"https://api.github.com/repos/Textalk/angular-schema-form/issues/69/comments","events_url":"https://api.github.com/repos/Textalk/angular-schema-form/issues/69/events","html_url":"https://github.com/Textalk/angular-schema-form/issues/69","id":40661370,"number":69,"title":"Does this support $ref?","user":{"login":"dkengaroo","id":5048295,"avatar_url":"https://avatars.githubusercontent.com/u/5048295?v=3","gravatar_id":"","url":"https://api.github.com/users/dkengaroo","html_url":"https://github.com/dkengaroo","followers_url":"https://api.github.com/users/dkengaroo/followers","following_url":"https://api.github.com/users/dkengaroo/following{/other_user}","gists_url":"https://api.github.com/users/dkengaroo/gists{/gist_id}","starred_url":"https://api.github.com/users/dkengaroo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkengaroo/subscriptions","organizations_url":"https://api.github.com/users/dkengaroo/orgs","repos_url":"https://api.github.com/users/dkengaroo/repos","events_url":"https://api.github.com/users/dkengaroo/events{/privacy}","received_events_url":"https://api.github.com/users/dkengaroo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Textalk/angular-schema-form/labels/enhancement","name":"enhancement","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":48,"created_at":"2014-08-20T03:58:28Z","updated_at":"2016-01-29T08:20:23Z","closed_at":null,"body":"Hiya,\r\n\r\nI have a schema with \r\n\"$schema\": \"http://json-schema.org/draft-04/schema#\",\r\n        \"title\": \"title\",\r\n        \"type\": \"object\",\r\n        \"item\": {\r\n                \"type\": \"object\",\r\n                \"properties\": {\r\n                    \"attribute\": {\r\n                        \"$ref\": \"#/definitions/schema2\"\r\n                    }\r\n                },\r\n                \"required\": [\r\n                    \"attribute_info\"\r\n                ]\r\n            } \r\n.... \r\nsomething like that.\r\n\r\nI kept the form simple with the \"*\" and a submit button. However the form doesn't render properly where the $ref is.\r\n\r\nam I doing something wrong?"},"comment":{"url":"https://api.github.com/repos/Textalk/angular-schema-form/issues/comments/176635926","html_url":"https://github.com/Textalk/angular-schema-form/issues/69#issuecomment-176635926","issue_url":"https://api.github.com/repos/Textalk/angular-schema-form/issues/69","id":176635926,"user":{"login":"AndreNel7","id":2454714,"avatar_url":"https://avatars.githubusercontent.com/u/2454714?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreNel7","html_url":"https://github.com/AndreNel7","followers_url":"https://api.github.com/users/AndreNel7/followers","following_url":"https://api.github.com/users/AndreNel7/following{/other_user}","gists_url":"https://api.github.com/users/AndreNel7/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreNel7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreNel7/subscriptions","organizations_url":"https://api.github.com/users/AndreNel7/orgs","repos_url":"https://api.github.com/users/AndreNel7/repos","events_url":"https://api.github.com/users/AndreNel7/events{/privacy}","received_events_url":"https://api.github.com/users/AndreNel7/received_events","type":"User","site_admin":false},"created_at":"2016-01-29T08:20:23Z","updated_at":"2016-01-29T08:20:23Z","body":"improved answer:\r\n\r\n< !DOCTYPE html>\r\n< html>\r\n< head>\r\n< title>Custom validators, async validators etc< /title>\r\n< link rel=\"stylesheet\" href=\"./dist/bootstrap/3.3.4/css/bootstrap.min.css\">\r\n< link rel=\"stylesheet\" href=\"./dist/bootstrap/3.3.4/css/bootstrap-theme.min.css\">\r\n< /head>\r\n< body ng-app=\"test\" class=\"container\" ng-controller=\"TestCtrl\">\r\n\r\n< h3>ASF (Angular Schema Form)< /h3>\r\n< form name=\"theForm\">\r\n< div sf-schema=\"schema\" sf-form=\"form\" sf-model=\"model\">< /div>\r\n< div>\r\nThe form is < em ng-show=\"theForm.$pristine\">pristine< /em>< em ng-show=\"theForm.$dirty\">dirty< /em>\r\nand < em ng-show=\"theForm.$valid\">valid< /em>< em ng-show=\"!theForm.$valid\">invalid< /em>.\r\n< /div>\r\n< div>{{prettyModel}}< /div>\r\n< /form>\r\n\r\n< script type=\"text/javascript\" src=\"./bower_components/tv4/tv4.js\">< /script> < !-- Tiny Validator for Schema v4 - https://github.com/geraintluff/tv4 -->\r\n< script type=\"text/javascript\" src=\"./bower_components/angular/angular.min.js\">< /script>\r\n< script type=\"text/javascript\" src=\"./bower_components/angular-sanitize/angular-sanitize.min.js\">\r\n< /script>\r\n\r\n< script type=\"text/javascript\" src=\"./bower_components/objectpath/lib/ObjectPath.js\">< /script>\r\n\r\n< script type=\"text/javascript\" src=\"./dist/schema-form.js\">< /script>\r\n< script type=\"text/javascript\" src=\"./dist/bootstrap-decorator.min.js\">< /script>\r\n\r\n< script type=\"text/javascript\" src=\"./json-refs-standalone.js\">< /script> < !-- https://github.com/whitlockjc/json-refs -->\r\n\r\n< script type=\"text/javascript\" src=\"./jquery-2.1.3.js\">< /script> < !-- for json extend / merge -->\r\n< script type=\"text/javascript\" src=\"./jQuery.extendext.min.js\">< /script> < !-- for json extend / merge - with array extend (instead of array overwrite) - https://github.com/mistic100/jQuery.extendext -->\r\n\r\n< script>\r\n```javascript\r\n    function getObject(in_obj, in_prop, in_val, in_path) // http://stackoverflow.com/questions/15523514/find-by-key-deep-in-nested-json-object // http://jsfiddle.net/FM3qu/7/\r\n    {\r\n        if (!in_path) in_path = '';\r\n        var result = null;\r\n        if (in_obj instanceof Array)\r\n        {\r\n            for (var i = 0; i < in_obj.length; i++)\r\n            {\r\n                result = getObject(in_obj[i], in_prop, in_val);\r\n                if (result)\r\n                {\r\n                    break;\r\n                }\r\n            }\r\n        }\r\n        else\r\n        {\r\n            for (var prop in in_obj)\r\n            {\r\n                //console.log(prop + ': ' + in_obj[prop] + ' -> ' + in_prop);\r\n                if (prop == in_prop)\r\n                {\r\n                    //console.log(prop);\r\n                    if (in_val)\r\n                    {\r\n                        if (in_obj[prop] == in_val)\r\n                        {\r\n                            return in_obj;\r\n                        }\r\n                    }\r\n                    else\r\n                    {\r\n                        return in_path += '.' + prop; // return path rather than object\r\n                        //console.log(in_path);\r\n                        //return in_obj;\r\n                    }\r\n                }\r\n                if (in_obj[prop] instanceof Object || in_obj[prop] instanceof Array)\r\n                {\r\n                    //console.log(in_path + '.' + prop);\r\n                    result = getObject(in_obj[prop], in_prop, in_val, in_path + '.' + prop);\r\n                    if (result)\r\n                    {\r\n                        break;\r\n                    }\r\n                }\r\n            }\r\n        }\r\n        return result;\r\n    }\r\n\r\n    var defRefJsonSchema =\r\n    {\r\n        \"$schema\": \"http://json-schema.org/draft-04/schema#\",\r\n\r\n        \"definitions\": {\r\n            \"address\": {\r\n                \"type\": \"object\",\r\n                \"properties\": {\r\n                    \"street_address\": { \"type\": \"string\" },\r\n                    \"city\": { \"type\": \"string\" },\r\n                    \"state\": { \"type\": \"string\" }\r\n                },\r\n                \"required\": [\"street_address\", \"city\", \"state\"]\r\n            },\r\n            \"country\": {\r\n                \"type\": \"object\",\r\n                \"properties\": {\r\n                    \"country\": { \"type\": \"string\" },\r\n                    \"country-dial-code\": { \"type\": \"integer\" },\r\n                    \"country-short\": { \"type\": \"string\" }\r\n                },\r\n                \"required\": [\"country\", \"country-dial-code\", \"country-short\"]\r\n            }\r\n        },\r\n        \"type\": \"object\",\r\n        \"properties\": {\r\n            \"billing_address\": { \"allOf\": [{ \"type\": \"object\", \"properties\": { \"billing_id\": { \"type\": \"number\" } } }, { \"$ref\": \"#/definitions/address\" }, { \"$ref\": \"#/definitions/country\" }] },\r\n        \"shipping_address\": { \"allOf\": [ {\"type\": \"object\", \"properties\": { \"shipping_id\": { \"type\": \"number\" } } }, { \"$ref\": \"#/definitions/address\" } ] },\r\n        }\r\n    };\r\n    // ___________________\r\n    //| \"$ref\" workaround |\r\n    //|___________________|\r\n    JsonRefs\r\n    .resolveRefs(defRefJsonSchema, {\r\n        \"filter\": ['relative', 'local']\r\n    })\r\n    .then(function (res) // https://github.com/whitlockjc/json-     refs/blob/master/docs/API.md#module_JsonRefs.resolveRefs\r\n    {\r\n        var sjson = JSON.stringify(res.resolved);\r\n\r\n        // ____________________\r\n        //| \"allOf\" workaround |\r\n        //|____________________|\r\n        while (sjson.indexOf('allOf') !== -1) // loop until all 'allOf' have been replaced\r\n        {\r\n            // Replace allOf with combined JSON object\r\n            //console.log('---------------------allOf-------------------------------');\r\n            //console.log(res.resolved);\r\n            //var aAllOf = getObject(res.resolved, 'allOf').allOf;\r\n            var aAllOfPath = getObject(res.resolved, 'allOf'); // hacked getObject() to return path to sub-object (from inside the main-object) rather than the sub-object itself\r\n            //console.log(aAllOfPath);\r\n            var aAllOf = eval('res.resolved' + aAllOfPath); // get sub-object from path in main-object\r\n            //console.log(aAllOf);\r\n\r\n            //var result = $.extend(true, {}, aAllOf[0], aAllOf[1]); // resultant object from combining allOf-path's objects\r\n            var result = {}; // resultant object from combining allOf-path's objects\r\n            for (var i = 0, length = aAllOf.length; i < length; i++)\r\n            {\r\n                //console.log(aAllOf[i]);\r\n                //$.extend(true, result, aAllOf[i]);\r\n                $.extendext(true, 'extend', result, aAllOf[i]); // https://github.com/mistic100/jQuery.extendext\r\n            }\r\n            console.log(JSON.stringify(result));\r\n\r\n            eval('delete res.resolved' + aAllOfPath); // delete allOf\r\n            //console.log('res.resolved' + aAllOfPath.split('.allOf')[0]);\r\n            eval('res.resolved' + aAllOfPath.split('.allOf')[0] + ' = ' + JSON.stringify(result)); // put combined obj in place of deleted allOf\r\n            //console.log(res.resolved);\r\n            sjson = JSON.stringify(res.resolved);\r\n        }\r\n        //console.log(sjson)\r\n\r\n        buildASF(res.resolved);\r\n    }, function (err)\r\n    {\r\n        console.log(err.stack);\r\n    });\r\n\r\n    function buildASF(jsonSchema)\r\n    {\r\n        angular.module('test', ['schemaForm']).controller('TestCtrl', function ($scope, $q, $timeout)\r\n        {\r\n            $scope.schema = jsonSchema;\r\n\r\n            $scope.form = [\r\n                \"*\",\r\n                {\r\n                    \"type\": \"submit\",\r\n                    \"title\": \"OK\"\r\n                }\r\n            ];\r\n\r\n            $scope.model =\r\n            {\r\n                \"billing_address\": { \"billing_id\": 111, \"street_address\": \"123 Home\", \"city\":\"centurion\", \"state\":\"Gauteng\", \"country\":\"South Africa\", \"country-short\":\"ZA\", \"country-dial-code\":27 },\r\n                \"shipping_address\": { \"shipping_id\": 222, \"street_address\": \"7 Ship\" }\r\n            };\r\n\r\n            $scope.$watch('model', function (value)\r\n            {\r\n                if (value)\r\n                {\r\n                    $scope.prettyModel = JSON.stringify(value, undefined, 2);\r\n                }\r\n            }, true);\r\n        });\r\n    }\r\n```\r\n< /script>\r\n\r\n< /body>\r\n< /html>"}}