insights-api-common 3.0.0 → 3.1.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: dc3e9311fa97474f63d69e67945cc243bac2f249ab67ab7055e45212727fc130
4
- data.tar.gz: 88aabb5afa5ddf89aafe5401342a6954c84523f6f4ecb6b77652b136c4bc58b6
3
+ metadata.gz: b6498652170c68a06887694e324b8864d318390fc8e5f86f827cb310111c0c71
4
+ data.tar.gz: 36bf35a644fca5018e0e4a9870bf17d7db4e4b0bf6dde2edaf9e94d17730f653
5
5
  SHA512:
6
- metadata.gz: 933e547ddc3cab50a6b78051be51195d1ebccb32a48acfcf369429a2a7b751b3a4ba0bd7050496117bcaef5ec238b57e8b5320d70d445748891444143e8fccb5
7
- data.tar.gz: bd10b8a9bd50bfe2e7fa90500e733d4517bb48a710582e0a251a33b83ba083dc27e42ea02285df5ae36c633b8a6c49f6640dd9176b0e4090f8ad880a5813eed1
6
+ metadata.gz: 1b7e883f0a2d5b617892e880ad061c044afa56644e0a2e4da05e7069b45adec29e1a027e9215c001e086dc7d0fddeec0c62d3a110a63e358cb8bdea321ce9155
7
+ data.tar.gz: c12ce153ce3acfcf141a51609f93f62209c954305070b8fa24574190080e27f032f5b5ca42dbe04e88fbc3109d871570d48522f31b6d98d0077ee0531ee62c9d
@@ -25,7 +25,7 @@ module Insights
25
25
  end
26
26
 
27
27
  def api_doc_definition
28
- @api_doc_definition ||= api_doc.definitions[model.name]
28
+ @api_doc_definition ||= api_doc.definitions[name.split("::").last[0..-11].singularize]
29
29
  end
30
30
 
31
31
  def api_version
@@ -419,7 +419,7 @@ module Insights
419
419
  new_content = openapi_contents.dup
420
420
  new_content["paths"] = build_paths.sort.to_h
421
421
  new_content["components"] ||= {}
422
- new_content["components"]["schemas"] = schemas.sort.each_with_object({}) { |(name, val), h| h[name] = val || openapi_contents["components"]["schemas"][name] || {} }
422
+ new_content["components"]["schemas"] = schemas.merge(schema_overrides).sort.each_with_object({}) { |(name, val), h| h[name] = val || openapi_contents["components"]["schemas"][name] || {} }
423
423
  new_content["components"]["parameters"] = parameters.sort.each_with_object({}) { |(name, val), h| h[name] = val || openapi_contents["components"]["parameters"][name] || {} }
424
424
  File.write(openapi_file, JSON.pretty_generate(new_content) + "\n")
425
425
  Insights::API::Common::GraphQL::Generator.generate(api_version, new_content) if graphql
@@ -438,6 +438,8 @@ module Insights
438
438
  [key, openapi_schema_properties_value(klass_name, model, key, value)]
439
439
  end
440
440
  end.compact.sort.to_h
441
+ rescue NameError
442
+ openapi_contents["components"]["schemas"][klass_name]["properties"]
441
443
  end
442
444
 
443
445
  def generator_blacklist_attributes
@@ -472,10 +474,12 @@ module Insights
472
474
 
473
475
  def build_paths
474
476
  applicable_rails_routes.each_with_object({}) do |route, expected_paths|
475
- without_format = route.path.split("(.:format)").first
476
- sub_path = without_format.split(base_path).last.sub(/:[_a-z]*id/, "{id}")
477
- klass_name = route.controller.split("/").last.camelize.singularize
478
- verb = route.verb.downcase
477
+ without_format = route.path.split("(.:format)").first
478
+ sub_path = without_format.split(base_path).last.sub(/:[_a-z]*id/, "{id}")
479
+ route_destination = route.controller.split("/").last.camelize
480
+ controller = "Api::V#{api_version.sub(".", "x")}::#{route_destination}Controller".safe_constantize
481
+ klass_name = controller.try(:presentation_name) || route_destination.singularize
482
+ verb = route.verb.downcase
479
483
  primary_collection = sub_path.split("/")[1].camelize.singularize
480
484
 
481
485
  expected_paths[sub_path] ||= {}
@@ -513,6 +517,10 @@ module Insights
513
517
 
514
518
  def handle_custom_route_action(_route_action, _verb, _primary_collection)
515
519
  end
520
+
521
+ def schema_overrides
522
+ {}
523
+ end
516
524
  end
517
525
  end
518
526
  end
@@ -9,7 +9,8 @@ module Insights
9
9
  encryption_filtered = previous.except(*encrypted_columns_set)
10
10
  return encryption_filtered unless arg.key?(:prefixes)
11
11
  version = api_version_from_prefix(arg[:prefixes].first)
12
- schema = ::Insights::API::Common::OpenApi::Docs.instance[version].definitions[self.class.name]
12
+ presentation_name = self.class.try(:presentation_name) || self.class.name
13
+ schema = ::Insights::API::Common::OpenApi::Docs.instance[version].definitions[presentation_name]
13
14
  attrs = encryption_filtered.slice(*schema["properties"].keys)
14
15
  schema["properties"].keys.each do |name|
15
16
  next if attrs[name].nil?
@@ -1,7 +1,7 @@
1
1
  module Insights
2
2
  module API
3
3
  module Common
4
- VERSION = "3.0.0".freeze
4
+ VERSION = "3.1.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.0.0
4
+ version: 3.1.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-08 00:00:00.000000000 Z
11
+ date: 2019-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_tenant