grape-swagger-entity 0.1.5 → 0.1.6

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
  SHA1:
3
- metadata.gz: 09decfdceca7643d9cf6df2f34843a5643d62a56
4
- data.tar.gz: ab8bbcc2c2d29802747f35848165abcf85407a4d
3
+ metadata.gz: 72459a987fb7696ab9b9af64da1bcbcd6e1b2de3
4
+ data.tar.gz: 9c401e5bcab37c4fb90af2b3faf4d5226953f5fa
5
5
  SHA512:
6
- metadata.gz: 5eeada88bb46cdc9b84157c0bc75b207f6f05f99fc9378c8c73a8d03d08ac83192a91d3cefab8a996d60ffb57e3b5ac51d1caee25c8692b845d9068616da9de1
7
- data.tar.gz: 6847991544fa81362e9deab7df204f38059fb49dca0f72a84ff94d6179d2f9ce7416262b138f30bc1fce0b3cb2e74439a5ed4f8da88cbafc5a58e328be4a7592
6
+ metadata.gz: 0df830bd1242402544528d473051715e12d5ee82650849582b1126de32048e2b0547478334394559ef584b7c38e7ebb11fa62e0435f6e2da7e6220e6ff36b0b2
7
+ data.tar.gz: 0b2c212b1580bba2706ca2e116e7f32b1ef50acb083e92191f2ec77363c6839017ac26705b874f81271a4d2d98d721c8c446e8d670ac500490362500445e5fbd
data/.rubocop.yml CHANGED
@@ -3,3 +3,18 @@ AllCops:
3
3
  - vendor/**/*
4
4
 
5
5
  inherit_from: .rubocop_todo.yml
6
+
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - spec/**/*
10
+
11
+ Metrics/LineLength:
12
+ Exclude:
13
+ - spec/**/*
14
+
15
+ Metrics/MethodLength:
16
+ Exclude:
17
+ - spec/**/*
18
+
19
+ Style/IndentHash:
20
+ EnforcedStyle: consistent
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2016-06-08 01:18:12 +0300 using RuboCop version 0.40.0.
3
+ # on 2017-02-02 15:42:44 +0100 using RuboCop version 0.47.1.
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
@@ -8,37 +8,42 @@
8
8
 
9
9
  # Offense count: 1
10
10
  Metrics/AbcSize:
11
- Max: 48
11
+ Max: 45
12
+
13
+ # Offense count: 8
14
+ # Configuration parameters: CountComments, ExcludedMethods.
15
+ Metrics/BlockLength:
16
+ Max: 27
12
17
 
13
18
  # Offense count: 1
14
19
  Metrics/CyclomaticComplexity:
15
- Max: 16
20
+ Max: 14
16
21
 
17
- # Offense count: 50
18
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
22
+ # Offense count: 11
23
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
19
24
  # URISchemes: http, https
20
25
  Metrics/LineLength:
21
- Max: 136
26
+ Max: 120
22
27
 
23
28
  # Offense count: 2
24
29
  # Configuration parameters: CountComments.
25
30
  Metrics/MethodLength:
26
- Max: 42
31
+ Max: 30
27
32
 
28
33
  # Offense count: 1
29
34
  Metrics/PerceivedComplexity:
30
- Max: 18
35
+ Max: 16
31
36
 
32
37
  # Offense count: 2
33
38
  Style/Documentation:
34
39
  Exclude:
35
40
  - 'spec/**/*'
36
- - 'test/**/*'
37
41
  - 'lib/grape-swagger/entity.rb'
38
42
  - 'lib/grape-swagger/entity/parser.rb'
39
43
 
40
44
  # Offense count: 1
41
- # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
45
+ # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
46
+ # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
42
47
  Style/FileName:
43
48
  Exclude:
44
49
  - 'lib/grape-swagger-entity.rb'
data/.travis.yml CHANGED
@@ -1,30 +1,31 @@
1
- language: ruby
1
+ before_install:
2
+ - gem update --system
3
+ - gem install bundler
2
4
 
3
- cache: bundler
5
+ after_success:
6
+ - bundle exec danger
7
+
8
+ rvm:
9
+ - 2.4.0
10
+ - 2.3.3
11
+ - 2.2.6
12
+
13
+ env:
14
+ - GRAPE_ENTITY=0.5.2
15
+ - GRAPE_ENTITY=0.6.1
4
16
 
5
17
  matrix:
18
+ fast_finish: true
19
+
6
20
  include:
7
- - rvm: 2.3.0
8
- script:
9
- - bundle exec danger
10
- - rvm: 2.3.0
11
- env:
12
- - GRAPE_ENTITY="~> 0.4.0"
13
- - rvm: 2.3.0
14
- env:
15
- - GRAPE_ENTITY="~> 0.5.0"
16
- - rvm: 2.3.0
17
- env:
18
- - GRAPE_ENTITY="~> 0.6.0"
19
- - rvm: 2.2
20
- - rvm: 2.1
21
- - rvm: jruby-9.1.2.0
22
21
  - rvm: ruby-head
22
+ env:
23
23
  - rvm: jruby-head
