grape-swagger-entity 0.4.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9cbc9a4f5350f907024319ec60d6bebcf58c1d9a9fbe0a87157eb521f5d90c27
4
- data.tar.gz: d70650e560a98a5c8e6299136146796d87bb8e124944c2b09603ddcab415085a
3
+ metadata.gz: 45d768ff8d366802a511df94e675aed675d4961c965ac39a130df0e5a5a47f73
4
+ data.tar.gz: 29289e700cb29cd5d7078b58e04bb284c5ccad4da1f12e24917d31351cb2210c
5
5
  SHA512:
6
- metadata.gz: 4fffce9cc2ae49583807c9e02a5ed6d0c6fdbd1e3acc2f4816868b292fb8ae0e77161bd4736dcb2d91e30633a814cd8fd31c2f21af9fec12cc4cec8243bb5ce1
7
- data.tar.gz: 2c5cdf2184fefbd92fda6b7f65d95d31f0c331e225be2439b5fa2f6d711a7754890271b7a41b06cdd36c44d3bcace9b836cd727c93b21892e6ae9651badb712a
6
+ metadata.gz: f1f7cb9609b3412b6fb624aaae0346b34549349a40f7912d1c72131fa7c905f47f8307928edb18dbcbc3ba6cefed34ecd861c125b60b45d8cbe1f4633a036199
7
+ data.tar.gz: b64399e310447774459e470cb7e9aa1621e2c544641ef16c6ec2e8a3a8cb472fff9cd8e33167a2b61d4939932aaca065172b01526ad099f0011fe989b2e4cdb0
@@ -2,7 +2,7 @@ AllCops:
2
2
  Exclude:
3
3
  - vendor/**/*
4
4
  TargetRubyVersion:
5
- 2.2
5
+ 2.7
6
6
 
7
7
  inherit_from: .rubocop_todo.yml
8
8
 
@@ -21,5 +21,34 @@ Metrics/MethodLength:
21
21
  Naming/FileName:
22
22
  Enabled: false
23
23
 
24
- Layout/IndentFirstHashElement:
24
+ Layout/FirstHashElementIndentation:
25
25
  EnforcedStyle: consistent
26
+
27
+ Layout/EmptyLinesAroundAttributeAccessor:
28
+ Enabled: true
29
+ Layout/SpaceAroundMethodCallOperator:
30
+ Enabled: true
31
+ Lint/DeprecatedOpenSSLConstant:
32
+ Enabled: true
33
+ Lint/MixedRegexpCaptureTypes:
34
+ Enabled: true
35
+ Lint/RaiseException:
36
+ Enabled: true
37
+ Lint/StructNewOverride:
38
+ Enabled: true
39
+ Style/ExponentialNotation:
40
+ Enabled: true
41
+ Style/HashEachMethods:
42
+ Enabled: true
43
+ Style/HashTransformKeys:
44
+ Enabled: true
45
+ Style/HashTransformValues:
46
+ Enabled: true
47
+ Style/RedundantFetchBlock:
48
+ Enabled: true
49
+ Style/RedundantRegexpCharacterClass:
50
+ Enabled: true
51
+ Style/RedundantRegexpEscape:
52
+ Enabled: true
53
+ Style/SlicingWithRange:
54
+ Enabled: true
@@ -1,49 +1,48 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2017-07-03 22:59:40 +0300 using RuboCop version 0.49.1.
3
+ # on 2020-06-29 22:12:50 UTC using RuboCop version 0.86.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 2
10
- Metrics/AbcSize:
11
- Max: 40
12
-
13
9
  # Offense count: 1
14
- # Configuration parameters: CountComments, ExcludedMethods.
15
- Metrics/BlockLength:
16
- Max: 27
10
+ # Configuration parameters: Include.
11
+ # Include: **/*.gemspec
12
+ Gemspec/RequiredRubyVersion:
13
+ Exclude:
14
+ - 'grape-swagger-entity.gemspec'
15
+
16
+ # Offense count: 4
17
+ # Configuration parameters: IgnoredMethods.
18
+ Metrics/AbcSize:
19
+ Max: 30
17
20
 
