flex_commerce_api 0.6.57

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +7 -0
  2. data/.env.example +6 -0
  3. data/.gitignore +14 -0
  4. data/.rspec +4 -0
  5. data/.rubocop.yml +1065 -0
  6. data/.ruby-gemset +1 -0
  7. data/.ruby-version +1 -0
  8. data/.travis.yml +3 -0
  9. data/Gemfile +4 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +56 -0
  12. data/Rakefile +1 -0
  13. data/app/models/address.rb +41 -0
  14. data/app/models/asset_file.rb +26 -0
  15. data/app/models/asset_folder.rb +14 -0
  16. data/app/models/bundle.rb +20 -0
  17. data/app/models/bundle_group.rb +15 -0
  18. data/app/models/cart.rb +136 -0
  19. data/app/models/category.rb +70 -0
  20. data/app/models/category_tree.rb +11 -0
  21. data/app/models/component.rb +8 -0
  22. data/app/models/container_coupon.rb +12 -0
  23. data/app/models/country.rb +11 -0
  24. data/app/models/coupon.rb +18 -0
  25. data/app/models/customer_account.rb +96 -0
  26. data/app/models/customer_account_authentication.rb +5 -0
  27. data/app/models/customer_segment.rb +6 -0
  28. data/app/models/customer_segment_member.rb +6 -0
  29. data/app/models/data_attribute.rb +6 -0
  30. data/app/models/data_store_record.rb +9 -0
  31. data/app/models/data_store_type.rb +9 -0
  32. data/app/models/discount_summary.rb +12 -0
  33. data/app/models/email.rb +5 -0
  34. data/app/models/ewis_opt_in.rb +8 -0
  35. data/app/models/external_url.rb +6 -0
  36. data/app/models/free_shipping_promotion.rb +12 -0
  37. data/app/models/import.rb +6 -0
  38. data/app/models/import_entry.rb +6 -0
  39. data/app/models/line_item.rb +34 -0
  40. data/app/models/line_item_discount.rb +7 -0
  41. data/app/models/markdown_price.rb +11 -0
  42. data/app/models/menu.rb +36 -0
  43. data/app/models/menu_item.rb +7 -0
  44. data/app/models/menu_item_item.rb +5 -0
  45. data/app/models/note.rb +18 -0
  46. data/app/models/order.rb +38 -0
  47. data/app/models/password_recovery.rb +20 -0
  48. data/app/models/payment_address_verification.rb +13 -0
  49. data/app/models/payment_process.rb +13 -0
  50. data/app/models/payment_provider.rb +15 -0
  51. data/app/models/payment_transaction.rb +13 -0
  52. data/app/models/product.rb +99 -0
  53. data/app/models/product_asset_file.rb +12 -0
  54. data/app/models/promotion.rb +19 -0
  55. data/app/models/promotion_qualifying_product_exclusion.rb +8 -0
  56. data/app/models/redirect.rb +14 -0
  57. data/app/models/refund.rb +14 -0
  58. data/app/models/remote_address.rb +22 -0
  59. data/app/models/remote_line_item.rb +11 -0
  60. data/app/models/remote_order.rb +15 -0
  61. data/app/models/remote_shipping_method.rb +12 -0
  62. data/app/models/report.rb +18 -0
  63. data/app/models/report_invocation.rb +18 -0
  64. data/app/models/retail_store.rb +18 -0
  65. data/app/models/role.rb +6 -0
  66. data/app/models/search_suggestion.rb +17 -0
  67. data/app/models/section.rb +9 -0
  68. data/app/models/session.rb +8 -0
  69. data/app/models/shipping_method.rb +26 -0
  70. data/app/models/slug.rb +19 -0
  71. data/app/models/static_page.rb +60 -0
  72. data/app/models/static_page_folder.rb +8 -0
  73. data/app/models/stock_level.rb +21 -0
  74. data/app/models/tax_code.rb +6 -0
  75. data/app/models/taxonomy.rb +5 -0
  76. data/app/models/template.rb +9 -0
  77. data/app/models/template_component.rb +11 -0
  78. data/app/models/template_definition.rb +12 -0
  79. data/app/models/template_section.rb +12 -0
  80. data/app/models/user.rb +8 -0
  81. data/app/models/user_profile.rb +6 -0
  82. data/app/models/v2/create_order.rb +10 -0
  83. data/app/models/v2/deallocate_order.rb +10 -0
  84. data/app/models/v2/line_item.rb +9 -0
  85. data/app/models/v2/order.rb +9 -0
  86. data/app/models/v2/unallocate_order.rb +10 -0
  87. data/app/models/variant.rb +18 -0
  88. data/app/models/webhook.rb +17 -0
  89. data/app/services/param_to_shql.rb +72 -0
  90. data/app/services/surrogate_keys.rb +44 -0
  91. data/bin/console +14 -0
  92. data/bin/setup +7 -0
  93. data/config/locales/payments.en.yml +3 -0
  94. data/flex-commerce-api.gemspec +41 -0
  95. data/lib/flex_commerce.rb +95 -0
  96. data/lib/flex_commerce_api.rb +21 -0
  97. data/lib/flex_commerce_api/api_base.rb +11 -0
  98. data/lib/flex_commerce_api/base_resource.rb +250 -0
  99. data/lib/flex_commerce_api/config.rb +55 -0
  100. data/lib/flex_commerce_api/error/access_denied.rb +6 -0
  101. data/lib/flex_commerce_api/error/bad_request.rb +10 -0
  102. data/lib/flex_commerce_api/error/base.rb +12 -0
  103. data/lib/flex_commerce_api/error/client_error.rb +7 -0
  104. data/lib/flex_commerce_api/error/connection_error.rb +6 -0
  105. data/lib/flex_commerce_api/error/internal_server.rb +37 -0
  106. data/lib/flex_commerce_api/error/not_found.rb +13 -0
  107. data/lib/flex_commerce_api/error/record_invalid.rb +16 -0
  108. data/lib/flex_commerce_api/error/unexpected_status.rb +7 -0
  109. data/lib/flex_commerce_api/errors.rb +13 -0
  110. data/lib/flex_commerce_api/json_api_client_extension/builder.rb +28 -0
  111. data/lib/flex_commerce_api/json_api_client_extension/capture_surrogate_keys_middleware.rb +16 -0
  112. data/lib/flex_commerce_api/json_api_client_extension/flexible_connection.rb +59 -0
  113. data/lib/flex_commerce_api/json_api_client_extension/has_many_association_proxy.rb +60 -0
  114. data/lib/flex_commerce_api/json_api_client_extension/included_data.rb +27 -0
  115. data/lib/flex_commerce_api/json_api_client_extension/json_format_middleware.rb +20 -0
  116. data/lib/flex_commerce_api/json_api_client_extension/logging_middleware.rb +24 -0
  117. data/lib/flex_commerce_api/json_api_client_extension/paginator.rb +26 -0
  118. data/lib/flex_commerce_api/json_api_client_extension/parse_json.rb +23 -0
  119. data/lib/flex_commerce_api/json_api_client_extension/parsers/parser.rb +16 -0
  120. data/lib/flex_commerce_api/json_api_client_extension/previewed_request_middleware.rb +17 -0
  121. data/lib/flex_commerce_api/json_api_client_extension/remote_builder.rb +29 -0
  122. data/lib/flex_commerce_api/json_api_client_extension/requestor.rb +42 -0
  123. data/lib/flex_commerce_api/json_api_client_extension/save_request_body_middleware.rb +20 -0
  124. data/lib/flex_commerce_api/json_api_client_extension/status_middleware.rb +40 -0
  125. data/lib/flex_commerce_api/v2/api_base.rb +13 -0
  126. data/lib/flex_commerce_api/version.rb +3 -0
  127. data/lib/json_erb.rb +9 -0
  128. data/lib/json_struct.rb +73 -0
  129. data/lib/patches.rb +4 -0
  130. data/lib/patches/json_api_client/resource.rb +50 -0
  131. data/lib/paypal_express.rb +3 -0
  132. data/lib/paypal_express/additional_info.rb +45 -0
  133. data/lib/paypal_express/api.rb +86 -0
  134. data/lib/paypal_express/auth.rb +83 -0
  135. data/lib/paypal_express/cart_shipping_method.rb +38 -0
  136. data/lib/paypal_express/exception/access_denied.rb +10 -0
  137. data/lib/paypal_express/exception/connection_error.rb +10 -0
  138. data/lib/paypal_express/exception/not_authorized.rb +10 -0
  139. data/lib/paypal_express/exception/transaction.rb +15 -0
  140. data/lib/paypal_express/generate_summary.rb +118 -0
  141. data/lib/paypal_express/process/paypal_params.rb +123 -0
  142. data/lib/paypal_express/process/response_parser.rb +146 -0
  143. data/lib/paypal_express/setup.rb +94 -0
  144. data/lib/paypal_express/shipping_methods_for_cart.rb +46 -0
  145. data/lib/retry.rb +20 -0
  146. data/schemas/jsonapi/schema.json +370 -0
  147. data/schemas/shift/v1/documents/collection/address.json +45 -0
  148. data/schemas/shift/v1/documents/collection/asset_file.json +43 -0
  149. data/schemas/shift/v1/documents/collection/asset_folder.json +43 -0
  150. data/schemas/shift/v1/documents/collection/customer_account.json +50 -0
  151. data/schemas/shift/v1/documents/collection/markdown_price.json +43 -0
  152. data/schemas/shift/v1/documents/collection/product.json +43 -0
  153. data/schemas/shift/v1/documents/collection/variant.json +43 -0
  154. data/schemas/shift/v1/documents/member/address.json +39 -0
  155. data/schemas/shift/v1/documents/member/asset_file.json +37 -0
  156. data/schemas/shift/v1/documents/member/asset_folder.json +39 -0
  157. data/schemas/shift/v1/documents/member/customer_account.json +44 -0
  158. data/schemas/shift/v1/documents/member/markdown_price.json +37 -0
  159. data/schemas/shift/v1/documents/member/product.json +39 -0
  160. data/schemas/shift/v1/documents/member/variant.json +46 -0
  161. data/schemas/shift/v1/resources/address.json +130 -0
  162. data/schemas/shift/v1/resources/asset_file.json +146 -0
  163. data/schemas/shift/v1/resources/asset_folder.json +188 -0
  164. data/schemas/shift/v1/resources/customer_account.json +339 -0
  165. data/schemas/shift/v1/resources/markdown_price.json +52 -0
  166. data/schemas/shift/v1/resources/product.json +230 -0
  167. data/schemas/shift/v1/resources/variant.json +298 -0
  168. data/tasks/json_schema.thor +275 -0
  169. data/todo.md +8 -0
  170. metadata +470 -0
