grape-swagger-entity 0.3.0 → 0.4.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 +5 -5
- data/.gitignore +2 -0
- data/.rubocop.yml +2 -2
- data/.travis.yml +6 -5
- data/CHANGELOG.md +36 -1
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/grape-swagger-entity.gemspec +1 -1
- data/lib/grape-swagger/entity/attribute_parser.rb +39 -7
- data/lib/grape-swagger/entity/parser.rb +17 -2
- data/lib/grape-swagger/entity/version.rb +1 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9cbc9a4f5350f907024319ec60d6bebcf58c1d9a9fbe0a87157eb521f5d90c27
|
4
|
+
data.tar.gz: d70650e560a98a5c8e6299136146796d87bb8e124944c2b09603ddcab415085a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fffce9cc2ae49583807c9e02a5ed6d0c6fdbd1e3acc2f4816868b292fb8ae0e77161bd4736dcb2d91e30633a814cd8fd31c2f21af9fec12cc4cec8243bb5ce1
|
7
|
+
data.tar.gz: 2c5cdf2184fefbd92fda6b7f65d95d31f0c331e225be2439b5fa2f6d711a7754890271b7a41b06cdd36c44d3bcace9b836cd727c93b21892e6ae9651badb712a
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -10,18 +10,19 @@ after_success:
|
|
10
10
|
- bundle exec danger
|
11
11
|
|
12
12
|
rvm:
|
13
|
-
- 2.4.
|
14
|
-
- 2.3
|
13
|
+
- 2.4.5
|
14
|
+
- 2.5.3
|
15
|
+
- 2.6.0
|
15
16
|
|
16
17
|
env:
|
17
|
-
- GRAPE_ENTITY=0.5.2
|
18
18
|
- GRAPE_ENTITY=0.6.1
|
19
|
+
- GRAPE_ENTITY=0.7.1
|
19
20
|
|
20
21
|
matrix:
|
21
22
|
fast_finish: true
|
22
23
|
|
23
24
|
include:
|
24
|
-
- rvm: 2.
|
25
|
+
- rvm: 2.3.8
|
25
26
|
env:
|
26
27
|
- rvm: ruby-head
|
27
28
|
env:
|
@@ -31,7 +32,7 @@ matrix:
|
|
31
32
|
env:
|
32
33
|
|
33
34
|
allow_failures:
|
34
|
-
- rvm: 2.
|
35
|
+
- rvm: 2.3.8
|
35
36
|
- rvm: ruby-head
|
36
37
|
- rvm: jruby-head
|
37
38
|
- rvm: rbx-2
|
data/CHANGELOG.md
CHANGED
@@ -4,10 +4,45 @@
|
|
4
4
|
|
5
5
|
* Your contribution here.
|
6
6
|
|
7
|
-
####
|
7
|
+
#### Features
|
8
8
|
|
9
9
|
* Your contribution here.
|
10
10
|
|
11
|
+
### 0.4.0 (May 30, 2020)
|
12
|
+
|
13
|
+
#### Features
|
14
|
+
|
15
|
+
* [#49](https://github.com/ruby-grape/grape-swagger-entity/pull/49): Bumped minimal required version of grape-swagger to 1.0.0 - [@Bugagazavr](https://github.com/Bugagazavr).
|
16
|
+
* [#48](https://github.com/ruby-grape/grape-swagger-entity/pull/48): Add support for extensions - [@MaximeRDY](https://github.com/MaximeRDY).
|
17
|
+
|
18
|
+
#### Fixes
|
19
|
+
|
20
|
+
* [#46](https://github.com/ruby-grape/grape-swagger-entity/pull/46): Fixed issue where a boolean example value of false would not display in swagger file - [@drewnichols](https://github.com/drewnichols).
|
21
|
+
|
22
|
+
### 0.3.4 (January 9, 2020)
|
23
|
+
|
24
|
+
#### Features
|
25
|
+
|
26
|
+
* [#40](https://github.com/ruby-grape/grape-swagger-entity/pull/40): Add support for minLength and maxLength - [@fotos](https://github.com/fotos).
|
27
|
+
|
28
|
+
### 0.3.3 (Fabruary 22, 2019)
|
29
|
+
|
30
|
+
#### Features
|
31
|
+
|
32
|
+
* [#39](https://github.com/ruby-grape/grape-swagger-entity/pull/39): Fix to avoid conflict with polymorphic model - [@kinoppyd](https://github.com/kinoppyd).
|
33
|
+
|
34
|
+
### 0.3.2 (January 15, 2019)
|
35
|
+
|
36
|
+
#### Features
|
37
|
+
|
38
|
+
* [#38](https://github.com/ruby-grape/grape-swagger-entity/pull/38): Added support for hidden option for documentation - [@vitoravelino](https://github.com/vitoravelino).
|
39
|
+
|
40
|
+
### 0.3.1 (November 26, 2018)
|
41
|
+
|
42
|
+
#### Features
|
43
|
+
|
44
|
+
* [#37](https://github.com/ruby-grape/grape-swagger-entity/pull/37): Add support for minItems, maxItems and uniqueItems - [@fotos](https://github.com/fotos).
|
45
|
+
|
11
46
|
### 0.3.0 (August 22, 2018)
|
12
47
|
|
13
48
|
#### Features
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -26,7 +26,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
26
26
|
|
27
27
|
## Contributing
|
28
28
|
|
29
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby-grape/grape-swagger-entity.
|
30
30
|
|
31
31
|
## License
|
32
32
|
|
@@ -13,19 +13,33 @@ module GrapeSwagger
|
|
13
13
|
|
14
14
|
if entity_model
|
15
15
|
name = endpoint.nil? ? entity_model.to_s.demodulize : endpoint.send(:expose_params_from_model, entity_model)
|
16
|
-
|
16
|
+
|
17
|
+
entity_model_type = entity_model_type(name, entity_options)
|
18
|
+
return entity_model_type unless documentation
|
19
|
+
|
20
|
+
add_array_documentation(entity_model_type, documentation) if documentation[:is_array]
|
21
|
+
|
22
|
+
entity_model_type
|
17
23
|
else
|
18
24
|
param = data_type_from(entity_options)
|
19
25
|
return param unless documentation
|
20
26
|
|
21
|
-
param
|
22
|
-
|
27
|
+
add_attribute_sample(param, documentation, :default)
|
28
|
+
add_attribute_sample(param, documentation, :example)
|
23
29
|
|
24
30
|
if (values = documentation[:values])
|
25
31
|
param[:enum] = values if values.is_a?(Array)
|
26
32
|
end
|
27
33
|
|
28
|
-
|
34
|
+
if documentation[:is_array]
|
35
|
+
param = { type: :array, items: param }
|
36
|
+
add_array_documentation(param, documentation)
|
37
|
+
end
|
38
|
+
|
39
|
+
add_attribute_documentation(param, documentation)
|
40
|
+
|
41
|
+
add_extension_documentation(param, documentation)
|
42
|
+
|
29
43
|
param
|
30
44
|
end
|
31
45
|
end
|
@@ -42,6 +56,7 @@ module GrapeSwagger
|
|
42
56
|
|
43
57
|
def could_it_be_a_model?(value)
|
44
58
|
return false if value.nil?
|
59
|
+
|
45
60
|
direct_model_type?(value[:type]) || ambiguous_model_type?(value[:type])
|
46
61
|
end
|
47
62
|
|
@@ -92,9 +107,26 @@ module GrapeSwagger
|
|
92
107
|
end
|
93
108
|
end
|
94
109
|
|
95
|
-
def
|
96
|
-
|
97
|
-
|
110
|
+
def add_attribute_sample(attribute, hash, key)
|
111
|
+
value = hash[key]
|
112
|
+
return if value.nil?
|
113
|
+
|
114
|
+
attribute[key] = value.is_a?(Proc) ? value.call : value
|
115
|
+
end
|
116
|
+
|
117
|
+
def add_attribute_documentation(param, documentation)
|
118
|
+
param[:minLength] = documentation[:min_length] if documentation.key?(:min_length)
|
119
|
+
param[:maxLength] = documentation[:max_length] if documentation.key?(:max_length)
|
120
|
+
end
|
121
|
+
|
122
|
+
def add_array_documentation(param, documentation)
|
123
|
+
param[:minItems] = documentation[:min_items] if documentation.key?(:min_items)
|
124
|
+
param[:maxItems] = documentation[:max_items] if documentation.key?(:max_items)
|
125
|
+
param[:uniqueItems] = documentation[:unique_items] if documentation.key?(:unique_items)
|
126
|
+
end
|
127
|
+
|
128
|
+
def add_extension_documentation(param, documentation)
|
129
|
+
GrapeSwagger::DocMethods::Extensions.add_extensions_to_root(documentation, param)
|
98
130
|
end
|
99
131
|
end
|
100
132
|
end
|
@@ -17,6 +17,14 @@ module GrapeSwagger
|
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
|
+
class Alias
|
21
|
+
attr_reader :original, :renamed
|
22
|
+
def initialize(original, renamed)
|
23
|
+
@original = original
|
24
|
+
@renamed = renamed
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
20
28
|
def extract_params(exposure)
|
21
29
|
exposure.root_exposures.each_with_object({}) do |value, memo|
|
22
30
|
if value.for_merge && (value.respond_to?(:entity_class) || value.respond_to?(:using_class_name))
|
@@ -25,7 +33,8 @@ module GrapeSwagger
|
|
25
33
|
extracted_params = extract_params(entity_class)
|
26
34
|
memo.merge!(extracted_params)
|
27
35
|
else
|
28
|
-
|
36
|
+
opts = value.send(:options)
|
37
|
+
opts[:as] ? memo[Alias.new(value.attribute, opts[:as])] = opts : memo[value.attribute] = opts
|
29
38
|
end
|
30
39
|
end
|
31
40
|
end
|
@@ -34,8 +43,12 @@ module GrapeSwagger
|
|
34
43
|
return unless params
|
35
44
|
|
36
45
|
parsed = params.each_with_object({}) do |(entity_name, entity_options), memo|
|
37
|
-
|
46
|
+
documentation_options = entity_options.fetch(:documentation, {})
|
47
|
+
in_option = documentation_options.fetch(:in, nil).to_s
|
48
|
+
hidden_option = documentation_options.fetch(:hidden, nil)
|
49
|
+
next if in_option == 'header' || hidden_option == true
|
38
50
|
|
51
|
+
entity_name = entity_name.original if entity_name.is_a?(Alias)
|
39
52
|
final_entity_name = entity_options.fetch(:as, entity_name)
|
40
53
|
documentation = entity_options[:documentation]
|
41
54
|
|
@@ -46,6 +59,7 @@ module GrapeSwagger
|
|
46
59
|
end
|
47
60
|
|
48
61
|
next unless documentation
|
62
|
+
|
49
63
|
memo[final_entity_name][:readOnly] = documentation[:read_only].to_s == 'true' if documentation[:read_only]
|
50
64
|
memo[final_entity_name][:description] = documentation[:desc] if documentation[:desc]
|
51
65
|
end
|
@@ -92,6 +106,7 @@ module GrapeSwagger
|
|
92
106
|
|
93
107
|
def with_required(hash, required)
|
94
108
|
return hash if required.empty?
|
109
|
+
|
95
110
|
hash[:required] = required
|
96
111
|
hash
|
97
112
|
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
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Zaitsev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape-entity
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 1.0.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: 0.
|
40
|
+
version: 1.0.0
|
41
41
|
description:
|
42
42
|
email:
|
43
43
|
- kirik910@gmail.com
|
@@ -83,8 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
|
-
|
87
|
-
rubygems_version: 2.5.2
|
86
|
+
rubygems_version: 3.0.3
|
88
87
|
signing_key:
|
89
88
|
specification_version: 4
|
90
89
|
summary: Grape swagger adapter to support grape-entity object parsing
|