18
21
  # Offense count: 1
19
22
  # Configuration parameters: CountComments.
20
23
  Metrics/ClassLength:
21
- Max: 124
24
+ Max: 111
22
25
 
23
- # Offense count: 1
26
+ # Offense count: 2
27
+ # Configuration parameters: IgnoredMethods.
24
28
  Metrics/CyclomaticComplexity:
25
- Max: 15
26
-
27
- # Offense count: 14
28
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
29
- # URISchemes: http, https
30
- Metrics/LineLength:
31
- Max: 120
29
+ Max: 11
32
30
 
33
- # Offense count: 3
34
- # Configuration parameters: CountComments.
31
+ # Offense count: 5
32
+ # Configuration parameters: CountComments, ExcludedMethods.
35
33
  Metrics/MethodLength:
36
- Max: 30
34
+ Max: 25
37
35
 
38
36
  # Offense count: 2
37
+ # Configuration parameters: IgnoredMethods.
39
38
  Metrics/PerceivedComplexity:
40
- Max: 16
39
+ Max: 12
41
40
 
42
- # Offense count: 2
41
+ # Offense count: 4
43
42
  Style/Documentation:
44
43
  Exclude:
45
44
  - 'spec/**/*'
46
45
  - 'test/**/*'
47
46
  - 'lib/grape-swagger/entity.rb'
48
- - 'lib/grape-swagger/entity/parser.rb'
49
47
  - 'lib/grape-swagger/entity/attribute_parser.rb'
48
+ - 'lib/grape-swagger/entity/parser.rb'
@@ -10,29 +10,27 @@ after_success:
10
10
  - bundle exec danger
11
11
 
12
12
  rvm:
13
- - 2.4.5
14
- - 2.5.3
15
- - 2.6.0
13
+ - 2.5.8
14
+ - 2.6.6
15
+ - 2.7.1
16
16
 
17
17
  env:
18
18
  - GRAPE_ENTITY=0.6.1
19
19
  - GRAPE_ENTITY=0.7.1
20
+ - GRAPE_ENTITY=0.8.0
20
21
 
21
22
  matrix:
22
23
  fast_finish: true
23
24
 
24
25
  include:
25
- - rvm: 2.3.8
26
+ - rvm: 2.4.10
26
27
  env:
27
28
  - rvm: ruby-head
28
29
  env:
29
30
  - rvm: jruby-head
30
31
  env:
31
- - rvm: rbx-2
32
- env:
33
32
 
34
33
  allow_failures:
35
- - rvm: 2.3.8
34
+ - rvm: 2.4.10
36
35
  - rvm: ruby-head
37
36
  - rvm: jruby-head
38
- - rvm: rbx-2
@@ -4,10 +4,20 @@
4
4
 
5
5
  * Your contribution here.
6
6
 
7
- #### Features
7
+ #### Fixes
8
8
 
9
9
  * Your contribution here.
10
10
 
