slack_resources 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (254) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +66 -1
  3. data/.rubocop.yml +10 -2
  4. data/Gemfile +0 -1
  5. data/Gemfile.lock +7 -7
  6. data/lib/generate_event_api_resources.rb +8 -0
  7. data/lib/slack_resources.rb +9 -1
  8. data/lib/slack_resources/generator/event_api/examples_preparation.rb +71 -0
  9. data/lib/{event_api → slack_resources/generator/event_api}/fetch.rb +0 -0
  10. data/lib/slack_resources/generator/event_api/strong_hash.rb +25 -0
  11. data/lib/slack_resources/generator/event_api/to_schema.rb +200 -0
  12. data/lib/slack_resources/generator/event_api/type_detection.rb +272 -0
  13. data/lib/slack_resources/generator/event_api/write.rb +123 -0
  14. data/lib/slack_resources/raw_data/event_api/_added_examples/emoji_changed.add.json +7 -0
  15. data/lib/slack_resources/raw_data/event_api/_added_examples/emoji_changed.remove.json +6 -0
  16. data/lib/slack_resources/{resources → raw_data}/event_api/_added_examples/event_callback.json +0 -0
  17. data/lib/slack_resources/raw_data/event_api/examples/app_mention.json +8 -0
  18. data/lib/slack_resources/raw_data/event_api/examples/app_rate_limited.json +7 -0
  19. data/lib/slack_resources/raw_data/event_api/examples/app_uninstalled.json +11 -0
  20. data/lib/slack_resources/raw_data/event_api/examples/channel_archive.json +5 -0
  21. data/lib/slack_resources/raw_data/event_api/examples/channel_created.json +9 -0
  22. data/lib/slack_resources/raw_data/event_api/examples/channel_deleted.json +4 -0
  23. data/lib/slack_resources/raw_data/event_api/examples/channel_history_changed.json +6 -0
  24. data/lib/slack_resources/raw_data/event_api/examples/channel_left.json +4 -0
  25. data/lib/slack_resources/raw_data/event_api/examples/channel_rename.json +8 -0
  26. data/lib/slack_resources/raw_data/event_api/examples/channel_unarchive.json +5 -0
  27. data/lib/slack_resources/raw_data/event_api/examples/dnd_updated.json +11 -0
  28. data/lib/slack_resources/raw_data/event_api/examples/dnd_updated_user.json +9 -0
  29. data/lib/slack_resources/raw_data/event_api/examples/email_domain_changed.json +5 -0
  30. data/lib/slack_resources/raw_data/event_api/examples/emoji_changed.json +8 -0
  31. data/lib/slack_resources/raw_data/event_api/examples/file_change.json +7 -0
  32. data/lib/slack_resources/raw_data/event_api/examples/file_comment_added.json +9 -0
  33. data/lib/slack_resources/raw_data/event_api/examples/file_comment_deleted.json +8 -0
  34. data/lib/slack_resources/raw_data/event_api/examples/file_comment_edited.json +9 -0
  35. data/lib/slack_resources/raw_data/event_api/examples/file_created.json +7 -0
  36. data/lib/slack_resources/raw_data/event_api/examples/file_deleted.json +5 -0
  37. data/lib/slack_resources/raw_data/event_api/examples/file_public.json +7 -0
  38. data/lib/slack_resources/raw_data/event_api/examples/file_shared.json +7 -0
  39. data/lib/slack_resources/raw_data/event_api/examples/file_unshared.json +7 -0
  40. data/lib/slack_resources/raw_data/event_api/examples/grid_migration_finished.json +12 -0
  41. data/lib/slack_resources/raw_data/event_api/examples/grid_migration_started.json +12 -0
  42. data/lib/slack_resources/raw_data/event_api/examples/group_archive.json +4 -0
  43. data/lib/slack_resources/raw_data/event_api/examples/group_close.json +5 -0
  44. data/lib/slack_resources/raw_data/event_api/examples/group_deleted.json +4 -0
  45. data/lib/slack_resources/raw_data/event_api/examples/group_history_changed.json +6 -0
  46. data/lib/slack_resources/raw_data/event_api/examples/group_left.json +4 -0
  47. data/lib/slack_resources/raw_data/event_api/examples/group_open.json +5 -0
  48. data/lib/slack_resources/raw_data/event_api/examples/group_rename.json +8 -0
  49. data/lib/slack_resources/raw_data/event_api/examples/group_unarchive.json +4 -0
  50. data/lib/slack_resources/raw_data/event_api/examples/im_close.json +5 -0
  51. data/lib/slack_resources/raw_data/event_api/examples/im_created.json +6 -0
  52. data/lib/slack_resources/raw_data/event_api/examples/im_history_changed.json +6 -0
  53. data/lib/slack_resources/raw_data/event_api/examples/im_open.json +5 -0
  54. data/lib/slack_resources/raw_data/event_api/examples/link_shared.json +33 -0
  55. data/lib/slack_resources/raw_data/event_api/examples/member_joined_channel.json +8 -0
  56. data/lib/slack_resources/raw_data/event_api/examples/member_left_channel.json +7 -0
  57. data/lib/slack_resources/raw_data/event_api/examples/message.app_home.json +20 -0
  58. data/lib/slack_resources/raw_data/event_api/examples/message.channels.json +20 -0
  59. data/lib/slack_resources/raw_data/event_api/examples/message.groups.json +20 -0
  60. data/lib/slack_resources/raw_data/event_api/examples/message.im.json +20 -0
  61. data/lib/slack_resources/raw_data/event_api/examples/message.json +7 -0
  62. data/lib/slack_resources/raw_data/event_api/examples/message.mpim.json +20 -0
  63. data/lib/slack_resources/raw_data/event_api/examples/pin_added.json +8 -0
  64. data/lib/slack_resources/raw_data/event_api/examples/pin_removed.json +9 -0
  65. data/lib/slack_resources/raw_data/event_api/examples/reaction_added.json +12 -0
  66. data/lib/slack_resources/raw_data/event_api/examples/reaction_removed.json +12 -0
  67. data/lib/slack_resources/raw_data/event_api/examples/resources_added.json +31 -0
  68. data/lib/slack_resources/raw_data/event_api/examples/resources_removed.json +31 -0
  69. data/lib/slack_resources/raw_data/event_api/examples/scope_denied.json +20 -0
  70. data/lib/slack_resources/raw_data/event_api/examples/scope_granted.json +20 -0
  71. data/lib/slack_resources/raw_data/event_api/examples/star_added.json +7 -0
  72. data/lib/slack_resources/raw_data/event_api/examples/star_removed.json +7 -0
  73. data/lib/slack_resources/raw_data/event_api/examples/subteam_created.json +28 -0
  74. data/lib/slack_resources/raw_data/event_api/examples/subteam_members_changed.json +17 -0
  75. data/lib/slack_resources/raw_data/event_api/examples/subteam_self_added.json +4 -0
  76. data/lib/slack_resources/raw_data/event_api/examples/subteam_self_removed.json +4 -0
  77. data/lib/slack_resources/raw_data/event_api/examples/subteam_updated.json +34 -0
  78. data/lib/slack_resources/raw_data/event_api/examples/team_domain_change.json +5 -0
  79. data/lib/slack_resources/raw_data/event_api/examples/team_join.json +5 -0
  80. data/lib/slack_resources/raw_data/event_api/examples/team_rename.json +4 -0
  81. data/lib/slack_resources/raw_data/event_api/examples/tokens_revoked.json +19 -0
  82. data/lib/slack_resources/raw_data/event_api/examples/url_verification.json +5 -0
  83. data/lib/slack_resources/raw_data/event_api/examples/user_change.json +5 -0
  84. data/lib/slack_resources/raw_data/event_api/examples/user_resource_denied.json +20 -0
  85. data/lib/slack_resources/raw_data/event_api/examples/user_resource_granted.json +20 -0
  86. data/lib/slack_resources/raw_data/event_api/examples/user_resource_removed.json +16 -0
  87. data/lib/slack_resources/{resources → raw_data}/event_api/meta.json +0 -72
  88. data/lib/{schema.json → slack_resources/raw_data/event_api/preset_schemas.json} +7 -0
  89. data/lib/slack_resources/resources/event_api.rb +38 -0
  90. data/lib/slack_resources/resources/event_api/details/app_mention.json +67 -46
  91. data/lib/slack_resources/resources/event_api/details/app_rate_limited.json +59 -41
  92. data/lib/slack_resources/resources/event_api/details/app_uninstalled.json +22 -16
  93. data/lib/slack_resources/resources/event_api/details/channel_archive.json +42 -30
  94. data/lib/slack_resources/resources/event_api/details/channel_created.json +63 -54
  95. data/lib/slack_resources/resources/event_api/details/channel_deleted.json +32 -23
  96. data/lib/slack_resources/resources/event_api/details/channel_history_changed.json +48 -33
  97. data/lib/slack_resources/resources/event_api/details/channel_left.json +32 -23
  98. data/lib/slack_resources/resources/event_api/details/channel_rename.json +58 -49
  99. data/lib/slack_resources/resources/event_api/details/channel_unarchive.json +42 -30
  100. data/lib/slack_resources/resources/event_api/details/dnd_updated.json +66 -54
  101. data/lib/slack_resources/resources/event_api/details/dnd_updated_user.json +62 -50
  102. data/lib/slack_resources/resources/event_api/details/email_domain_changed.json +39 -27
  103. data/lib/slack_resources/resources/event_api/details/emoji_changed.add.json +78 -0
  104. data/lib/slack_resources/resources/event_api/details/emoji_changed.json +85 -44
  105. data/lib/slack_resources/resources/event_api/details/emoji_changed.remove.json +77 -0
  106. data/lib/slack_resources/resources/event_api/details/event_callback.json +102 -72
  107. data/lib/slack_resources/resources/event_api/details/file_change.json +49 -37
  108. data/lib/slack_resources/resources/event_api/details/file_comment_added.json +61 -46
  109. data/lib/slack_resources/resources/event_api/details/file_comment_deleted.json +59 -44
  110. data/lib/slack_resources/resources/event_api/details/file_comment_edited.json +61 -46
  111. data/lib/slack_resources/resources/event_api/details/file_created.json +49 -37
  112. data/lib/slack_resources/resources/event_api/details/file_deleted.json +41 -29
  113. data/lib/slack_resources/resources/event_api/details/file_public.json +49 -37
  114. data/lib/slack_resources/resources/event_api/details/file_shared.json +49 -37
  115. data/lib/slack_resources/resources/event_api/details/file_unshared.json +49 -37
  116. data/lib/slack_resources/resources/event_api/details/grid_migration_finished.json +31 -22
  117. data/lib/slack_resources/resources/event_api/details/grid_migration_started.json +31 -22
  118. data/lib/slack_resources/resources/event_api/details/group_archive.json +32 -23
  119. data/lib/slack_resources/resources/event_api/details/group_close.json +42 -30
  120. data/lib/slack_resources/resources/event_api/details/group_deleted.json +32 -23
  121. data/lib/slack_resources/resources/event_api/details/group_history_changed.json +48 -33
  122. data/lib/slack_resources/resources/event_api/details/group_left.json +32 -23
  123. data/lib/slack_resources/resources/event_api/details/group_open.json +42 -30
  124. data/lib/slack_resources/resources/event_api/details/group_rename.json +58 -49
  125. data/lib/slack_resources/resources/event_api/details/group_unarchive.json +32 -23
  126. data/lib/slack_resources/resources/event_api/details/im_close.json +42 -30
  127. data/lib/slack_resources/resources/event_api/details/im_created.json +53 -41
  128. data/lib/slack_resources/resources/event_api/details/im_history_changed.json +48 -33
  129. data/lib/slack_resources/resources/event_api/details/im_open.json +42 -30
  130. data/lib/slack_resources/resources/event_api/details/link_shared.json +107 -83
  131. data/lib/slack_resources/resources/event_api/details/member_joined_channel.json +66 -48
  132. data/lib/slack_resources/resources/event_api/details/member_left_channel.json +58 -43
  133. data/lib/slack_resources/resources/event_api/details/message.app_home.json +74 -53
  134. data/lib/slack_resources/resources/event_api/details/message.channels.json +74 -56
  135. data/lib/slack_resources/resources/event_api/details/message.groups.json +74 -56
  136. data/lib/slack_resources/resources/event_api/details/message.im.json +74 -56
  137. data/lib/slack_resources/resources/event_api/details/message.json +106 -60
  138. data/lib/slack_resources/resources/event_api/details/message.mpim.json +74 -56
  139. data/lib/slack_resources/resources/event_api/details/pin_added.json +65 -47
  140. data/lib/slack_resources/resources/event_api/details/pin_removed.json +73 -52
  141. data/lib/slack_resources/resources/event_api/details/reaction_added.json +94 -73
  142. data/lib/slack_resources/resources/event_api/details/reaction_removed.json +94 -73
  143. data/lib/slack_resources/resources/event_api/details/resources_added.json +127 -115
  144. data/lib/slack_resources/resources/event_api/details/resources_removed.json +127 -115
  145. data/lib/slack_resources/resources/event_api/details/scope_denied.json +74 -59
  146. data/lib/slack_resources/resources/event_api/details/scope_granted.json +74 -59
  147. data/lib/slack_resources/resources/event_api/details/star_added.json +56 -41
  148. data/lib/slack_resources/resources/event_api/details/star_removed.json +56 -41
  149. data/lib/slack_resources/resources/event_api/details/subteam_created.json +177 -168
  150. data/lib/slack_resources/resources/event_api/details/subteam_members_changed.json +118 -82
  151. data/lib/slack_resources/resources/event_api/details/subteam_self_added.json +31 -22
  152. data/lib/slack_resources/resources/event_api/details/subteam_self_removed.json +31 -22
  153. data/lib/slack_resources/resources/event_api/details/subteam_updated.json +189 -180
  154. data/lib/slack_resources/resources/event_api/details/team_domain_change.json +38 -26
  155. data/lib/slack_resources/resources/event_api/details/team_join.json +35 -26
  156. data/lib/slack_resources/resources/event_api/details/team_rename.json +32 -23
  157. data/lib/slack_resources/resources/event_api/details/tokens_revoked.json +58 -49
  158. data/lib/slack_resources/resources/event_api/details/url_verification.json +32 -26
  159. data/lib/slack_resources/resources/event_api/details/user_change.json +35 -26
  160. data/lib/slack_resources/resources/event_api/details/user_resource_denied.json +82 -64
  161. data/lib/slack_resources/resources/event_api/details/user_resource_granted.json +82 -64
  162. data/lib/slack_resources/resources/event_api/details/user_resource_removed.json +41 -29
  163. data/lib/slack_resources/resources/event_api/examples/app_mention.json +4 -4
  164. data/lib/slack_resources/resources/event_api/examples/app_rate_limited.json +4 -4
  165. data/lib/slack_resources/resources/event_api/examples/app_uninstalled.json +1 -9
  166. data/lib/slack_resources/resources/event_api/examples/channel_archive.json +1 -1
  167. data/lib/slack_resources/resources/event_api/examples/channel_created.json +2 -2
  168. data/lib/slack_resources/resources/event_api/examples/channel_deleted.json +2 -2
  169. data/lib/slack_resources/resources/event_api/examples/channel_history_changed.json +2 -2
  170. data/lib/slack_resources/resources/event_api/examples/channel_left.json +2 -2
  171. data/lib/slack_resources/resources/event_api/examples/channel_rename.json +2 -2
  172. data/lib/slack_resources/resources/event_api/examples/channel_unarchive.json +1 -1
  173. data/lib/slack_resources/resources/event_api/examples/dnd_updated.json +3 -3
  174. data/lib/slack_resources/resources/event_api/examples/dnd_updated_user.json +3 -3
  175. data/lib/slack_resources/resources/event_api/examples/email_domain_changed.json +2 -2
  176. data/lib/slack_resources/resources/event_api/examples/emoji_changed.add.json +7 -0
  177. data/lib/slack_resources/resources/event_api/examples/emoji_changed.json +4 -5
  178. data/lib/slack_resources/resources/event_api/examples/emoji_changed.remove.json +8 -0
  179. data/lib/slack_resources/resources/event_api/examples/event_callback.json +7 -6
  180. data/lib/slack_resources/resources/event_api/examples/file_change.json +3 -3
  181. data/lib/slack_resources/resources/event_api/examples/file_comment_added.json +3 -3
  182. data/lib/slack_resources/resources/event_api/examples/file_comment_deleted.json +3 -3
  183. data/lib/slack_resources/resources/event_api/examples/file_comment_edited.json +3 -3
  184. data/lib/slack_resources/resources/event_api/examples/file_created.json +3 -3
  185. data/lib/slack_resources/resources/event_api/examples/file_deleted.json +2 -2
  186. data/lib/slack_resources/resources/event_api/examples/file_public.json +3 -3
  187. data/lib/slack_resources/resources/event_api/examples/file_shared.json +3 -3
  188. data/lib/slack_resources/resources/event_api/examples/file_unshared.json +3 -3
  189. data/lib/slack_resources/resources/event_api/examples/grid_migration_finished.json +2 -10
  190. data/lib/slack_resources/resources/event_api/examples/grid_migration_started.json +2 -10
  191. data/lib/slack_resources/resources/event_api/examples/group_archive.json +2 -2
  192. data/lib/slack_resources/resources/event_api/examples/group_close.json +2 -2
  193. data/lib/slack_resources/resources/event_api/examples/group_deleted.json +2 -2
  194. data/lib/slack_resources/resources/event_api/examples/group_history_changed.json +2 -2
  195. data/lib/slack_resources/resources/event_api/examples/group_left.json +2 -2
  196. data/lib/slack_resources/resources/event_api/examples/group_open.json +2 -2
  197. data/lib/slack_resources/resources/event_api/examples/group_rename.json +2 -2
  198. data/lib/slack_resources/resources/event_api/examples/group_unarchive.json +2 -2
  199. data/lib/slack_resources/resources/event_api/examples/im_close.json +2 -2
  200. data/lib/slack_resources/resources/event_api/examples/im_created.json +3 -3
  201. data/lib/slack_resources/resources/event_api/examples/im_history_changed.json +2 -2
  202. data/lib/slack_resources/resources/event_api/examples/im_open.json +2 -2
  203. data/lib/slack_resources/resources/event_api/examples/link_shared.json +18 -30
  204. data/lib/slack_resources/resources/event_api/examples/member_joined_channel.json +3 -3
  205. data/lib/slack_resources/resources/event_api/examples/member_left_channel.json +3 -3
  206. data/lib/slack_resources/resources/event_api/examples/message.app_home.json +7 -18
  207. data/lib/slack_resources/resources/event_api/examples/message.channels.json +7 -18
  208. data/lib/slack_resources/resources/event_api/examples/message.groups.json +7 -18
  209. data/lib/slack_resources/resources/event_api/examples/message.im.json +7 -18
  210. data/lib/slack_resources/resources/event_api/examples/message.json +6 -4
  211. data/lib/slack_resources/resources/event_api/examples/message.mpim.json +7 -18
  212. data/lib/slack_resources/resources/event_api/examples/pin_added.json +3 -3
  213. data/lib/slack_resources/resources/event_api/examples/pin_removed.json +4 -4
  214. data/lib/slack_resources/resources/event_api/examples/reaction_added.json +5 -5
  215. data/lib/slack_resources/resources/event_api/examples/reaction_removed.json +5 -5
  216. data/lib/slack_resources/resources/event_api/examples/resources_added.json +17 -28
  217. data/lib/slack_resources/resources/event_api/examples/resources_removed.json +17 -28
  218. data/lib/slack_resources/resources/event_api/examples/scope_denied.json +6 -17
  219. data/lib/slack_resources/resources/event_api/examples/scope_granted.json +6 -17
  220. data/lib/slack_resources/resources/event_api/examples/star_added.json +3 -3
  221. data/lib/slack_resources/resources/event_api/examples/star_removed.json +3 -3
  222. data/lib/slack_resources/resources/event_api/examples/subteam_created.json +2 -2
  223. data/lib/slack_resources/resources/event_api/examples/subteam_members_changed.json +6 -6
  224. data/lib/slack_resources/resources/event_api/examples/subteam_self_added.json +2 -2
  225. data/lib/slack_resources/resources/event_api/examples/subteam_self_removed.json +2 -2
  226. data/lib/slack_resources/resources/event_api/examples/subteam_updated.json +2 -2
  227. data/lib/slack_resources/resources/event_api/examples/team_domain_change.json +2 -2
  228. data/lib/slack_resources/resources/event_api/examples/team_rename.json +2 -2
  229. data/lib/slack_resources/resources/event_api/examples/tokens_revoked.json +8 -16
  230. data/lib/slack_resources/resources/event_api/examples/url_verification.json +1 -1
  231. data/lib/slack_resources/resources/event_api/examples/user_resource_denied.json +6 -17
  232. data/lib/slack_resources/resources/event_api/examples/user_resource_granted.json +6 -17
  233. data/lib/slack_resources/resources/event_api/examples/user_resource_removed.json +3 -14
  234. data/lib/slack_resources/resources/event_api/schema.json +257 -105
  235. data/lib/slack_resources/resources/event_api/schemas/emoji_changed.add.json +42 -0
  236. data/lib/slack_resources/resources/event_api/schemas/emoji_changed.json +27 -9
  237. data/lib/slack_resources/resources/event_api/schemas/emoji_changed.remove.json +40 -0
  238. data/lib/slack_resources/resources/event_api/schemas/member_joined_channel.json +1 -4
  239. data/lib/slack_resources/resources/event_api/schemas/member_left_channel.json +1 -4
  240. data/lib/slack_resources/resources/event_api/schemas/message.app_home.json +1 -4
  241. data/lib/slack_resources/resources/event_api/schemas/message.channels.json +1 -7
  242. data/lib/slack_resources/resources/event_api/schemas/message.groups.json +1 -7
  243. data/lib/slack_resources/resources/event_api/schemas/message.im.json +1 -7
  244. data/lib/slack_resources/resources/event_api/schemas/message.json +39 -17
  245. data/lib/slack_resources/resources/event_api/schemas/message.mpim.json +1 -7
  246. data/lib/slack_resources/resources/event_api/schemas/resources_added.json +15 -15
  247. data/lib/slack_resources/resources/event_api/schemas/resources_removed.json +15 -15
  248. data/lib/slack_resources/resources/event_api/schemas/team_rename.json +2 -2
  249. data/lib/slack_resources/resources/event_api/schemas/url_verification.json +0 -6
  250. data/lib/slack_resources/resources/event_api/summary.json +4887 -3400
  251. data/slack_resources.gemspec +4 -2
  252. metadata +91 -8
  253. data/lib/event_api/write.rb +0 -364
  254. data/lib/slack_resources/version.rb +0 -3
