{"action":"created","comment":{"url":"https://api.github.com/repos/apiaryio/fury.js/pulls/comments/31923559","id":31923559,"diff_hunk":"@@ -0,0 +1,201 @@\n+/*\n+ * Renders refract elements into MSON.\n+ */\n+\n+/*\n+ * Indent a piece of multiline text by a number of spaces.\n+ * Setting `first` to `true` will also indent the first line.\n+ */\n+function indent(input, spaces, options={first: false}) {\n+   let pre = '';\n+   let lines = [];\n+\n+   for (let _ = 0; _ < spaces; _++) {\n+     pre += ' ';\n+   }\n+\n+   for (let line of input.split('\\n')) {\n+     // Only indent non-blank lines!\n+     lines.push(line ? pre + line : line);\n+   }\n+\n+   lines = lines.join('\\n').trim();\n+\n+   if (options.first) {\n+     lines = pre + lines;\n+   }\n+\n+   return lines;\n+ }\n+\n+/*\n+ * Get type information for an element, such as the element name, whether\n+ * it is required, etc. Returns an array of strings.\n+ */\n+function getTypeAttributes(element, attributes={}) {\n+  let typeAttributes = [];\n+\n+  if (element.element !== 'string' && element.element !== 'dataStructure') {\n+    typeAttributes.push(element.element);\n+  }\n+\n+  return typeAttributes.concat(attributes.typeAttributes || []);\n+}\n+\n+function handleContent(element, spaces, marker) {\n+  let renderedContent = '';\n+  let objectLike = null;\n+\n+  if (element.content === undefined) {\n+    return [renderedContent, objectLike];\n+  }\n+\n+  for (let item of element.content) {\n+    // Note: the `initialIndent` option above works because we specifically\n+    //       do *not* pass it down the rabbit hole here.\n+    if (item.element === 'member') {\n+      // This is an object type or something similar.\n+      objectLike = true;\n+      /* eslint-disable block-scoped-var */\n+      renderedContent += handle(item.key.content, item.value, {\n+        parent: element,\n+        spaces,\n+        marker,\n+        attributesElement: item\n+      });\n+      /* eslint-enable block-scoped-var */\n+    } else if (item.element === 'ref') {\n+      renderedContent += `${marker} Include ${item.content.href}\\n`;\n+    } else if (item.element === 'select') {\n+      // This is a `OneOf` mutually exclusive type. Currently not\n+      // supported as it needs some support upstream in Minim.\n+      console.warn('MSON select/option elements are not yet supported!');\n+    } else {\n+      // This is an array type or something similar.\n+      objectLike = false;\n+      /* eslint-disable block-scoped-var */\n+      renderedContent += handle(item.meta.title.toValue(), item, {\n+        parent: element,\n+        spaces,\n+        marker\n+      });\n+      /* eslint-enable block-scoped-var */\n+    }\n+  }\n+\n+  return [renderedContent, objectLike];\n+}\n+\n+/*\n+ * Handle the rendering of an element based on its element type. This function\n+ * will call itself recursively to handle child elements for objects and\n+ * arrays.\n+ */\n+function handle(name, element, {parent=null, spaces=4, marker='+',\n+                                initialMarker='+',\n+                                initialIndent=true,\n+                                attributesElement=element}) {\n+  const elementName = element.element;\n+  let str = initialMarker;\n+\n+  // Start with the item name if it has one.\n+  if (name) {\n+    str += ` ${name}`;\n+  }\n+\n+  // Next, comes the optional example value\n+  if (typeof element.content !== 'object') {","path":"src/adapters/mson.es6","position":107,"original_position":107,"commit_id":"dc51565eb443729ab74e3a88dde70c47dae3d8a5","original_commit_id":"dc51565eb443729ab74e3a88dde70c47dae3d8a5","user":{"login":"smizell","id":130959,"avatar_url":"https://avatars.githubusercontent.com/u/130959?v=3","gravatar_id":"","url":"https://api.github.com/users/smizell","html_url":"https://github.com/smizell","followers_url":"https://api.github.com/users/smizell/followers","following_url":"https://api.github.com/users/smizell/following{/other_user}","gists_url":"https://api.github.com/users/smizell/gists{/gist_id}","starred_url":"https://api.github.com/users/smizell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smizell/subscriptions","organizations_url":"https://api.github.com/users/smizell/orgs","repos_url":"https://api.github.com/users/smizell/repos","events_url":"https://api.github.com/users/smizell/events{/privacy}","received_events_url":"https://api.github.com/users/smizell/received_events","type":"User","site_admin":false},"body":"This would be nice to capture in an instance method in Minim, maybe. Introspecting the content seems like a useful thing for guessing the primitive element for the instance.","created_at":"2015-06-08T15:04:34Z","updated_at":"2015-06-08T15:04:34Z","html_url":"https://github.com/apiaryio/fury.js/pull/23#discussion_r31923559","pull_request_url":"https://api.github.com/repos/apiaryio/fury.js/pulls/23","_links":{"self":{"href":"https://api.github.com/repos/apiaryio/fury.js/pulls/comments/31923559"},"html":{"href":"https://github.com/apiaryio/fury.js/pull/23#discussion_r31923559"},"pull_request":{"href":"https://api.github.com/repos/apiaryio/fury.js/pulls/23"}}},"pull_request":{"url":"https://api.github.com/repos/apiaryio/fury.js/pulls/23","id":37070234,"html_url":"https://github.com/apiaryio/fury.js/pull/23","diff_url":"https://github.com/apiaryio/fury.js/pull/23.diff","patch_url":"https://github.com/apiaryio/fury.js/pull/23.patch","issue_url":"https://api.github.com/repos/apiaryio/fury.js/issues/23","number":23,"state":"open","locked":false,"title":"Add support for MSON serialization.","user":{"login":"danielgtaylor","id":106826,"avatar_url":"https://avatars.githubusercontent.com/u/106826?v=3","gravatar_id":"","url":"https://api.github.com/users/danielgtaylor","html_url":"https://github.com/danielgtaylor","followers_url":"https://api.github.com/users/danielgtaylor/followers","following_url":"https://api.github.com/users/danielgtaylor/following{/other_user}","gists_url":"https://api.github.com/users/danielgtaylor/gists{/gist_id}","starred_url":"https://api.github.com/users/danielgtaylor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielgtaylor/subscriptions","organizations_url":"https://api.github.com/users/danielgtaylor/orgs","repos_url":"https://api.github.com/users/danielgtaylor/repos","events_url":"https://api.github.com/users/danielgtaylor/events{/privacy}","received_events_url":"https://api.github.com/users/danielgtaylor/received_events","type":"User","site_admin":false},"body":"This PR adds support to serialize from refract element instances into MSON within an API Blueprint, and adds the feature to the API Blueprint serializer. Not everything is supported yet, but a significant portion of the spec is, including defaults, samples, multiline descriptions, inheritance, includes, and data structures. See the updated `sample.json`/`sample.apib` for an example. This is the same technology that was included in the reveal demo but has several added features.\r\n\r\nThe `extends` and `select` (One Of) elements aren't yet supported and depend on upstream implementation before they can be serialized here.\r\n\r\nNote that this is **not** implemented in a Swig template, or any template format. This is due to the recursive nature and indentation of the format. I tried several approaches and scrapped them before settling on this approach. I am worried about the maintainability of the codebase, so any suggestions are welcome.\r\n\r\ncc @zdne @smizell ","created_at":"2015-06-05T21:07:52Z","updated_at":"2015-06-08T15:04:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0f7b443906e897ba668b55f7037895e2488a58ea","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apiaryio/fury.js/pulls/23/commits","review_comments_url":"https://api.github.com/repos/apiaryio/fury.js/pulls/23/comments","review_comment_url":"https://api.github.com/repos/apiaryio/fury.js/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apiaryio/fury.js/issues/23/comments","statuses_url":"https://api.github.com/repos/apiaryio/fury.js/statuses/dc51565eb443729ab74e3a88dde70c47dae3d8a5","head":{"label":"apiaryio:daniel/mson","ref":"daniel/mson","sha":"dc51565eb443729ab74e3a88dde70c47dae3d8a5","user":{"login":"apiaryio","id":765943,"avatar_url":"https://avatars.githubusercontent.com/u/765943?v=3","gravatar_id":"","url":"https://api.github.com/users/apiaryio","html_url":"https://github.com/apiaryio","followers_url":"https://api.github.com/users/apiaryio/followers","following_url":"https://api.github.com/users/apiaryio/following{/other_user}","gists_url":"https://api.github.com/users/apiaryio/gists{/gist_id}","starred_url":"https://api.github.com/users/apiaryio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apiaryio/subscriptions","organizations_url":"https://api.github.com/users/apiaryio/orgs","repos_url":"https://api.github.com/users/apiaryio/repos","events_url":"https://api.github.com/users/apiaryio/events{/privacy}","received_events_url":"https://api.github.com/users/apiaryio/received_events","type":"Organization","site_admin":false},"repo":{"id":30531423,"name":"fury.js","full_name":"apiaryio/fury.js","owner":{"login":"apiaryio","id":765943,"avatar_url":"https://avatars.githubusercontent.com/u/765943?v=3","gravatar_id":"","url":"https://api.github.com/users/apiaryio","html_url":"https://github.com/apiaryio","followers_url":"https://api.github.com/users/apiaryio/followers","following_url":"https://api.github.com/users/apiaryio/following{/other_user}","gists_url":"https://api.github.com/users/apiaryio/gists{/gist_id}","starred_url":"https://api.github.com/users/apiaryio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apiaryio/subscriptions","organizations_url":"https://api.github.com/users/apiaryio/orgs","repos_url":"https://api.github.com/users/apiaryio/repos","events_url":"https://api.github.com/users/apiaryio/events{/privacy}","received_events_url":"https://api.github.com/users/apiaryio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apiaryio/fury.js","description":"API Description SDK","fork":false,"url":"https://api.github.com/repos/apiaryio/fury.js","forks_url":"https://api.github.com/repos/apiaryio/fury.js/forks","keys_url":"https://api.github.com/repos/apiaryio/fury.js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apiaryio/fury.js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apiaryio/fury.js/teams","hooks_url":"https://api.github.com/repos/apiaryio/fury.js/hooks","issue_events_url":"https://api.github.com/repos/apiaryio/fury.js/issues/events{/number}","events_url":"https://api.github.com/repos/apiaryio/fury.js/events","assignees_url":"https://api.github.com/repos/apiaryio/fury.js/assignees{/user}","branches_url":"https://api.github.com/repos/apiaryio/fury.js/branches{/branch}","tags_url":"https://api.github.com/repos/apiaryio/fury.js/tags","blobs_url":"https://api.github.com/repos/apiaryio/fury.js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apiaryio/fury.js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apiaryio/fury.js/git/refs{/sha}","trees_url":"https://api.github.com/repos/apiaryio/fury.js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apiaryio/fury.js/statuses/{sha}","languages_url":"https://api.github.com/repos/apiaryio/fury.js/languages","stargazers_url":"https://api.github.com/repos/apiaryio/fury.js/stargazers","contributors_url":"https://api.github.com/repos/apiaryio/fury.js/contributors","subscribers_url":"https://api.github.com/repos/apiaryio/fury.js/subscribers","subscription_url":"https://api.github.com/repos/apiaryio/fury.js/subscription","commits_url":"https://api.github.com/repos/apiaryio/fury.js/commits{/sha}","git_commits_url":"https://api.github.com/repos/apiaryio/fury.js/git/commits{/sha}","comments_url":"https://api.github.com/repos/apiaryio/fury.js/comments{/number}","issue_comment_url":"https://api.github.com/repos/apiaryio/fury.js/issues/comments{/number}","contents_url":"https://api.github.com/repos/apiaryio/fury.js/contents/{+path}","compare_url":"https://api.github.com/repos/apiaryio/fury.js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apiaryio/fury.js/merges","archive_url":"https://api.github.com/repos/apiaryio/fury.js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apiaryio/fury.js/downloads","issues_url":"https://api.github.com/repos/apiaryio/fury.js/issues{/number}","pulls_url":"https://api.github.com/repos/apiaryio/fury.js/pulls{/number}","milestones_url":"https://api.github.com/repos/apiaryio/fury.js/milestones{/number}","notifications_url":"https://api.github.com/repos/apiaryio/fury.js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apiaryio/fury.js/labels{/name}","releases_url":"https://api.github.com/repos/apiaryio/fury.js/releases{/id}","created_at":"2015-02-09T10:51:42Z","updated_at":"2015-06-05T20:11:09Z","pushed_at":"2015-06-05T21:27:43Z","git_url":"git://github.com/apiaryio/fury.js.git","ssh_url":"git@github.com:apiaryio/fury.js.git","clone_url":"https://github.com/apiaryio/fury.js.git","svn_url":"https://github.com/apiaryio/fury.js","homepage":"","size":726,"stargazers_count":13,"watchers_count":13,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":13,"default_branch":"master"}},"base":{"label":"apiaryio:master","ref":"master","sha":"038ab061ee70b5f6150875595af4a57f18ca2e3f","user":{"login":"apiaryio","id":765943,"avatar_url":"https://avatars.githubusercontent.com/u/765943?v=3","gravatar_id":"","url":"https://api.github.com/users/apiaryio","html_url":"https://github.com/apiaryio","followers_url":"https://api.github.com/users/apiaryio/followers","following_url":"https://api.github.com/users/apiaryio/following{/other_user}","gists_url":"https://api.github.com/users/apiaryio/gists{/gist_id}","starred_url":"https://api.github.com/users/apiaryio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apiaryio/subscriptions","organizations_url":"https://api.github.com/users/apiaryio/orgs","repos_url":"https://api.github.com/users/apiaryio/repos","events_url":"https://api.github.com/users/apiaryio/events{/privacy}","received_events_url":"https://api.github.com/users/apiaryio/received_events","type":"Organization","site_admin":false},"repo":{"id":30531423,"name":"fury.js","full_name":"apiaryio/fury.js","owner":{"login":"apiaryio","id":765943,"avatar_url":"https://avatars.githubusercontent.com/u/765943?v=3","gravatar_id":"","url":"https://api.github.com/users/apiaryio","html_url":"https://github.com/apiaryio","followers_url":"https://api.github.com/users/apiaryio/followers","following_url":"https://api.github.com/users/apiaryio/following{/other_user}","gists_url":"https://api.github.com/users/apiaryio/gists{/gist_id}","starred_url":"https://api.github.com/users/apiaryio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apiaryio/subscriptions","organizations_url":"https://api.github.com/users/apiaryio/orgs","repos_url":"https://api.github.com/users/apiaryio/repos","events_url":"https://api.github.com/users/apiaryio/events{/privacy}","received_events_url":"https://api.github.com/users/apiaryio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apiaryio/fury.js","description":"API Description SDK","fork":false,"url":"https://api.github.com/repos/apiaryio/fury.js","forks_url":"https://api.github.com/repos/apiaryio/fury.js/forks","keys_url":"https://api.github.com/repos/apiaryio/fury.js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apiaryio/fury.js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apiaryio/fury.js/teams","hooks_url":"https://api.github.com/repos/apiaryio/fury.js/hooks","issue_events_url":"https://api.github.com/repos/apiaryio/fury.js/issues/events{/number}","events_url":"https://api.github.com/repos/apiaryio/fury.js/events","assignees_url":"https://api.github.com/repos/apiaryio/fury.js/assignees{/user}","branches_url":"https://api.github.com/repos/apiaryio/fury.js/branches{/branch}","tags_url":"https://api.github.com/repos/apiaryio/fury.js/tags","blobs_url":"https://api.github.com/repos/apiaryio/fury.js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apiaryio/fury.js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apiaryio/fury.js/git/refs{/sha}","trees_url":"https://api.github.com/repos/apiaryio/fury.js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apiaryio/fury.js/statuses/{sha}","languages_url":"https://api.github.com/repos/apiaryio/fury.js/languages","stargazers_url":"https://api.github.com/repos/apiaryio/fury.js/stargazers","contributors_url":"https://api.github.com/repos/apiaryio/fury.js/contributors","subscribers_url":"https://api.github.com/repos/apiaryio/fury.js/subscribers","subscription_url":"https://api.github.com/repos/apiaryio/fury.js/subscription","commits_url":"https://api.github.com/repos/apiaryio/fury.js/commits{/sha}","git_commits_url":"https://api.github.com/repos/apiaryio/fury.js/git/commits{/sha}","comments_url":"https://api.github.com/repos/apiaryio/fury.js/comments{/number}","issue_comment_url":"https://api.github.com/repos/apiaryio/fury.js/issues/comments{/number}","contents_url":"https://api.github.com/repos/apiaryio/fury.js/contents/{+path}","compare_url":"https://api.github.com/repos/apiaryio/fury.js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apiaryio/fury.js/merges","archive_url":"https://api.github.com/repos/apiaryio/fury.js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apiaryio/fury.js/downloads","issues_url":"https://api.github.com/repos/apiaryio/fury.js/issues{/number}","pulls_url":"https://api.github.com/repos/apiaryio/fury.js/pulls{/number}","milestones_url":"https://api.github.com/repos/apiaryio/fury.js/milestones{/number}","notifications_url":"https://api.github.com/repos/apiaryio/fury.js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apiaryio/fury.js/labels{/name}","releases_url":"https://api.github.com/repos/apiaryio/fury.js/releases{/id}","created_at":"2015-02-09T10:51:42Z","updated_at":"2015-06-05T20:11:09Z","pushed_at":"2015-06-05T21:27:43Z","git_url":"git://github.com/apiaryio/fury.js.git","ssh_url":"git@github.com:apiaryio/fury.js.git","clone_url":"https://github.com/apiaryio/fury.js.git","svn_url":"https://github.com/apiaryio/fury.js","homepage":"","size":726,"stargazers_count":13,"watchers_count":13,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":13,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apiaryio/fury.js/pulls/23"},"html":{"href":"https://github.com/apiaryio/fury.js/pull/23"},"issue":{"href":"https://api.github.com/repos/apiaryio/fury.js/issues/23"},"comments":{"href":"https://api.github.com/repos/apiaryio/fury.js/issues/23/comments"},"review_comments":{"href":"https://api.github.com/repos/apiaryio/fury.js/pulls/23/comments"},"review_comment":{"href":"https://api.github.com/repos/apiaryio/fury.js/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apiaryio/fury.js/pulls/23/commits"},"statuses":{"href":"https://api.github.com/repos/apiaryio/fury.js/statuses/dc51565eb443729ab74e3a88dde70c47dae3d8a5"}}}}