11
+ ### 0.5.1 (June 30, 2020)
12
+
13
+ #### Features
14
+
15
+ * [#50](https://github.com/ruby-grape/grape-swagger-entity/pull/50): Features/inheritance and discriminator - [@MaximeRDY](https://github.com/MaximeRDY).
16
+
17
+ ### 0.5.0 (June 29, 2020)
18
+
19
+ Yanked due to invalid dependency
20
+
11
21
  ### 0.4.0 (May 30, 2020)
12
22
 
13
23
  #### Features
data/Dangerfile CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  danger.import_dangerfile(gem: 'ruby-grape-danger')
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in grape-swagger-entity.gemspec
@@ -12,8 +14,8 @@ group :development, :test do
12
14
  gem 'rack-test'
13
15
  gem 'rake'
14
16
  gem 'rdoc'
15
- gem 'rspec', '~> 3.0'
16
- gem 'rubocop', '~> 0.68.1'
17
+ gem 'rspec', '~> 3.9'
18
+ gem 'rubocop', '~> 0.85'
17
19
  end
18
20
 
19
21
  gem 'grape-swagger', git: 'https://github.com/ruby-grape/grape-swagger.git'
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'bundler'
3
5
 
data/bin/pry CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'grape-swagger/entity'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'grape-swagger/entity/version'
@@ -17,7 +19,7 @@ Gem::Specification.new do |s|
17
19
  s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
20
  s.require_paths = ['lib']
19
21
 
20
- s.required_ruby_version = '>= 2.2.6'
21
- s.add_runtime_dependency 'grape-entity', '>= 0.5.0'
22
- s.add_runtime_dependency 'grape-swagger', '>= 1.0.0'
22
+ s.required_ruby_version = '>= 2.4'
23
+ s.add_runtime_dependency 'grape-entity', '>= 0.6.0'
24
+ s.add_runtime_dependency 'grape-swagger', '>= 1.2.0'
23
25
  end
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'grape-swagger/entity'
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'grape-swagger'
2
4
  require 'grape-entity'
3
5
 
4
6
  require 'grape-swagger/entity/version'
7
+ require 'grape-swagger/entity/helper'
5
8
  require 'grape-swagger/entity/attribute_parser'
6
9
  require 'grape-swagger/entity/parser'
7
10
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrapeSwagger
2
4
  module Entity
3
5
  class AttributeParser
@@ -12,7 +14,7 @@ module GrapeSwagger
12
14
  entity_model = model_from(entity_options)
13
15
 
14
16
  if entity_model
15
- name = endpoint.nil? ? entity_model.to_s.demodulize : endpoint.send(:expose_params_from_model, entity_model)
17
+ name = GrapeSwagger::Entity::Helper.model_name(entity_model, endpoint)
16
18
 
17
19
  entity_model_type = entity_model_type(name, entity_options)
18
20
  return entity_model_type unless documentation
@@ -39,7 +41,7 @@ module GrapeSwagger
39
41
  add_attribute_documentation(param, documentation)
40
42
 
41
43
  add_extension_documentation(param, documentation)
42
-
44
+ add_discriminator_extension(param, documentation)
43
45
  param
44
46
  end
45
47
  end
@@ -65,8 +67,7 @@ module GrapeSwagger
65
67
  end
66
68
 
67
69
  def ambiguous_model_type?(type)
68
- type &&
69
- type.is_a?(Class) &&
70
+ type&.is_a?(Class) &&
70
71
  !GrapeSwagger::DocMethods::DataType.primitive?(type.name.downcase) &&
71
72
  !type == Array
72
73
  end
@@ -87,7 +88,7 @@ module GrapeSwagger
87
88
  else
88
89
  { type: data_type }
89
90
  end
90
- type[:format] = documentation[:format] if documentation && documentation.key?(:format)
91
+ type[:format] = documentation[:format] if documentation&.key?(:format)
91
92
 
92
93
  type
93
94
  end
@@ -128,6 +129,10 @@ module GrapeSwagger
128
129
  def add_extension_documentation(param, documentation)
129
130
  GrapeSwagger::DocMethods::Extensions.add_extensions_to_root(documentation, param)
130
131
  end
132
+
133
+ def add_discriminator_extension(param, documentation)
134
+ param[:documentation] = { is_discriminator: true } if documentation.key?(:is_discriminator)
135
+ end
131
136
  end
132
137
  end
133
138
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GrapeSwagger
4
+ module Entity
5
+ # Helper methods for DRY
6
+ class Helper
7
+ class << self
8
+ def model_name(entity_model, endpoint)
9
+ if endpoint.nil?
10
+ entity_model.to_s.demodulize
11
+ else
12
+ endpoint.send(:expose_params_from_model, entity_model)
13
+ end
14
+ end
15
+
16
+ def discriminator(entity_model)
17
+ entity_model.superclass.root_exposures.detect do |value|
18
+ value.documentation&.dig(:is_discriminator)
19
+ end
20
+ end
21
+
22
+ def root_exposures_without_parent(entity_model)
23
+ entity_model.root_exposures.select do |value|
24
+ entity_model.superclass.root_exposures.find_by(value.attribute).nil?
25
+ end
26
+ end
27
+
28
+ def root_exposure_with_discriminator(entity_model)
29
+ if discriminator(entity_model)
30
+ root_exposures_without_parent(entity_model)
31
+ else
32
+ entity_model.root_exposures
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrapeSwagger
2
4
  module Entity
3
5
  class Parser
@@ -19,6 +21,7 @@ module GrapeSwagger
19
21
 
20
22
  class Alias
21
23
  attr_reader :original, :renamed
24
+
22
25
  def initialize(original, renamed)
23
26
  @original = original
24
27
  @renamed = renamed
@@ -26,7 +29,7 @@ module GrapeSwagger
26
29
  end
27
30
 
28
31
  def extract_params(exposure)
29
- exposure.root_exposures.each_with_object({}) do |value, memo|
32
+ GrapeSwagger::Entity::Helper.root_exposure_with_discriminator(exposure).each_with_object({}) do |value, memo|
30
33
  if value.for_merge && (value.respond_to?(:entity_class) || value.respond_to?(:using_class_name))
31
34
  entity_class = value.respond_to?(:entity_class) ? value.entity_class : value.using_class_name
32
35
 
@@ -64,7 +67,39 @@ module GrapeSwagger
64
67
  memo[final_entity_name][:description] = documentation[:desc] if documentation[:desc]
65
68
  end
66
69
 
67
- [parsed, required_params(params)]
70
+ discriminator = GrapeSwagger::Entity::Helper.discriminator(model)
71
+ if discriminator
72
+ respond_with_all_of(parsed, params, discriminator)
73
+ else
74
+ [parsed, required_params(params)]
75
+ end
76
+ end
77
+
78
+ def respond_with_all_of(parsed, params, discriminator)
79
+ parent_name = GrapeSwagger::Entity::Helper.model_name(model.superclass, endpoint)
80
+
81
+ {
82
+ allOf: [
83
+ {
84
+ '$ref' => "#/definitions/#{parent_name}"
85
+ },
86
+ [
87
+ add_discriminator(parsed, discriminator),
88
+ required_params(params).push(discriminator.attribute)
89
+ ]
90
+ ]
91
+ }
92
+ end
93
+
94
+ def add_discriminator(parsed, discriminator)
95
+ model_name = GrapeSwagger::Entity::Helper.model_name(model, endpoint)
96
+
97
+ parsed.merge(
98
+ discriminator.attribute => {
99
+ type: 'string',
100
+ enum: [model_name]
101
+ }
102
+ )
68
103
  end
69
104
 
70
105
  def parse_nested(entity_name, entity_options, parent_model = nil)
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrapeSwagger
2
4
  module Entity
3
- VERSION = '0.4.0'.freeze
5
+ VERSION = '0.5.1'
4
6
  end
5
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-swagger-entity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Zaitsev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-30 00:00:00.000000000 Z
11
+ date: 2020-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape-entity
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.0
19
+ version: 0.6.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.5.0
26
+ version: 0.6.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: grape-swagger
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.0
33
+ version: 1.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.0.0
40
+ version: 1.2.0
41
41
  description:
42
42
  email:
43
43
  - kirik910@gmail.com
@@ -62,6 +62,7 @@ files:
62
62
  - lib/grape-swagger-entity.rb
63
63
  - lib/grape-swagger/entity.rb
64
64
  - lib/grape-swagger/entity/attribute_parser.rb
65
+ - lib/grape-swagger/entity/helper.rb
65
66
  - lib/grape-swagger/entity/parser.rb
66
67
  - lib/grape-swagger/entity/version.rb
67
68
  homepage: https://github.com/ruby-grape/grape-swagger-entity
@@ -76,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
77
  requirements:
77
78
  - - ">="
78
79
  - !ruby/object:Gem::Version
79
- version: 2.2.6
80
+ version: '2.4'
80
81
  required_rubygems_version: !ruby/object:Gem::Requirement
81
82
  requirements:
82
83
  - - ">="