@@ -0,0 +1,272 @@
1
+ require 'active_support/core_ext/module/delegation'
2
+
3
+ module SlackResources
4
+ module Generator
5
+ class TypeDetection
6
+ using StrongHash
7
+
8
+ SPECIAL_TYPE = '_type'.freeze
9
+ MULTIPLE_EXAMPLES = 'MULTIPLE_EXAMPLES'.freeze
10
+
11
+ CONST_TYPES = %w[
12
+ type
13
+ subtype
14
+ ].freeze
15
+
16
+ DEFAULT_TYPES = Set.new(%w[
17
+ string
18
+ number
19
+ object
20
+ array
21
+ boolean
22
+ null
23
+ ])
24
+
25
+ STRING_ID_PROPERTIES_MAP = {
26
+ item_user: 'user_id',
27
+ user: 'user_id',
28
+ creator: 'user_id',
29
+ inviter: 'user_id',
30
+ created_by: 'user_id',
31
+ updated_by: 'user_id',
32
+ deleted_by: 'user_id',
33
+ channel: 'channel_id',
34
+ comment: 'comment_id',
35
+ team: 'team_id',
36
+ }.stringify_keys!
37
+
38
+ STRING_ID_PROPERTIES = Set.new(STRING_ID_PROPERTIES_MAP.keys)
39
+
40
+ DIRECT_STRING_PROPERTIES = Set.new(%w[
41
+ email_domain
42
+ text
43
+ description
44
+ handle
45
+ url
46
+ domain
47
+ challenge
48
+ ])
49
+
50
+ USER_COUNT_PROPERTIES = Set.new(%w[
51
+ user_count
52
+ added_users_count
53
+ removed_users_count
54
+ ])
55
+
56
+ ARRAY_PROPERTIES_TYPE_MAP = {
57
+ authed_users: 'user_id',
58
+ users: 'user_id',
59
+ added_users: 'user_id',
60
+ removed_users: 'user_id',
61
+ authed_teams: 'team_id',
62
+ channels: 'channel_id',
63
+ groups: 'group_id',
64
+ scopes: 'scope',
65
+ links: 'link',
66
+ oauth: 'string',
67
+ bot: 'string',
68
+ resources: 'resource_item',
69
+ }.stringify_keys!
70
+
71
+ TOKENS_REVOKED_ARRAY_PROPERTIES = Set.new(%w[
72
+ oauth
73
+ bot
74
+ ])
75
+
76
+ ARRAY_PROPERTIES = Set.new(ARRAY_PROPERTIES_TYPE_MAP.keys - TOKENS_REVOKED_ARRAY_PROPERTIES.to_a)
77
+
78
+ BOOLEAN = Set.new([true, false])
79
+
80
+ AMBIENT_PROPERTIES = Set.new(%w[
81
+ id
82
+ type
83
+ name
84
+ subtype
85
+ value
86
+ item
87
+ ])
88
+
89
+ class << self
90
+ def default_type?(type)
91
+ DEFAULT_TYPES.include?(type)
92
+ end
93
+ end
94
+
95
+ def initialize(to_schema_instance:, parent_key:, prop_name:, value:, container:, preset:)
96
+ @to_schema = to_schema_instance
97
+ @parent_key = parent_key
98
+ @prop_name = prop_name
99
+ @value = value
100
+ @container = container
101
+ @preset = preset
102
+ end
103
+
104
+ def execute! # rubocop:disable Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity
105
+ case
106
+ when root_schema? && constantable?
107
+ { 'const' => @value }
108
+ when item_schema? && type?
109
+ define_string("#{root_type_prefix}_#{@parent_key}_type")
110
+
111
+ when string_id?
112
+ define_string_id
113
+
114
+ when emoji_list?
115
+ define_string('emoji_name')
116
+ '[]emoji_name'
117
+ when emoji_alternative?
118
+ define_string('emoji_name')
119
+
120
+ when array?
121
+ define_array_type
122
+
123
+ when user_count?
124
+ 'user_count'
125
+ when time_integer?
126
+ 'time_integer'
127
+ when boolean?
128
+ 'boolean'
129
+ when direct_string? || (on_url_verification? && @prop_name == 'token')
130
+ 'string'
131
+ when timestamp?
132
+ 'timestamp'
133
+
134
+ else
135
+ define_default_type(normalized_prop_name, @value, @container, const_type?)
136
+ end
137
+ end
138
+
139
+ private
140
+
141
+ delegate(
142
+ :root_schema?,
143
+ :define_string,
144
+ :root_type,
145
+ :root_type_prefix,
146
+ :define_default_type,
147
+ :define_object,
148
+ :define_enum,
149
+ :ref_to,
150
+ to: :@to_schema
151
+ )
152
+
153
+ def normalized_prop_name
154
+ if ambient?
155
+ root_schema? ? "#{root_type_prefix}_#{@prop_name}" : "#{@parent_key}_#{@prop_name}"
156
+ else
157
+ @prop_name
158
+ end
159
+ end
160
+
161
+ def type?
162
+ @prop_name == 'type'
163
+ end
164
+
165
+ def const_type?
166
+ CONST_TYPES.include?(@prop_name) || @prop_name.match(/_type$/)
167
+ end
168
+
169
+ def string?
170
+ @value.is_a?(String)
171
+ end
172
+
173
+ def constantable?
174
+ const_type? && (@value.is_a?(String) || @value.is_a?(Integer))
175
+ end
176
+
177
+ def emoji_alternative?
178
+ @prop_name == 'reaction'
179
+ end
180
+
181
+ def item_schema?
182
+ @parent_key == 'item'
183
+ end
184
+
185
+ def ambient?
186
+ AMBIENT_PROPERTIES.include?(@prop_name)
187
+ end
188
+
189
+ def time_integer?
190
+ @value.is_a?(Integer)
191
+ end
192
+
193
+ def boolean?
194
+ BOOLEAN.include?(@value)
195
+ end
196
+
197
+ def timestamp?
198
+ @prop_name == 'latest' || @prop_name.match(/.+_ts$/) || float_string?
199
+ end
200
+
201
+ def float_string?
202
+ @value.respond_to?(:to_f) && @value == @value.to_f.to_s
203
+ end
204
+
205
+ def array?
206
+ ARRAY_PROPERTIES.include?(@prop_name) || tokens_revoked_array?
207
+ end
208
+
209
+ def tokens_revoked_array?
210
+ on_tokens_revoked? && TOKENS_REVOKED_ARRAY_PROPERTIES.include?(@prop_name)
211
+ end
212
+
213
+ def user_count?
214
+ USER_COUNT_PROPERTIES.include?(@prop_name)
215
+ end
216
+
217
+ def direct_string?
218
+ DIRECT_STRING_PROPERTIES.include?(@prop_name)
219
+ end
220
+
221
+ def string_id?
222
+ @prop_name.match(/_id$/) || (string_value? && STRING_ID_PROPERTIES.include?(@prop_name))
223
+ end
224
+
225
+ def string_value?
226
+ @value.nil? || @value.is_a?(String)
227
+ end
228
+
229
+ def default_type?(type)
230
+ DEFAULT_TYPES.include?(type)
231
+ end
232
+
233
+ def emoji_list?
234
+ on_emoji_changed? && @prop_name == 'names'
235
+ end
236
+
237
+ def on_tokens_revoked?
238
+ root_type == 'tokens_revoked'
239
+ end
240
+
241
+ def on_url_verification?
242
+ root_type == 'url_verification'
243
+ end
244
+
245
+ def on_emoji_changed?
246
+ root_type == 'emoji_changed'
247
+ end
248
+
249
+ def define_array_type
250
+ type = ARRAY_PROPERTIES_TYPE_MAP[@prop_name]
251
+ array_type = "[]#{type}"
252
+
253
+ return array_type if default_type?(type)
254
+ return define_string(type) && array_type unless @value.is_a?(Hash)
255
+
256
+ to_child_schema(
257
+ prop_name: type,
258
+ example: @value.first,
259
+ key: @prop_name,
260
+ parent: @container
261
+ )
262
+
263
+ array_type
264
+ end
265
+
266
+ def define_string_id
267
+ type = STRING_ID_PROPERTIES_MAP[@prop_name] || @prop_name
268
+ define_string(type)
269
+ end
270
+ end
271
+ end
272
+ end
@@ -0,0 +1,123 @@
1
+ require 'pathname'
2
+ require 'rest-client'
3
+ require 'nokogiri'
4
+ require 'json'
5
+ require 'active_support/core_ext/object/blank'
6
+ require 'active_support/core_ext/string/inflections'
7
+
8
+ module SlackResources
9
+ module Generator
10
+ class Writer
11
+ using StrongHash
12
+
13
+ def initialize(output_dir:, data_dir:)
14
+ @output_dir = Pathname(output_dir)
15
+ @details_output_dir = @output_dir.join('details')
16
+ @schemas_output_dir = @output_dir.join('schemas')
17
+ @example_output_dir = @output_dir.join('examples')
18
+
19
+ @data_dir = Pathname(data_dir)
20
+ @meta = JSON.parse(File.read(@data_dir.join('meta.json')))
21
+ @preset_schema = JSON.parse(File.read(@data_dir.join('preset_schemas.json')))
22
+ @preset_definitions = @preset_schema['definitions']
23
+
24
+ @examples_dir = @data_dir.join('examples')
25
+ @added_examples_dir = @data_dir.join('_added_examples')
26
+ end
27
+
28
+ def execute!
29
+ FileUtils.mkdir_p(@details_output_dir)
30
+ FileUtils.mkdir_p(@schemas_output_dir)
31
+ FileUtils.mkdir_p(@example_output_dir)
32
+
33
+ alt_event_type_mapped_examples = ExamplePreparation.new(
34
+ examples_dir: @examples_dir,
35
+ added_examples_dir: @added_examples_dir
36
+ ).execute!
37
+
38
+ examples_with_metadata = alt_event_type_mapped_examples.map do |alt_event_type, example|
39
+ info = @meta['subscriptions'][alt_event_type] || @meta['subscriptions'][example['type']] || {}
40
+ [info['url'], alt_event_type, example, info['compatibility'], info['scopes']]
41
+ end
42
+
43
+ all_sub_schemas = @preset_definitions.merge(
44
+ 'scope' => {
45
+ "type": 'string',
46
+ "enum": @meta['scopes'],
47
+ }
48
+ )
49
+
50
+ main_schemas = {}
51
+
52
+ all_details = examples_with_metadata.map do |url, alt_event_type, example, compatibility, scopes|
53
+ raw_example = example.delete('_raw_example')
54
+ schema, new_definition, included_props_names = ToSchema.new(
55
+ example: example,
56
+ url: url,
57
+ preset: all_sub_schemas
58
+ ).execute!
59
+
60
+ all_sub_schemas.protect_merge!(new_definition)
61
+
62
+ included_schemas = included_props_names.inject({}) do |a, included_prop|
63
+ all_sub_schemas[included_prop] ? a.protect_merge!(included_prop => all_sub_schemas[included_prop]) : a
64
+ end
65
+
66
+ schema['description'] = "learn more: #{url}"
67
+ schema['example'] = raw_example
68
+
69
+ main_schemas[alt_event_type] = schema
70
+
71
+ [
72
+ alt_event_type,
73
+ {
74
+ url: url,
75
+ event: alt_event_type,
76
+ sub_schemas: included_schemas,
77
+ schema: schema,
78
+ compatibility: compatibility,
79
+ scopes: scopes,
80
+ },
81
+ {
82
+ "$schema": 'http://json-schema.org/draft-07/schema',
83
+ 'definitions' => included_schemas.protect_merge!(alt_event_type => schema),
84
+ },
85
+ raw_example,
86
+ ]
87
+ end
88
+
89
+ write_each_data_json!(all_details)
90
+ write_all_schemas_json!(all_sub_schemas, main_schemas)
91
+ write_summary!(all_details.map { |d| d[1] })
92
+
93
+ all_details
94
+ end
95
+
96
+ # @output_dir = Pathname('./lib/slack_resources/resources/event_api/')
97
+
98
+ private
99
+
100
+ def write_each_data_json!(all_details)
101
+ all_details.each do |alt_event_type, data, single_schema, example|
102
+ File.write(@details_output_dir.join("#{alt_event_type}.json").to_s, JSON.pretty_generate(data))
103
+ File.write(@example_output_dir.join("#{alt_event_type}.json").to_s, JSON.pretty_generate(example))
104
+ File.write(@schemas_output_dir.join("#{alt_event_type}.json").to_s, JSON.pretty_generate(single_schema))
105
+ end
106
+ end
107
+
108
+ def write_all_schemas_json!(all_sub_schemas, main_schemas)
109
+ File.write(
110
+ @output_dir.join('schema.json').to_s,
111
+ JSON.pretty_generate(
112
+ "$schema": 'http://json-schema.org/draft-07/schema',
113
+ 'definitions' => all_sub_schemas.protect_merge!(main_schemas).key_ordered
114
+ )
115
+ )
116
+ end
117
+
118
+ def write_summary!(data)
119
+ File.write(@output_dir.join('summary.json').to_s, JSON.pretty_generate(data.sort_by { |a| a[:type] }))
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,7 @@
1
+ {
2
+ "type": "emoji_changed",
3
+ "subtype": "add",
4
+ "name": "picard_facepalm",
5
+ "value": "https://my.slack.com/emoji/picard_facepalm/db8e287430eaa459.gif",
6
+ "event_ts" : "1361482916.000004"
7
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "emoji_changed",
3
+ "subtype": "remove",
4
+ "names": ["picard_facepalm"],
5
+ "event_ts" : "1361482916.000004"
6
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "type": "app_mention",
3
+ "user": "U061F7AUR",
4
+ "text": "<@U0LAN0Z89> is it everything a river should be?",
5
+ "ts": "1515449522.000016",
6
+ "channel": "C0LAN2Q65",
7
+ "event_ts": "1515449522000016"
8
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "token": "Jhj5dZrVaK7ZwHHjRyZWjbDl",
3
+ "type": "app_rate_limited",
4
+ "team_id": "T123456",
5
+ "minute_rate_limited": 1518467820,
6
+ "api_app_id": "A123456"
7
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "token": "XXYYZZ",
3
+ "team_id": "TXXXXXXXX",
4
+ "api_app_id": "AXXXXXXXXX",
5
+ "event": {
6
+ "type": "app_uninstalled"
7
+ },
8
+ "type": "event_callback",
9
+ "event_id": "EvXXXXXXXX",
10
+ "event_time": 1234567890
11
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "type": "channel_archive",
3
+ "channel": "C024BE91L",
4
+ "user": "U024BE7LH"
5
+ }