insights-api-common 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6498652170c68a06887694e324b8864d318390fc8e5f86f827cb310111c0c71
4
- data.tar.gz: 36bf35a644fca5018e0e4a9870bf17d7db4e4b0bf6dde2edaf9e94d17730f653
3
+ metadata.gz: a539b3339e7b65eb26ab1920ab25bc151125250f80a7d03e856981685323149d
4
+ data.tar.gz: 1f72cb479407b8407fc802d668641bcf6a05bdab3bc250dcab339694a8388e61
5
5
  SHA512:
6
- metadata.gz: 1b7e883f0a2d5b617892e880ad061c044afa56644e0a2e4da05e7069b45adec29e1a027e9215c001e086dc7d0fddeec0c62d3a110a63e358cb8bdea321ce9155
7
- data.tar.gz: c12ce153ce3acfcf141a51609f93f62209c954305070b8fa24574190080e27f032f5b5ca42dbe04e88fbc3109d871570d48522f31b6d98d0077ee0531ee62c9d
6
+ metadata.gz: 5b6c6bc264eff66c71a00e9147217c93cf4681d97d1694c3145e78b9f3576f70bfec6f1a7c40f1baa94573970bd4250e07eb5bd1fe55b6239142559f21c8fc8a
7
+ data.tar.gz: 7922ce22df6e493ca3b45d2853450f887fc2679011c1d23542d8519d0f531d273ba29b9c27e6ca3f4ad3a0353497fb544f0de8340ba815634cfde9f734f9704f
@@ -17,10 +17,13 @@ module Insights
17
17
  private
18
18
 
19
19
  def body_params
20
- @body_params ||= begin
21
- raw_body = request.body.read
22
- parsed_body = raw_body.blank? ? {} : JSON.parse(raw_body)
23
- ActionController::Parameters.new(parsed_body).permit!
20
+ @body_params ||= ActionController::Parameters.new(parsed_body).permit!
21
+ end
22
+
23
+ def parsed_body
24
+ @parsed_body ||= begin
25
+ request_body = request.body.read
26
+ request_body.blank? ? {} : JSON.parse(request_body)
24
27
  rescue JSON::ParserError
25
28
  raise Insights::API::Common::ApplicationControllerMixins::RequestBodyValidation::BodyParseError, "Failed to parse request body, expected JSON"
26
29
  end
@@ -38,7 +41,7 @@ module Insights
38
41
  request.method,
39
42
  request.path,
40
43
  api_version,
41
- body_params.as_json
44
+ parsed_body
42
45
  )
43
46
  end
44
47
  end
@@ -304,20 +304,59 @@ module Insights
304
304
  }
305
305
  end
306
306
 
307
+ def openapi_tag_description(klass_name)
308
+ {
309
+ "summary" => "Tag a #{klass_name}",
310
+ "operationId" => "tag#{klass_name}",
311
+ "description" => "Tags a #{klass_name} object",
312
+ "parameters" => [
313
+ { "$ref" => build_parameter("ID") }
314
+ ],
315
+ "requestBody" => request_body("Tag", "add", :single => false),
316
+ "responses" => {
317
+ "201" => {
318
+ "description" => "#{klass_name} tagged successful",
319
+ "content" => {
320
+ "application/json" => {
321
+ "schema" => {
322
+ "type" => "array",
323
+ "items" => {
324
+ "$ref" => build_schema("Tag")
325
+ }
326
+ }
327
+ }
328
+ }
329
+ },
330
+ "304" => {
331
+ "description" => "Not modified"
332
+ }
333
+ }
334
+ }
335
+ end
336
+
337
+ def openapi_untag_description(klass_name)
338
+ {
339
+ "summary" => "Untag a #{klass_name}",
340
+ "operationId" => "untag#{klass_name}",
341
+ "description" => "Untags a #{klass_name} object",
342
+ "parameters" => [
343
+ { "$ref" => build_parameter("ID") }
344
+ ],
345
+ "requestBody" => request_body("Tag", "removed", :single => false),
346
+ "responses" => {
347
+ "204" => {
348
+ "description" => "#{klass_name} untagged successfully",
349
+ }
350
+ }
351
+ }
352
+ end
353
+
307
354
  def openapi_create_description(klass_name)
308
355
  {
309
356
  "summary" => "Create a new #{klass_name}",
310
357
  "operationId" => "create#{klass_name}",
311
358
  "description" => "Creates a #{klass_name} object",
312
- "requestBody" => {
313
- "content" => {
314
- "application/json" => {
315
- "schema" => { "$ref" => build_schema(klass_name) }
316
- }
317
- },
318
- "description" => "#{klass_name} attributes to create",
319
- "required" => true
320
- },
359
+ "requestBody" => request_body(klass_name, "create"),
321
360
  "responses" => {
322
361
  "201" => {
323
362
  "description" => "#{klass_name} creation successful",
@@ -331,6 +370,20 @@ module Insights
331
370
  }
332
371
  end
333
372
 
373
+ def request_body(klass_name, action, single: true)
374
+ schema = single ? { "$ref" => build_schema(klass_name) } : {"type" => "array", "items" => {"$ref" => build_schema(klass_name)}}
375
+
376
+ {
377
+ "content" => {
378
+ "application/json" => {
379
+ "schema" => schema
380
+ }
381
+ },
382
+ "description" => "#{klass_name} attributes to #{action}",
383
+ "required" => true
384
+ }
385
+ end
386
+
334
387
  def openapi_update_description(klass_name, verb)
335
388
  action = verb == "patch" ? "Update" : "Replace"
336
389
  {
@@ -340,15 +393,7 @@ module Insights
340
393
  "parameters" => [
341
394
  { "$ref" => build_parameter("ID") }
342
395
  ],
343
- "requestBody" => {
344
- "content" => {
345
- "application/json" => {
346
- "schema" => { "$ref" => build_schema(klass_name) }
347
- }
348
- },
349
- "description" => "#{klass_name} attributes to update",
350
- "required" => true
351
- },
396
+ "requestBody" => request_body(klass_name, "update"),
352
397
  "responses" => {
353
398
  "204" => { "description" => "Updated, no content" },
354
399
  "400" => { "description" => "Bad request" },
@@ -490,6 +535,8 @@ module Insights
490
535
  when "destroy" then openapi_destroy_description(klass_name)
491
536
  when "create" then openapi_create_description(klass_name)
492
537
  when "update" then openapi_update_description(klass_name, verb)
538
+ when "tag" then openapi_tag_description(primary_collection)
539
+ when "untag" then openapi_untag_description(primary_collection)
493
540
  else handle_custom_route_action(route.action.camelize, verb, primary_collection)
494
541
  end
495
542
 
@@ -1,7 +1,7 @@
1
1
  module Insights
2
2
  module API
3
3
  module Common
4
- VERSION = "3.1.0".freeze
4
+ VERSION = "3.2.0".freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insights-api-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Insights Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-13 00:00:00.000000000 Z
11
+ date: 2019-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_tenant