{"action":"created","comment":{"url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/pulls/comments/74238488","id":74238488,"diff_hunk":"@@ -2,97 +2,119 @@\n /**\n  * AWS APIG Model definition.\n  */\n-module.exports = function(S) {\n+module.exports = function (S) {\n \n-  const _          = require('lodash'),\n-        BbPromise  = require('bluebird'),\n-        yaml       = require('js-yaml'),\n-        path       = require('path'),\n-        SError     = require(S.getServerlessPath('Error'));\n+  const _         = require('lodash'),\n+        BbPromise = require('bluebird'),\n+        yaml      = require('js-yaml'),\n+        path      = require('path'),\n+        walkSync  = require('walk-sync'),\n+        SError    = require(S.getServerlessPath('Error'));\n \n   class Models extends S.classes.Serializer {\n \n-    constructor(data, filePath) {\n+    constructor (data, filePath) {\n       super();\n \n       this._class = 'Models';\n+      this._walkSyncGlobs = {\n+        globs  : ['**/s-models.yaml', '**/s-models.json'],\n+        ignore : ['**/node_modules']\n+\n+      };\n       this._filePath = filePath;\n \n       if (data) this.fromObject(data);\n     }\n \n-    load() {\n+    load () {\n       return this.deserialize(this);\n     }\n \n-    save() {\n+    save () {\n       return this.serialize(this);\n     }\n \n-    fromObject(data) {\n+    fromObject (data) {\n       return _.assign(this, data);\n     }\n-\n-    toObject() {\n+    \n+    toObject () {\n       return S.utils.exportObject(_.cloneDeep(this));\n     }\n \n-    getFilePath() {\n+    getFilePath () {\n       return this._filePath;\n     }\n \n-    getRootPath() {\n+    getWalkSyncGlobs () {\n+      return this._walkSyncGlobs;\n+    }\n+\n+    getRootPath () {\n       let args = _.toArray(arguments);\n       args.unshift(path.dirname(this.getFilePath()));\n       return path.join.apply(path, args);\n     }\n \n-    deserializeModels(models) {\n+    walkSyncDirs () {\n+      return walkSync(this.getRootPath(), this.getWalkSyncGlobs());\n+    }\n+\n+    deserializeModels (models) {\n       let _this = this;\n \n       if (!models.getFilePath()) return BbPromise.resolve();\n \n       return BbPromise.try(function () {\n \n-          // Validate: Check project path is set\n-          if (!S.hasProject()) throw new SError('Models could not be loaded because no project path has been set on Serverless instance');\n+        // Validate: Check project path is set\n+        if (!S.hasProject()) throw new SError('Models could not be loaded because no project path has been set on Serverless instance');\n \n-          // Set Data\n-          let filePath = models.getFilePath();\n-          if (_.endsWith(filePath, '.yaml')) {\n-            models.fromObject(yaml.safeLoad(S.utils.readFileSync(filePath)));\n-          } else {\n-            models.fromObject(S.utils.readFileSync(filePath));\n-          }\n-        })\n+        // Set Data\n+        let filePath = models.getFilePath();\n+        if (_.endsWith(filePath, '.yaml')) {\n+          models.fromObject(yaml.safeLoad(S.utils.readFileSync(filePath)));\n+        } else {\n+          models.fromObject(S.utils.readFileSync(filePath));\n+        }\n+      })\n         .then(function () {\n           return models;\n         });\n     }\n \n-    serializeModels() {\n-      \n+    serializeModels () {\n+\n     }\n \n-    static loadFromProject(project) {\n-      return BbPromise.mapSeries([ 's-models.json', 's-models.yaml' ], (filename) => {\n+    static loadFromProject (project) {\n+      let models = new S.classes.Models({}, '');\n+\n+      return BbPromise.mapSeries(models.walkSyncDirs(), (filename) => {\n         // Load Templates\n         let modelsFilePath = project.getRootPath(filename);\n \n         if (S.utils.fileExistsSync(modelsFilePath)) {\n           let models = new S.classes.Models({}, modelsFilePath);\n+          \n           return models.load();\n         }\n         return null;\n       })\n-      .filter((models) => { return models !== null; })\n-      .then(function (models) {\n-        if (models.length > 0) {\n-          return BbPromise.resolve(models[0]);\n-        }\n-\n-        return BbPromise.resolve({});\n-      });\n+        .filter((models) => {\n+          return models !== null;\n+        })\n+        .reduce((result, model) => {\n+          _.forOwn(model, (value, modelName) => {\n+            if (!_.startsWith(modelName, '_')) {\n+              if (_.has(result, modelName)) throw new SError('Detected duplicate models names for model: ' + modelName + ' .Please use different model names');\n+              result[modelName] = value;\n+            }\n+          });\n+\n+          return result;","path":"lib/Models.js","position":null,"original_position":152,"commit_id":"788919a211289e13fd6a9bd1ec315504a08f9a90","original_commit_id":"65546d053fadffe0ecb081589bf16e2eb63dabf2","user":{"login":"nickchisiu","id":8492343,"avatar_url":"https://avatars.githubusercontent.com/u/8492343?v=3","gravatar_id":"","url":"https://api.github.com/users/nickchisiu","html_url":"https://github.com/nickchisiu","followers_url":"https://api.github.com/users/nickchisiu/followers","following_url":"https://api.github.com/users/nickchisiu/following{/other_user}","gists_url":"https://api.github.com/users/nickchisiu/gists{/gist_id}","starred_url":"https://api.github.com/users/nickchisiu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nickchisiu/subscriptions","organizations_url":"https://api.github.com/users/nickchisiu/orgs","repos_url":"https://api.github.com/users/nickchisiu/repos","events_url":"https://api.github.com/users/nickchisiu/events{/privacy}","received_events_url":"https://api.github.com/users/nickchisiu/received_events","type":"User","site_admin":false},"body":"done, sorry for that .","created_at":"2016-08-10T13:00:23Z","updated_at":"2016-08-10T13:00:23Z","html_url":"https://github.com/HyperBrain/serverless-models-plugin/pull/10#discussion_r74238488","pull_request_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/pulls/comments/74238488"},"html":{"href":"https://github.com/HyperBrain/serverless-models-plugin/pull/10#discussion_r74238488"},"pull_request":{"href":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/pulls/10","id":80775689,"html_url":"https://github.com/HyperBrain/serverless-models-plugin/pull/10","diff_url":"https://github.com/HyperBrain/serverless-models-plugin/pull/10.diff","patch_url":"https://github.com/HyperBrain/serverless-models-plugin/pull/10.patch","issue_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/issues/10","number":10,"state":"open","locked":false,"title":"V1.1.0","user":{"login":"nickchisiu","id":8492343,"avatar_url":"https://avatars.githubusercontent.com/u/8492343?v=3","gravatar_id":"","url":"https://api.github.com/users/nickchisiu","html_url":"https://github.com/nickchisiu","followers_url":"https://api.github.com/users/nickchisiu/followers","following_url":"https://api.github.com/users/nickchisiu/following{/other_user}","gists_url":"https://api.github.com/users/nickchisiu/gists{/gist_id}","starred_url":"https://api.github.com/users/nickchisiu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nickchisiu/subscriptions","organizations_url":"https://api.github.com/users/nickchisiu/orgs","repos_url":"https://api.github.com/users/nickchisiu/repos","events_url":"https://api.github.com/users/nickchisiu/events{/privacy}","received_events_url":"https://api.github.com/users/nickchisiu/received_events","type":"User","site_admin":false},"body":"I tested #9 feature by having multiple s-models files in different places and it gets deployed successfully to AWS API Gateway","created_at":"2016-08-10T11:11:20Z","updated_at":"2016-08-10T13:00:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7b2409474c4a69849665298005e8b9af4b0fbb41","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/pulls/10/commits","review_comments_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/pulls/10/comments","review_comment_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/issues/10/comments","statuses_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/statuses/788919a211289e13fd6a9bd1ec315504a08f9a90","head":{"label":"nickchisiu:v1.1.0","ref":"v1.1.0","sha":"788919a211289e13fd6a9bd1ec315504a08f9a90","user":{"login":"nickchisiu","id":8492343,"avatar_url":"https://avatars.githubusercontent.com/u/8492343?v=3","gravatar_id":"","url":"https://api.github.com/users/nickchisiu","html_url":"https://github.com/nickchisiu","followers_url":"https://api.github.com/users/nickchisiu/followers","following_url":"https://api.github.com/users/nickchisiu/following{/other_user}","gists_url":"https://api.github.com/users/nickchisiu/gists{/gist_id}","starred_url":"https://api.github.com/users/nickchisiu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nickchisiu/subscriptions","organizations_url":"https://api.github.com/users/nickchisiu/orgs","repos_url":"https://api.github.com/users/nickchisiu/repos","events_url":"https://api.github.com/users/nickchisiu/events{/privacy}","received_events_url":"https://api.github.com/users/nickchisiu/received_events","type":"User","site_admin":false},"repo":{"id":64767335,"name":"serverless-models-plugin","full_name":"nickchisiu/serverless-models-plugin","owner":{"login":"nickchisiu","id":8492343,"avatar_url":"https://avatars.githubusercontent.com/u/8492343?v=3","gravatar_id":"","url":"https://api.github.com/users/nickchisiu","html_url":"https://github.com/nickchisiu","followers_url":"https://api.github.com/users/nickchisiu/followers","following_url":"https://api.github.com/users/nickchisiu/following{/other_user}","gists_url":"https://api.github.com/users/nickchisiu/gists{/gist_id}","starred_url":"https://api.github.com/users/nickchisiu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nickchisiu/subscriptions","organizations_url":"https://api.github.com/users/nickchisiu/orgs","repos_url":"https://api.github.com/users/nickchisiu/repos","events_url":"https://api.github.com/users/nickchisiu/events{/privacy}","received_events_url":"https://api.github.com/users/nickchisiu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nickchisiu/serverless-models-plugin","description":"Model support for Serverless 0.5.x","fork":true,"url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin","forks_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/forks","keys_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/teams","hooks_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/hooks","issue_events_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/events","assignees_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/tags","blobs_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/languages","stargazers_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/stargazers","contributors_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/contributors","subscribers_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/subscribers","subscription_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/subscription","commits_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/merges","archive_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/downloads","issues_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/labels{/name}","releases_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/releases{/id}","deployments_url":"https://api.github.com/repos/nickchisiu/serverless-models-plugin/deployments","created_at":"2016-08-02T15:10:25Z","updated_at":"2016-08-02T15:10:36Z","pushed_at":"2016-08-10T12:59:27Z","git_url":"git://github.com/nickchisiu/serverless-models-plugin.git","ssh_url":"git@github.com:nickchisiu/serverless-models-plugin.git","clone_url":"https://github.com/nickchisiu/serverless-models-plugin.git","svn_url":"https://github.com/nickchisiu/serverless-models-plugin","homepage":"","size":24,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"HyperBrain:master","ref":"master","sha":"00bd1d71333242377b6abf8bef9131e6434ccaa3","user":{"login":"HyperBrain","id":5524702,"avatar_url":"https://avatars.githubusercontent.com/u/5524702?v=3","gravatar_id":"","url":"https://api.github.com/users/HyperBrain","html_url":"https://github.com/HyperBrain","followers_url":"https://api.github.com/users/HyperBrain/followers","following_url":"https://api.github.com/users/HyperBrain/following{/other_user}","gists_url":"https://api.github.com/users/HyperBrain/gists{/gist_id}","starred_url":"https://api.github.com/users/HyperBrain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HyperBrain/subscriptions","organizations_url":"https://api.github.com/users/HyperBrain/orgs","repos_url":"https://api.github.com/users/HyperBrain/repos","events_url":"https://api.github.com/users/HyperBrain/events{/privacy}","received_events_url":"https://api.github.com/users/HyperBrain/received_events","type":"User","site_admin":false},"repo":{"id":56439416,"name":"serverless-models-plugin","full_name":"HyperBrain/serverless-models-plugin","owner":{"login":"HyperBrain","id":5524702,"avatar_url":"https://avatars.githubusercontent.com/u/5524702?v=3","gravatar_id":"","url":"https://api.github.com/users/HyperBrain","html_url":"https://github.com/HyperBrain","followers_url":"https://api.github.com/users/HyperBrain/followers","following_url":"https://api.github.com/users/HyperBrain/following{/other_user}","gists_url":"https://api.github.com/users/HyperBrain/gists{/gist_id}","starred_url":"https://api.github.com/users/HyperBrain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HyperBrain/subscriptions","organizations_url":"https://api.github.com/users/HyperBrain/orgs","repos_url":"https://api.github.com/users/HyperBrain/repos","events_url":"https://api.github.com/users/HyperBrain/events{/privacy}","received_events_url":"https://api.github.com/users/HyperBrain/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/HyperBrain/serverless-models-plugin","description":"Model support for Serverless 0.5.x","fork":false,"url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin","forks_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/forks","keys_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/teams","hooks_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/hooks","issue_events_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/events","assignees_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/tags","blobs_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/languages","stargazers_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/stargazers","contributors_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/contributors","subscribers_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/subscribers","subscription_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/subscription","commits_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/merges","archive_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/downloads","issues_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/labels{/name}","releases_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/releases{/id}","deployments_url":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/deployments","created_at":"2016-04-17T14:02:39Z","updated_at":"2016-08-02T15:10:23Z","pushed_at":"2016-08-10T12:59:27Z","git_url":"git://github.com/HyperBrain/serverless-models-plugin.git","ssh_url":"git@github.com:HyperBrain/serverless-models-plugin.git","clone_url":"https://github.com/HyperBrain/serverless-models-plugin.git","svn_url":"https://github.com/HyperBrain/serverless-models-plugin","homepage":"","size":24,"stargazers_count":17,"watchers_count":17,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":5,"forks":3,"open_issues":5,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/pulls/10"},"html":{"href":"https://github.com/HyperBrain/serverless-models-plugin/pull/10"},"issue":{"href":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/issues/10"},"comments":{"href":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/HyperBrain/serverless-models-plugin/statuses/788919a211289e13fd6a9bd1ec315504a08f9a90"}}}}
{"actor":{"display_login":"nickchisiu"}}