grape-swagger-representable 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +29 -0
- data/.rubocop_todo.yml +8 -20
- data/Gemfile +3 -1
- data/Rakefile +2 -0
- data/bin/pry +1 -0
- data/grape-swagger-representable.gemspec +3 -2
- data/lib/grape-swagger-representable.rb +2 -0
- data/lib/grape-swagger/representable.rb +2 -0
- data/lib/grape-swagger/representable/parser.rb +36 -7
- data/lib/grape-swagger/representable/version.rb +3 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16bed46317a7ff343cc6c63c61b53ed61e569b34
|
4
|
+
data.tar.gz: b65dd960b7ea15d0daa0ab3a1efcee5baa03e792
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d9c600e84a70795644fa23e80a7a620d77da1490bda16b7f858f1bc14355779163e821846e3459c768101fc99459b6c1317fe4d2956d463cdca7f3760edf9f2
|
7
|
+
data.tar.gz: 37d417d8eaf1a7a57a397095d2d4978f4a11a369734d566263c4efb689b80492a5ecab2392dfeb7716532913916e36c5201aa971ec72af19ca31f29f2bd14b44
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,34 @@
|
|
1
1
|
AllCops:
|
2
2
|
Exclude:
|
3
3
|
- vendor/**/*
|
4
|
+
TargetRubyVersion: 2.4
|
4
5
|
|
5
6
|
inherit_from: .rubocop_todo.yml
|
7
|
+
|
8
|
+
Layout/EmptyLinesAroundArguments:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Layout/IndentHash:
|
12
|
+
EnforcedStyle: consistent
|
13
|
+
|
14
|
+
Metrics/BlockLength:
|
15
|
+
Exclude:
|
16
|
+
- spec/**/*
|
17
|
+
|
18
|
+
Metrics/ClassLength:
|
19
|
+
Max: 300
|
20
|
+
|
21
|
+
Metrics/LineLength:
|
22
|
+
Max: 120
|
23
|
+
Exclude:
|
24
|
+
- spec/**/*
|
25
|
+
|
26
|
+
Metrics/MethodLength:
|
27
|
+
Exclude:
|
28
|
+
- spec/**/*
|
29
|
+
|
30
|
+
Naming:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Style/RegexpLiteral:
|
34
|
+
Enabled: false
|
data/.rubocop_todo.yml
CHANGED
@@ -1,34 +1,29 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2018-08-21 15:46:20 +0300 using RuboCop version 0.58.2.
|
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:
|
9
|
+
# Offense count: 3
|
10
10
|
Metrics/AbcSize:
|
11
|
-
Max:
|
12
|
-
|
13
|
-
# Offense count: 8
|
14
|
-
# Configuration parameters: CountComments, ExcludedMethods.
|
15
|
-
Metrics/BlockLength:
|
16
|
-
Max: 132
|
11
|
+
Max: 39
|
17
12
|
|
18
13
|
# Offense count: 2
|
19
14
|
Metrics/CyclomaticComplexity:
|
20
|
-
Max:
|
15
|
+
Max: 19
|
21
16
|
|
22
|
-
# Offense count:
|
17
|
+
# Offense count: 2
|
23
18
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
24
19
|
# URISchemes: http, https
|
25
20
|
Metrics/LineLength:
|
26
|
-
Max:
|
21
|
+
Max: 130
|
27
22
|
|
28
23
|
# Offense count: 2
|
29
24
|
# Configuration parameters: CountComments.
|
30
25
|
Metrics/MethodLength:
|
31
|
-
Max:
|
26
|
+
Max: 35
|
32
27
|
|
33
28
|
# Offense count: 1
|
34
29
|
# Configuration parameters: CountKeywordArgs.
|
@@ -37,14 +32,7 @@ Metrics/ParameterLists:
|
|
37
32
|
|
38
33
|
# Offense count: 2
|
39
34
|
Metrics/PerceivedComplexity:
|
40
|
-
Max:
|
41
|
-
|
42
|
-
# Offense count: 1
|
43
|
-
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
44
|
-
# 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
|
45
|
-
Naming/FileName:
|
46
|
-
Exclude:
|
47
|
-
- 'lib/grape-swagger-representable.rb'
|
35
|
+
Max: 21
|
48
36
|
|
49
37
|
# Offense count: 2
|
50
38
|
Style/Documentation:
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in grape-swagger-representable.gemspec
|
4
6
|
gemspec
|
5
7
|
|
6
|
-
gem 'grape-swagger',
|
8
|
+
gem 'grape-swagger', git: 'https://github.com/ruby-grape/grape-swagger.git'
|
data/Rakefile
CHANGED
data/bin/pry
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
lib = File.expand_path('
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'grape-swagger/representable/version'
|
5
6
|
|
@@ -18,7 +19,7 @@ Gem::Specification.new do |s|
|
|
18
19
|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
20
|
s.require_paths = ['lib']
|
20
21
|
|
21
|
-
s.add_runtime_dependency 'grape-swagger', '>= 0.
|
22
|
+
s.add_runtime_dependency 'grape-swagger', '>= 0.31.0'
|
22
23
|
s.add_runtime_dependency 'representable'
|
23
24
|
|
24
25
|
s.add_development_dependency 'bundler', '~> 1.12'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GrapeSwagger
|
2
4
|
module Representable
|
3
5
|
class Parser
|
@@ -75,33 +77,60 @@ module GrapeSwagger
|
|
75
77
|
}
|
76
78
|
end
|
77
79
|
else
|
78
|
-
attributes =
|
79
|
-
attributes = attributes.deep_merge!(parse_representer(nested)) if nested
|
80
|
+
attributes, required = combine(representer, nested)
|
80
81
|
|
81
82
|
if is_a_collection
|
82
83
|
{
|
83
84
|
type: :array,
|
84
|
-
items: {
|
85
|
+
items: with_required({
|
85
86
|
type: :object,
|
86
87
|
properties: attributes
|
87
|
-
},
|
88
|
+
}, required),
|
88
89
|
description: documentation[:desc] || property[:desc] || ''
|
89
90
|
}
|
90
91
|
else
|
91
|
-
{
|
92
|
+
with_required({
|
92
93
|
type: :object,
|
93
94
|
properties: attributes,
|
94
95
|
description: documentation[:desc] || property[:desc] || ''
|
95
|
-
}
|
96
|
+
}, required)
|
96
97
|
end
|
97
98
|
end
|
98
99
|
end
|
99
100
|
|
100
101
|
def parse_representer(representer)
|
101
|
-
representer.map.each_with_object({}) do |value, property|
|
102
|
+
properties = representer.map.each_with_object({}) do |value, property|
|
102
103
|
property_name = value[:as].try(:call) || value.name
|
103
104
|
property[property_name] = parse_representer_property(value)
|
104
105
|
end
|
106
|
+
|
107
|
+
required = representer.map
|
108
|
+
.select { |value| value[:documentation] && value[:documentation][:required] }
|
109
|
+
.map { |value| value[:as] || value.name }
|
110
|
+
|
111
|
+
[properties, required]
|
112
|
+
end
|
113
|
+
|
114
|
+
def combine(representer, nested)
|
115
|
+
attributes, required = parse_representer(representer)
|
116
|
+
return [attributes, required] unless nested
|
117
|
+
|
118
|
+
nested_attributes, nested_required = parse_representer(nested) if nested
|
119
|
+
final_attributes = attributes.deep_merge!(nested_attributes)
|
120
|
+
|
121
|
+
overrided = (attributes.keys & nested_attributes.keys)
|
122
|
+
|
123
|
+
final_required = (required + nested_required)
|
124
|
+
.uniq
|
125
|
+
.select { |k| (overrided.include?(k) && nested_required.include?(k)) || !overrided.include?(k) }
|
126
|
+
|
127
|
+
[final_attributes, final_required]
|
128
|
+
end
|
129
|
+
|
130
|
+
def with_required(hash, required)
|
131
|
+
return hash if required.empty?
|
132
|
+
hash[:required] = required
|
133
|
+
hash
|
105
134
|
end
|
106
135
|
end
|
107
136
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-swagger-representable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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: 2018-
|
11
|
+
date: 2018-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape-swagger
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.31.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.
|
26
|
+
version: 0.31.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: representable
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|