@@ -0,0 +1,298 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "id": {
6
+ "type": "string",
7
+ "description": "A unique identifier for the variant.json"
8
+ },
9
+ "type": {
10
+ "type": "string",
11
+ "description": "The json_api type for any variant.json",
12
+ "pattern": "^variants$"
13
+ },
14
+ "attributes": {
15
+ "type": "object",
16
+ "properties": {
17
+ "meta_attributes": {
18
+ "type": "object",
19
+ "description": "Description for meta_attributes"
20
+ },
21
+ "updated_at": {
22
+ "type": "string",
23
+ "description": "Description for updated_at"
24
+ },
25
+ "created_at": {
26
+ "type": "string",
27
+ "description": "Description for created_at"
28
+ },
29
+ "deleted_at": {
30
+ "type": "null",
31
+ "description": "Description for deleted_at"
32
+ },
33
+ "title": {
34
+ "type": "string",
35
+ "description": "Description for title"
36
+ },
37
+ "description": {
38
+ "type": "string",
39
+ "description": "Description for description"
40
+ },
41
+ "reference": {
42
+ "type": "string",
43
+ "description": "Description for reference"
44
+ },
45
+ "ewis_eligible": {
46
+ "type": "boolean",
47
+ "description": "Description for ewis_eligible"
48
+ },
49
+ "expected_availability_date": {
50
+ "type": "null",
51
+ "description": "Description for expected_availability_date"
52
+ },
53
+ "ordered_total": {
54
+ "type": "number",
55
+ "description": "Description for ordered_total"
56
+ },
57
+ "position": {
58
+ "type": "null",
59
+ "description": "Description for position"
60
+ },
61
+ "price": {
62
+ "type": "number",
63
+ "description": "Description for price"
64
+ },
65
+ "price_includes_taxes": {
66
+ "type": "boolean",
67
+ "description": "Description for price_includes_taxes"
68
+ },
69
+ "product_id": {
70
+ "type": "number",
71
+ "description": "Description for product_id"
72
+ },
73
+ "sku": {
74
+ "type": "string",
75
+ "description": "Description for sku"
76
+ },
77
+ "stock_allocated_level": {
78
+ "type": "number",
79
+ "description": "Description for stock_allocated_level"
80
+ },
81
+ "stock_level": {
82
+ "type": "number",
83
+ "description": "Description for stock_level"
84
+ },
85
+ "tax_code": {
86
+ "type": "null",
87
+ "description": "Description for tax_code"
88
+ },
89
+ "current_price": {
90
+ "type": "number",
91
+ "description": "Description for current_price"
92
+ },
93
+ "stock_available_level": {
94
+ "type": "number",
95
+ "description": "Description for stock_available_level"
96
+ },
97
+ "has_assets": {
98
+ "type": "boolean",
99
+ "description": "Description for has_assets"
100
+ },
101
+ "available_to_browse": {
102
+ "type": "boolean",
103
+ "description": "Description for available_to_browse"
104
+ },
105
+ "available_to_order": {
106
+ "type": "boolean",
107
+ "description": "Description for available_to_order"
108
+ },
109
+ "picture_url": {
110
+ "type": ["null","string"],
111
+ "description": "Description for picture_url"
112
+ }
113
+ }
114
+ },
115
+ "relationships": {
116
+ "type": "object",
117
+ "properties": {
118
+ "product": {
119
+ "type": "object",
120
+ "properties": {
121
+ "links": {
122
+ "type": "object",
123
+ "properties": {
124
+ "self": {
125
+ "type": "string"
126
+ },
127
+ "related": {
128
+ "type": "string"
129
+ }
130
+ },
131
+ "additionalProperties": false
132
+ },
133
+ "data": {
134
+ "oneOf": [
135
+ {
136
+ "type": "object",
137
+ "description": "The id and type form a pointer into the 'included' top level document property",
138
+ "properties": {
139
+ "id": {
140
+ "type": "string"
141
+ },
142
+ "type": {
143
+ "type": "string"
144
+ }
145
+ },
146
+ "additionalProperties": false
147
+ },
148
+ {
149
+ "type": "array",
150
+ "items": {
151
+ "type": "object",
152
+ "description": "The id and type form a pointer into the 'included' top level document property",
153
+ "properties": {
154
+ "id": {
155
+ "type": "string"
156
+ },
157
+ "type": {
158
+ "type": "string"
159
+ }
160
+ },
161
+ "additionalProperties": false
162
+ }
163
+ }
164
+ ]
165
+ },
166
+ "meta": {
167
+ "type": "object",
168
+ "additionalProperties": true
169
+ }
170
+ }
171
+ },
172
+ "asset_files": {
173
+ "type": "object",
174
+ "properties": {
175
+ "links": {
176
+ "type": "object",
177
+ "properties": {
178
+ "self": {
179
+ "type": "string"
180
+ },
181
+ "related": {
182
+ "type": "string"
183
+ }
184
+ },
185
+ "additionalProperties": false
186
+ },
187
+ "data": {
188
+ "oneOf": [
189
+ {
190
+ "type": "object",
191
+ "description": "The id and type form a pointer into the 'included' top level document property",
192
+ "properties": {
193
+ "id": {
194
+ "type": "string"
195
+ },
196
+ "type": {
197
+ "type": "string"
198
+ }
199
+ },
200
+ "additionalProperties": false
201
+ },
202
+ {
203
+ "type": "array",
204
+ "items": {
205
+ "type": "object",
206
+ "description": "The id and type form a pointer into the 'included' top level document property",
207
+ "properties": {
208
+ "id": {
209
+ "type": "string"
210
+ },
211
+ "type": {
212
+ "type": "string"
213
+ }
214
+ },
215
+ "additionalProperties": false
216
+ }
217
+ }
218
+ ]
219
+ },
220
+ "meta": {
221
+ "type": "object",
222
+ "additionalProperties": true
223
+ }
224
+ }
225
+ },
226
+ "markdown_prices": {
227
+ "type": "object",
228
+ "properties": {
229
+ "links": {
230
+ "type": "object",
231
+ "properties": {
232
+ "self": {
233
+ "type": "string"
234
+ },
235
+ "related": {
236
+ "type": "string"
237
+ }
238
+ },
239
+ "additionalProperties": false
240
+ },
241
+ "data": {
242
+ "oneOf": [
243
+ {
244
+ "type": "object",
245
+ "description": "The id and type form a pointer into the 'included' top level document property",
246
+ "properties": {
247
+ "id": {
248
+ "type": "string"
249
+ },
250
+ "type": {
251
+ "type": "string"
252
+ }
253
+ },
254
+ "additionalProperties": false
255
+ },
256
+ {
257
+ "type": "array",
258
+ "items": {
259
+ "type": "object",
260
+ "description": "The id and type form a pointer into the 'included' top level document property",
261
+ "properties": {
262
+ "id": {
263
+ "type": "string"
264
+ },
265
+ "type": {
266
+ "type": "string"
267
+ }
268
+ },
269
+ "additionalProperties": false
270
+ }
271
+ }
272
+ ]
273
+ },
274
+ "meta": {
275
+ "type": "object",
276
+ "additionalProperties": true
277
+ }
278
+ }
279
+ }
280
+ }
281
+ },
282
+ "links": {
283
+ "type": "object",
284
+ "properties": {
285
+ "self": {
286
+ "type": "string"
287
+ }
288
+ },
289
+ "additionalProperties": false
290
+ },
291
+ "meta": {
292
+ "type": "object",
293
+ "additionalProperties": false
294
+ }
295
+ },
296
+ "definitions": {
297
+ }
298
+ }
@@ -0,0 +1,275 @@
1
+ require "json"
2
+ require "active_support/core_ext/string"
3
+ class JsonSchema < Thor
4
+ desc "generate_from_vcr", "Given a json encoded vcr file, produces a json schema compatible schema."
5
+
6
+ def generate_from_vcr(output_file, input_file, thing = output_file)
7
+ interaction = JSON.parse(File.read(input_file))["http_interactions"].first
8
+ data = interaction.dig("response", "body", "decoded")
9
+ node = data["data"] # This will be different for a collection
10
+ version = get_version_from_uri(interaction.dig("request", "uri"))
11
+ base_dir = File.expand_path("../schemas/shift/#{version}", File.dirname(__FILE__))
12
+
13
+ generate_resource_schema(node, File.join(base_dir, "resources", output_file), thing)
14
+ generate_collection_document_schema(data, File.join(base_dir, "documents", "collection", output_file), thing)
15
+ generate_member_document_schema(data, File.join(base_dir, "documents", "member", output_file), thing)
16
+ end
17
+
18
+ private
19
+
20
+ def generate_collection_document_schema(data, full_filename, thing)
21
+ schema = {
22
+ "$schema": "http://json-schema.org/draft-04/schema#",
23
+ "type": "object",
24
+ properties: {
25
+ data: {
26
+ type: "array",
27
+ items: {
28
+ "$ref": "#/definitions/resource"
29
+ }
30
+ },
31
+ meta: {
32
+ type: "object",
33
+ additionalProperties: true
34
+ },
35
+ jsonapi: {
36
+ type: "object"
37
+ },
38
+ links: {
39
+ type: "object"
40
+ },
41
+ included: {
42
+ type: "array",
43
+ items: {
44
+ "$ref": "#/definitions/includedItems"
45
+ }
46
+ }
47
+ },
48
+ required: ["data", "meta"],
49
+ additionalProperties: false,
50
+ definitions: {
51
+ resource: {"$ref": "../../resources/#{File.basename(full_filename)}"},
52
+ includedItems: {
53
+ oneOf: detect_used_items_in_included_data(data)
54
+ }
55
+ }
56
+ }
57
+ FileUtils.mkdir_p(File.dirname(full_filename))
58
+ File.open(full_filename, "w") { |file| file.write("#{JSON.pretty_generate(schema)}") }
59
+ end
60
+
61
+ def detect_used_items_in_included_data(data)
62
+ return [] unless data.key?("included")
63
+ data["included"].map do |node|
64
+ {
65
+ "$ref": "../../resources/#{node['type'].singularize}.json"
66
+ }
67
+ end
68
+ end
69
+
70
+ def generate_member_document_schema(data, full_filename, thing)
71
+ schema = {
72
+ "$schema": "http://json-schema.org/draft-04/schema#",
73
+ "type": "object",
74
+ properties: {
75
+ data: {
76
+ type: "object",
77
+ "$ref": "#/definitions/resource"
78
+ },
79
+ meta: {
80
+ type: "object",
81
+ additionalProperties: true
82
+ },
83
+ jsonapi: {
84
+ type: "object"
85
+ },
86
+ links: {
87
+ type: "object"
88
+ },
89
+ included: {
90
+ type: "array",
91
+ items: {
92
+ "$ref": "#/definitions/includedItems"
93
+ }
94
+ }
95
+ },
96
+ additionalProperties: false,
97
+ definitions: {
98
+ resource: {"$ref": "../../resources/#{File.basename(full_filename)}"},
99
+ includedItems: {
100
+ oneOf: detect_used_items_in_included_data(data)
101
+ }
102
+ }
103
+ }
104
+ FileUtils.mkdir_p(File.dirname(full_filename))
105
+ File.open(full_filename, "w") { |file| file.write("#{JSON.pretty_generate(schema)}") }
106
+ end
107
+
108
+ def generate_resource_schema(node, full_filename, thing)
109
+ schema = {
110
+ "$schema": "http://json-schema.org/draft-04/schema#",
111
+ "type": "object",
112
+ "properties": {
113
+ "id": {
114
+ "type": "string",
115
+ "description": "A unique identifier for the #{thing}"
116
+ },
117
+ "type": {
118
+ "type": "string",
119
+ "description": "The json_api type for any #{thing}",
120
+ "pattern": "^#{node["type"]}$"
121
+ },
122
+ "attributes": {
123
+ "type": "object",
124
+ "properties": properties_for_attributes(node)
125
+ },
126
+ "relationships": {
127
+ "type": "object",
128
+ "properties": properties_for_relationships(node)
129
+ },
130
+ "links": {
131
+ "type": "object",
132
+ "properties": {
133
+ "self": {
134
+ "type": "string"
135
+ }
136
+ },
137
+ "additionalProperties": false
138
+ },
139
+ "meta": {
140
+ "type": "object",
141
+ "additionalProperties": false
142
+ }
143
+ },
144
+ "definitions": {
145
+
146
+ }
147
+ }
148
+
149
+ FileUtils.mkdir_p(File.dirname(full_filename))
150
+ File.open(full_filename, "w") { |file| file.write("#{JSON.pretty_generate(schema)}") }
151
+ end
152
+
153
+ def get_version_from_uri(uri)
154
+ URI.parse(uri).path.split("/").reject { |node| node=="" }[1]
155
+ end
156
+
157
+ def properties_for_attributes(node)
158
+ node["attributes"].reduce({}) do |acc, (attribute, value)|
159
+ acc.merge attribute => guess_type_def_for(attribute, value)
160
+ end
161
+ end
162
+
163
+ def properties_for_relationships(node)
164
+ return {} if node["relationships"].nil?
165
+ node["relationships"].reduce({}) do |acc, (relationship, definition)|
166
+ acc.merge relationship => {
167
+ type: "object",
168
+ properties: {
169
+ "links": {
170
+ "type": "object",
171
+ "properties": {
172
+ "self": {
173
+ "type": "string",
174
+ },
175
+ "related": {
176
+ "type": "string"
177
+ }
178
+ },
179
+ "additionalProperties": false
180
+ },
181
+ "data": guess_data_type_for_relationship(relationship, definition),
182
+ "meta": {
183
+ "type": "object",
184
+ "additionalProperties": true
185
+ }
186
+ }
187
+ }
188
+ end
189
+ end
190
+
191
+ def guess_type_def_for(attribute, value)
192
+ case value
193
+ when TrueClass, FalseClass
194
+ {
195
+ "type": "boolean",
196
+ "description": "Description for #{attribute}"
197
+ }
198
+ when Numeric
199
+ {
200
+ "type": "number",
201
+ "description": "Description for #{attribute}"
202
+ }
203
+ when Hash
204
+ {
205
+ "type": "object",
206
+ "description": "Description for #{attribute}"
207
+ }
208
+ when NilClass
209
+ {
210
+ "type": "null",
211
+ "description": "Description for #{attribute}"
212
+ }
213
+ when Array
214
+ {
215
+ "type": "array",
216
+ "description": "Description for #{attribute}"
217
+ }
218
+ when String
219
+ {
220
+ "type": "string",
221
+ "description": "Description for #{attribute}"
222
+ }
223
+ else
224
+ raise "Type #{value.class.name} unknown"
225
+ end
226
+ end
227
+
228
+ def guess_data_type_for_relationship(relationship, definition)
229
+ if definition.key?("data")
230
+ definition["data"].is_a?(Array) ? array_relationship_data : singular_relationship_data
231
+ else
232
+ {
233
+ "oneOf": [
234
+ singular_relationship_data,
235
+ array_relationship_data
236
+ ]
237
+ }
238
+ end
239
+ end
240
+
241
+ def array_relationship_data
242
+ {
243
+ "type": "array",
244
+ "items": {
245
+ "type": "object",
246
+ "description": "The id and type form a pointer into the 'included' top level document property",
247
+ "properties": {
248
+ "id": {
249
+ "type": "string"
250
+ },
251
+ "type": {
252
+ "type": "string"
253
+ }
254
+ },
255
+ "additionalProperties": false
256
+ }
257
+ }
258
+ end
259
+
260
+ def singular_relationship_data
261
+ {
262
+ "type": "object",
263
+ "description": "The id and type form a pointer into the 'included' top level document property",
264
+ "properties": {
265
+ "id": {
266
+ "type": "string"
267
+ },
268
+ "type": {
269
+ "type": "string"
270
+ }
271
+ },
272
+ "additionalProperties": false
273
+ }
274
+ end
275
+ end