24
+ env:
24
25
  - rvm: rbx-2
26
+ env:
27
+
25
28
  allow_failures:
26
29
  - rvm: ruby-head
27
30
  - rvm: jruby-head
28
31
  - rvm: rbx-2
29
-
30
- before_install: gem install bundler -v 1.12.1
data/CHANGELOG.md CHANGED
@@ -8,6 +8,13 @@
8
8
 
9
9
  * Your contribution here.
10
10
 
11
+ ### 0.1.6 (February 3, 2017)
12
+
13
+ #### Features
14
+
15
+ * [#21](https://github.com/ruby-grape/grape-swagger-entity/pull/21): Adds support for own format - [@LeFnord](https://github.com/LeFnord).
16
+ * [#19](https://github.com/ruby-grape/grape-swagger-entity/pull/19): Adds support for default value - [@LeFnord](https://github.com/LeFnord).
17
+
11
18
  ### 0.1.5 (November 21, 2016)
12
19
 
13
20
  #### Features
data/Gemfile CHANGED
@@ -3,11 +3,21 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in grape-swagger-entity.gemspec
4
4
  gemspec
5
5
 
6
- gem 'grape-entity', ENV.fetch('GRAPE_ENTITY', '0.5.0')
7
- gem 'grape-swagger', github: 'ruby-grape/grape-swagger'
8
- gem 'ruby-grape-danger', '~> 0.1.0', require: false
6
+ group :development, :test do
7
+ gem 'bundler'
8
+ gem 'pry', platforms: [:mri]
9
+ gem 'pry-byebug', platforms: [:mri]
10
+ gem 'rack'
11
+ gem 'rack-cors'
12
+ gem 'rack-test'
13
+ gem 'rake'
14
+ gem 'rdoc'
15
+ gem 'rspec', '~> 3.0'
16
+ gem 'rubocop', '~> 0.46'
17
+ end
9
18
 
10
- if RUBY_VERSION < '2.2.2'
11
- gem 'rack', '<2.0.0'
12
- gem 'activesupport', '<5.0.0'
19
+ group :test do
20
+ gem 'grape-entity', ENV.fetch('GRAPE_ENTITY', '0.6.1')
21
+ gem 'ruby-grape-danger', '~> 0.1.1', require: false
22
+ gem 'simplecov', require: false
13
23
  end
data/Rakefile CHANGED
@@ -1,6 +1,18 @@
1
- require 'bundler/gem_tasks'
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.setup(:default, :development)
5
+
6
+ require 'rake'
7
+
8
+ Bundler::GemHelper.install_tasks
9
+
10
+ require 'rspec/core'
2
11
  require 'rspec/core/rake_task'
3
12
 
4
13
  RSpec::Core::RakeTask.new(:spec)
5
14
 
6
- task default: :spec
15
+ require 'rubocop/rake_task'
16
+ RuboCop::RakeTask.new(:rubocop)
17
+
18
+ task default: [:spec, :rubocop]
@@ -18,17 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  s.require_paths = ['lib']
20
20
 
21
+ s.required_ruby_version = '>= 2.2.6'
21
22
  s.add_runtime_dependency 'grape-swagger', '>= 0.20.4'
22
23
  s.add_runtime_dependency 'grape-entity'
23
-
24
- s.add_development_dependency 'bundler', '~> 1.12'
25
- s.add_development_dependency 'rake', '~> 10.0'
26
- s.add_development_dependency 'rspec', '~> 3.0'
27
- s.add_development_dependency 'rack-test'
28
- s.add_development_dependency 'rack-cors'
29
- s.add_development_dependency 'rubocop', '0.40.0'
30
- s.add_development_dependency 'redcarpet' unless RUBY_PLATFORM.eql?('java') || RUBY_ENGINE.eql?('rbx')
31
- s.add_development_dependency 'rouge' unless RUBY_PLATFORM.eql?('java') || RUBY_ENGINE.eql?('rbx')
32
- s.add_development_dependency 'pry' unless RUBY_PLATFORM.eql?('java') || RUBY_ENGINE.eql?('rbx')
33
- s.add_development_dependency 'pry-byebug' unless RUBY_PLATFORM.eql?('java') || RUBY_ENGINE.eql?('rbx')
34
24
  end
@@ -12,6 +12,7 @@ module GrapeSwagger
12
12
  def call
13
13
  # TODO: this should only be a temporary hack ;)
14
14
  if ::GrapeEntity::VERSION =~ /0\.4\.\d/
15
+ warn 'usage of grape-entity <0.5.0 is deprecated'
15
16
  parameters = model.exposures ? model.exposures : model.documentation
16
17
  else
17
18
  parameters = model.root_exposures.each_with_object({}) do |value, memo|
@@ -31,43 +32,23 @@ module GrapeSwagger
31
32
  next if entity_options.fetch(:documentation, {}).fetch(:in, nil).to_s == 'header'
32
33
 
33
34
  entity_name = entity_options[:as] if entity_options[:as]
34
- model = entity_options[:using] if entity_options[:using].present?
35
-
36
- if entity_options[:documentation] && could_it_be_a_model?(entity_options[:documentation])
37
- model ||= entity_options[:documentation][:type]
38
- end
35
+ documentation = entity_options[:documentation]
36
+ model = model_from(entity_options)
39
37
 
40
38
  if model
41
39
  name = endpoint.nil? ? model.to_s.demodulize : endpoint.send(:expose_params_from_model, model)
42
40
  memo[entity_name] = entity_model_type(name, entity_options)
43
41
  else
44
- documented_type = entity_options[:type]
45
-
46
- if entity_options[:documentation]
47
- documented_type ||= entity_options[:documentation][:type]
48
- end
49
-
50
- data_type = GrapeSwagger::DocMethods::DataType.call(documented_type)
51
-
52
- if GrapeSwagger::DocMethods::DataType.primitive?(data_type)
53
- data = GrapeSwagger::DocMethods::DataType.mapping(data_type)
42
+ memo[entity_name] = data_type_from(entity_options)
43
+ next unless documentation
54
44
 
55
- memo[entity_name] = {
56
- type: data.first,
57
- format: data.last
58
- }
59
- else
60
- memo[entity_name] = {
61
- type: data_type
62
- }
63
- end
45
+ memo[entity_name][:default] = documentation[:default] if documentation[:default]
64
46
 
65
- if entity_options[:documentation] && entity_options[:documentation][:values]
66
- values = entity_options[:documentation][:values]
47
+ if (values = documentation[:values])
67
48
  memo[entity_name][:enum] = values if values.is_a?(Array)
68
49
  end
69
50
 
70
- if entity_options[:documentation] && entity_options[:documentation][:is_array]
51
+ if documentation[:is_array]
71
52
  memo[entity_name] = {
72
53
  type: :array,
73
54
  items: memo.delete(entity_name)
@@ -75,13 +56,22 @@ module GrapeSwagger
75
56
  end
76
57
  end
77
58
 
78
- if entity_options[:documentation] && entity_options[:documentation][:desc]
79
- memo[entity_name][:description] = entity_options[:documentation][:desc]
80
- end
59
+ memo[entity_name][:description] = documentation[:desc] if documentation && documentation[:desc]
81
60
  end
82
61
  end
83
62
 
63
+ def model_from(entity_options)
64
+ model = entity_options[:using] if entity_options[:using].present?
65
+
66
+ if could_it_be_a_model?(entity_options[:documentation])
67
+ model ||= entity_options[:documentation][:type]
68
+ end
69
+
70
+ model
71
+ end
72
+
84
73
  def could_it_be_a_model?(value)
74
+ return false if value.nil?
85
75
  direct_model_type?(value[:type]) || ambiguous_model_type?(value[:type])
86
76
  end
87
77
 
@@ -96,6 +86,27 @@ module GrapeSwagger
96
86
  !type == Array
97
87
  end
98
88
 
89
+ def data_type_from(documentation)
90
+ documented_type = documentation[:type]
91
+ documented_type ||= (documentation[:documentation] && documentation[:documentation][:type])
92
+
93
+ data_type = GrapeSwagger::DocMethods::DataType.call(documented_type)
94
+
95
+ document_data_type(documentation[:documentation], data_type)
96
+ end
97
+
98
+ def document_data_type(documentation, data_type)
99
+ type = if GrapeSwagger::DocMethods::DataType.primitive?(data_type)
100
+ data = GrapeSwagger::DocMethods::DataType.mapping(data_type)
101
+ { type: data.first, format: data.last }
102
+ else
103
+ { type: data_type }
104
+ end
105
+ type[:format] = documentation[:format] if documentation && documentation.key?(:format)
106
+
107
+ type
108
+ end
109
+
99
110
  def entity_model_type(name, entity_options)
100
111
  if entity_options[:documentation] && entity_options[:documentation][:is_array]
101
112
  {
@@ -1,5 +1,5 @@
1
1
  module GrapeSwagger
2
2
  module Entity
3
- VERSION = '0.1.5'.freeze
3
+ VERSION = '0.1.6'.freeze
4
4
  end
5
5
  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.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Zaitsev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-21 00:00:00.000000000 Z
11
+ date: 2017-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape-swagger
@@ -38,146 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.12'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.12'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '10.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '10.0'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.0'
83
- - !ruby/object:Gem::Dependency
84
- name: rack-test
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rack-cors
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: rubocop
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - '='
116
- - !ruby/object:Gem::Version
117
- version: 0.40.0
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - '='
123
- - !ruby/object:Gem::Version
124
- version: 0.40.0
125
- - !ruby/object:Gem::Dependency
126
- name: redcarpet
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: rouge
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: pry
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: pry-byebug
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: '0'
181
41
  description:
182
42
  email:
183
43
  - kirik910@gmail.com
@@ -215,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
215
75
  requirements:
216
76
  - - ">="
217
77
  - !ruby/object:Gem::Version
218
- version: '0'
78
+ version: 2.2.6
219
79
  required_rubygems_version: !ruby/object:Gem::Requirement
220
80
  requirements:
221
81
  - - ">="