grape-swagger-entity 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b3f412857146befcf1427a89020bd59a2515b9b8
4
+ data.tar.gz: 5618a826e1c63b6ba7a26c0086971cfddea321a4
5
+ SHA512:
6
+ metadata.gz: 437390a4680e55cfb19ecca81eecb04de6dd989af608c294d2ab1785c4615874014519d045208ddbf465dbf1de9058450c20c0c85fc92d520953e32bbf876f5b
7
+ data.tar.gz: 4ed9cbc8be6b104117441c2fe77850d45195cd1c62b8d607140eae31964f0e9d4eb2a6786f55630065eb77907be40ab2fc5b63bb3a7012678692044ffff77940
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ AllCops:
2
+ Exclude:
3
+ - vendor/**/*
4
+
5
+ inherit_from: .rubocop_todo.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,38 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-05-08 01:57:12 +0300 using RuboCop version 0.39.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ Metrics/AbcSize:
11
+ Max: 69
12
+
13
+ # Offense count: 1
14
+ Metrics/CyclomaticComplexity:
15
+ Max: 16
16
+
17
+ # Offense count: 51
18
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
19
+ # URISchemes: http, https
20
+ Metrics/LineLength:
21
+ Max: 136
22
+
23
+ # Offense count: 1
24
+ # Configuration parameters: CountComments.
25
+ Metrics/MethodLength:
26
+ Max: 27
27
+
28
+ # Offense count: 1
29
+ Metrics/PerceivedComplexity:
30
+ Max: 19
31
+
32
+ # Offense count: 2
33
+ Style/Documentation:
34
+ Exclude:
35
+ - 'spec/**/*'
36
+ - 'test/**/*'
37
+ - 'lib/grape-swagger/entity.rb'
38
+ - 'lib/grape-swagger/entity/parser.rb'
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+
3
+ cache: bundler
4
+
5
+ matrix:
6
+ include:
7
+ - rvm: 2.3.0
8
+ - rvm: 2.2
9
+ - rvm: 2.1
10
+ - rvm: ruby-head
11
+ - rvm: jruby-head
12
+ - rvm: jruby-19mode
13
+ - rvm: rbx-2
14
+ allow_failures:
15
+ - rvm: ruby-head
16
+ - rvm: jruby-head
17
+ before_install: gem install bundler -v 1.12.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in grape-swagger-entity.gemspec
4
+ gemspec
5
+
6
+ gem 'grape-swagger', github: 'Bugagazavr/grape-swagger', branch: 'representers'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Kirill Zaitsev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # GrapeSwagger::Entity [![Build Status](https://travis-ci.org/Bugagazavr/grape-swagger-entity.svg)](https://travis-ci.org/Bugagazavr/grape-swagger-entity)
2
+
3
+ A simple grape-swagger adapter to allow parse representers as response model
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'grape-swagger-entity'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install grape-swagger-entity
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests. You can also run `bin/pry` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/grape-swagger-entity.
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
34
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/pry ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'grape-swagger/entity'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'pry'
14
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'grape-swagger/entity/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'grape-swagger-entity'
8
+ s.version = GrapeSwagger::Entity::VERSION
9
+ s.authors = ['Kirill Zaitsev']
10
+ s.email = ['kirik910@gmail.com']
11
+
12
+ s.summary = 'Grape swagger adapter to support grape-entity object parsing'
13
+ s.homepage = 'https://github.com/Bugagazavr/grape-swagger-entity'
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ s.bindir = 'exe'
18
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ s.require_paths = ['lib']
20
+
21
+ s.add_runtime_dependency 'grape-swagger', '>= 0.20.2'
22
+ 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'
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
+ end
@@ -0,0 +1,74 @@
1
+ module GrapeSwagger
2
+ module Entity
3
+ class Parser
4
+ attr_reader :model
5
+ attr_reader :endpoint
6
+
7
+ def initialize(model, endpoint)
8
+ @model = model
9
+ @endpoint = endpoint
10
+ end
11
+
12
+ def call
13
+ # TODO: this should only be a temporary hack ;)
14
+ if ::GrapeEntity::VERSION =~ /0\.4\.\d/
15
+ parameters = model.exposures ? model.exposures : model.documentation
16
+ elsif ::GrapeEntity::VERSION =~ /0\.5\.\d/
17
+ parameters = model.root_exposures.each_with_object({}) do |value, memo|
18
+ memo[value.attribute] = value.send(:options)
19
+ end
20
+ end
21
+
22
+ parse_grape_entity_params(parameters)
23
+ end
24
+
25
+ private
26
+
27
+ def parse_grape_entity_params(params)
28
+ return if params.nil?
29
+
30
+ params.each_with_object({}) do |x, memo|
31
+ next if x[1].fetch(:documentation, {}).fetch(:in, nil).to_s == 'header'
32
+ x[0] = x.last[:as] if x.last[:as]
33
+
34
+ model = x.last[:using] if x.last[:using].present?
35
+ model ||= x.last[:documentation][:type] if x.last[:documentation] && could_it_be_a_model?(x.last[:documentation])
36
+
37
+ if model
38
+ name = endpoint.send(:expose_params_from_model, model)
39
+ memo[x.first] = if x.last[:documentation] && x.last[:documentation][:is_array]
40
+ { 'type' => 'array', 'items' => { '$ref' => "#/definitions/#{name}" } }
41
+ else
42
+ { '$ref' => "#/definitions/#{name}" }
43
+ end
44
+ else
45
+ documented_type = x.last[:type]
46
+ documented_type ||= x.last[:documentation][:type] if x.last[:documentation]
47
+ data_type = GrapeSwagger::DocMethods::DataType.call(documented_type)
48
+
49
+ if GrapeSwagger::DocMethods::DataType.primitive?(data_type)
50
+ data = GrapeSwagger::DocMethods::DataType.mapping(data_type)
51
+ memo[x.first] = { type: data.first, format: data.last }
52
+ else
53
+ memo[x.first] = { type: data_type }
54
+ end
55
+
56
+ memo[x.first][:enum] = x.last[:values] if x.last[:values] && x.last[:values].is_a?(Array)
57
+ end
58
+ memo[x.first][:description] = x.last[:documentation][:desc] if x.last[:documentation] && x.last[:documentation][:desc]
59
+ end
60
+ end
61
+
62
+ def could_it_be_a_model?(value)
63
+ (
64
+ value[:type].to_s.include?('Entity') || value[:type].to_s.include?('Entities')
65
+ ) || (
66
+ value[:type] &&
67
+ value[:type].is_a?(Class) &&
68
+ !GrapeSwagger::DocMethods::DataType.primitive?(value[:type].name.downcase) &&
69
+ !value[:type] == Array
70
+ )
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,5 @@
1
+ module GrapeSwagger
2
+ module Entity
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ require 'grape-swagger'
2
+ require 'grape-entity'
3
+
4
+ require 'grape-swagger/entity/version'
5
+ require 'grape-swagger/entity/parser'
6
+
7
+ module GrapeSwagger
8
+ module Entity
9
+ end
10
+ end
11
+
12
+ GrapeSwagger.model_parsers.register(::GrapeSwagger::Entity::Parser, ::Grape::Entity)
metadata ADDED
@@ -0,0 +1,227 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grape-swagger-entity
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kirill Zaitsev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: grape-swagger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.20.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.20.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: grape-entity
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
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'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '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
+ description:
182
+ email:
183
+ - kirik910@gmail.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".gitignore"
189
+ - ".rspec"
190
+ - ".rubocop.yml"
191
+ - ".rubocop_todo.yml"
192
+ - ".travis.yml"
193
+ - Gemfile
194
+ - LICENSE.txt
195
+ - README.md
196
+ - Rakefile
197
+ - bin/pry
198
+ - bin/setup
199
+ - grape-swagger-entity.gemspec
200
+ - lib/grape-swagger/entity.rb
201
+ - lib/grape-swagger/entity/parser.rb
202
+ - lib/grape-swagger/entity/version.rb
203
+ homepage: https://github.com/Bugagazavr/grape-swagger-entity
204
+ licenses:
205
+ - MIT
206
+ metadata: {}
207
+ post_install_message:
208
+ rdoc_options: []
209
+ require_paths:
210
+ - lib
211
+ required_ruby_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ required_rubygems_version: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
221
+ requirements: []
222
+ rubyforge_project:
223
+ rubygems_version: 2.5.1
224
+ signing_key:
225
+ specification_version: 4
226
+ summary: Grape swagger adapter to support grape-entity object parsing
227
+ test_files: []