grape-swagger 0.34.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -7
- data/CHANGELOG.md +4 -0
- data/Gemfile +3 -2
- data/README.md +5 -1
- data/grape-swagger.gemspec +1 -2
- data/lib/grape-swagger/doc_methods/data_type.rb +1 -1
- data/lib/grape-swagger/endpoint.rb +1 -1
- data/lib/grape-swagger/endpoint/params_parser.rb +12 -5
- data/lib/grape-swagger/version.rb +1 -1
- data/spec/lib/data_type_spec.rb +2 -2
- data/spec/lib/endpoint/params_parser_spec.rb +2 -1
- data/spec/lib/endpoint_spec.rb +1 -1
- data/spec/support/model_parsers/entity_parser.rb +1 -1
- data/spec/support/model_parsers/representable_parser.rb +1 -1
- data/spec/swagger_v2/api_swagger_v2_hide_param_spec.rb +14 -3
- data/spec/swagger_v2/boolean_params_spec.rb +1 -1
- metadata +4 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a02b298de5d3db8a877e2d19c3a33d926793beea5f6de12f637a142593ebf6cd
|
4
|
+
data.tar.gz: d794323888e880667ba53916e4b8e028c200910309da26fbbc823c5a1a11f4d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f52b468dcfc8bb22a52a2b0d3cb9609d9b512c31836c69644dfbfbb63ece456dfa9e0eb3200b54006bda1ebac848bf10538bed4ab7cc92241af19b63c01451e4
|
7
|
+
data.tar.gz: ccf7750c17e52a0172b5c8d6df101ebad543e9960793267e6d607be4f812e7dd1d6d3fab8cd07919b4bee39dad80c6ac3f79628ece4d4fd45c51314a6cc6049c
|
data/.travis.yml
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
|
+
os: linux
|
4
|
+
|
3
5
|
before_install:
|
4
6
|
- gem install bundler
|
5
7
|
|
@@ -11,19 +13,19 @@ rvm:
|
|
11
13
|
- 2.6.5
|
12
14
|
- 2.7.0
|
13
15
|
env:
|
14
|
-
- GRAPE_VERSION=1.
|
15
|
-
- GRAPE_VERSION=1.
|
16
|
-
- GRAPE_VERSION=1.0
|
17
|
-
- GRAPE_VERSION=
|
16
|
+
- GRAPE_VERSION=1.3.0 MODEL_PARSER=grape-swagger-entity
|
17
|
+
- GRAPE_VERSION=1.3.0 MODEL_PARSER=grape-swagger-representable
|
18
|
+
- GRAPE_VERSION=1.3.0
|
19
|
+
- GRAPE_VERSION=HEAD
|
18
20
|
|
19
|
-
|
21
|
+
jobs:
|
20
22
|
fast_finish: true
|
21
23
|
|
22
24
|
include:
|
23
25
|
- rvm: 2.4.9
|
24
|
-
env:
|
26
|
+
env:
|
25
27
|
- rvm: ruby-head
|
26
|
-
env:
|
28
|
+
env:
|
27
29
|
- rvm: jruby-head
|
28
30
|
env:
|
29
31
|
|
data/CHANGELOG.md
CHANGED
@@ -3,9 +3,13 @@
|
|
3
3
|
#### Features
|
4
4
|
|
5
5
|
* Your contribution here.
|
6
|
+
* [#777](https://github.com/ruby-grape/grape-swagger/pull/777): Make usage of grape >= 1.3, rack >= 2.1 - [@LeFnord](https://github.com/LeFnord).
|
7
|
+
* [#775](https://github.com/ruby-grape/grape-swagger/pull/775): Add in token_owner support to param hidden procs - [@urkle](https://github.com/urkle).
|
6
8
|
|
7
9
|
#### Fixes
|
8
10
|
|
11
|
+
* Your contribution here.
|
12
|
+
|
9
13
|
### 0.34.2 (January 20, 2020)
|
10
14
|
|
11
15
|
#### Fixes
|
data/Gemfile
CHANGED
@@ -6,7 +6,7 @@ ruby RUBY_VERSION
|
|
6
6
|
|
7
7
|
gemspec
|
8
8
|
|
9
|
-
gem 'grape', case version = ENV['GRAPE_VERSION'] || '
|
9
|
+
gem 'grape', case version = ENV['GRAPE_VERSION'] || '>= 1.3.0'
|
10
10
|
when 'HEAD'
|
11
11
|
{ git: 'https://github.com/ruby-grape/grape' }
|
12
12
|
else
|
@@ -20,12 +20,13 @@ group :development, :test do
|
|
20
20
|
gem 'pry', platforms: [:mri]
|
21
21
|
gem 'pry-byebug', platforms: [:mri]
|
22
22
|
|
23
|
+
gem 'rack', '~> 2.1'
|
23
24
|
gem 'rack-cors'
|
24
25
|
gem 'rack-test'
|
25
26
|
gem 'rake'
|
26
27
|
gem 'rdoc'
|
27
28
|
gem 'rspec', '~> 3.9'
|
28
|
-
gem 'rubocop', '~> 0.
|
29
|
+
gem 'rubocop', '~> 0.79', require: false
|
29
30
|
end
|
30
31
|
|
31
32
|
group :test do
|
data/README.md
CHANGED
@@ -52,6 +52,7 @@ grape-swagger | swagger spec | grape | grape-entity | represen
|
|
52
52
|
0.27.0 | 2.0 | >= 0.16.2 ... <= 1.1.0 | >= 0.5.0 | >= 2.4.1 |
|
53
53
|
0.32.0 | 2.0 | >= 0.16.2 | >= 0.5.0 | >= 2.4.1 |
|
54
54
|
0.34.0 | 2.0 | >= 0.16.2 ... < 1.3.0 | >= 0.5.0 | >= 2.4.1 |
|
55
|
+
1.0.0 | 2.0 | >= 1.3.0 | >= 0.5.0 | >= 2.4.1 |
|
55
56
|
|
56
57
|
|
57
58
|
## Swagger-Spec <a name="swagger-spec"></a>
|
@@ -743,9 +744,12 @@ end
|
|
743
744
|
Exclude single optional parameter from the documentation
|
744
745
|
|
745
746
|
```ruby
|
747
|
+
not_admins = lambda { |token_owner = nil| token_owner.nil? || !token_owner.admin? }
|
748
|
+
|
746
749
|
params do
|
747
750
|
optional :one, documentation: { hidden: true }
|
748
|
-
optional :two, documentation: { hidden: -> { true } }
|
751
|
+
optional :two, documentation: { hidden: -> { |t=nil| true } }
|
752
|
+
optional :three, documentation: { hidden: not_admins }
|
749
753
|
end
|
750
754
|
post :act do
|
751
755
|
...
|
data/grape-swagger.gemspec
CHANGED
@@ -14,8 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.license = 'MIT'
|
15
15
|
|
16
16
|
s.required_ruby_version = '>= 2.4'
|
17
|
-
s.add_runtime_dependency 'grape', '
|
18
|
-
s.add_runtime_dependency 'rack', '2.0.8'
|
17
|
+
s.add_runtime_dependency 'grape', '~> 1.3.0'
|
19
18
|
|
20
19
|
s.files = `git ls-files`.split("\n")
|
21
20
|
s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
|
@@ -301,7 +301,7 @@ module Grape
|
|
301
301
|
default_type(required)
|
302
302
|
|
303
303
|
request_params = unless declared_params.nil? && route.headers.nil?
|
304
|
-
GrapeSwagger::Endpoint::ParamsParser.parse_request_params(required, settings)
|
304
|
+
GrapeSwagger::Endpoint::ParamsParser.parse_request_params(required, settings, self)
|
305
305
|
end || {}
|
306
306
|
|
307
307
|
request_params.empty? ? required : request_params
|
@@ -3,15 +3,16 @@
|
|
3
3
|
module GrapeSwagger
|
4
4
|
module Endpoint
|
5
5
|
class ParamsParser
|
6
|
-
attr_reader :params, :settings
|
6
|
+
attr_reader :params, :settings, :endpoint
|
7
7
|
|
8
|
-
def self.parse_request_params(params, settings)
|
9
|
-
new(params, settings).parse_request_params
|
8
|
+
def self.parse_request_params(params, settings, endpoint)
|
9
|
+
new(params, settings, endpoint).parse_request_params
|
10
10
|
end
|
11
11
|
|
12
|
-
def initialize(params, settings)
|
12
|
+
def initialize(params, settings, endpoint)
|
13
13
|
@params = params
|
14
14
|
@settings = settings
|
15
|
+
@endpoint = endpoint
|
15
16
|
end
|
16
17
|
|
17
18
|
def parse_request_params
|
@@ -55,7 +56,13 @@ module GrapeSwagger
|
|
55
56
|
return true unless param_options.key?(:documentation) && !param_options[:required]
|
56
57
|
|
57
58
|
param_hidden = param_options[:documentation].fetch(:hidden, false)
|
58
|
-
|
59
|
+
if param_hidden.is_a?(Proc)
|
60
|
+
param_hidden = if settings[:token_owner]
|
61
|
+
param_hidden.call(endpoint.send(settings[:token_owner].to_sym))
|
62
|
+
else
|
63
|
+
param_hidden.call
|
64
|
+
end
|
65
|
+
end
|
59
66
|
!param_hidden
|
60
67
|
end
|
61
68
|
|
data/spec/lib/data_type_spec.rb
CHANGED
@@ -55,8 +55,8 @@ describe GrapeSwagger::DocMethods::DataType do
|
|
55
55
|
it { is_expected.to eq 'file' }
|
56
56
|
end
|
57
57
|
|
58
|
-
describe '
|
59
|
-
let(:value) { { type:
|
58
|
+
describe 'Grape::API::Boolean' do
|
59
|
+
let(:value) { { type: Grape::API::Boolean } }
|
60
60
|
|
61
61
|
it { is_expected.to eq 'boolean' }
|
62
62
|
end
|
@@ -5,8 +5,9 @@ require 'spec_helper'
|
|
5
5
|
describe GrapeSwagger::Endpoint::ParamsParser do
|
6
6
|
let(:settings) { {} }
|
7
7
|
let(:params) { [] }
|
8
|
+
let(:endpoint) { nil }
|
8
9
|
|
9
|
-
let(:parser) { described_class.new(params, settings) }
|
10
|
+
let(:parser) { described_class.new(params, settings, endpoint) }
|
10
11
|
|
11
12
|
describe '#parse_request_params' do
|
12
13
|
subject(:parse_request_params) { parser.parse_request_params }
|
data/spec/lib/endpoint_spec.rb
CHANGED
@@ -49,7 +49,7 @@ describe Grape::Endpoint do
|
|
49
49
|
describe 'parse_request_params' do
|
50
50
|
let(:subject) { GrapeSwagger::Endpoint::ParamsParser }
|
51
51
|
before do
|
52
|
-
subject.send(:parse_request_params, params, {})
|
52
|
+
subject.send(:parse_request_params, params, {}, nil)
|
53
53
|
end
|
54
54
|
|
55
55
|
context 'when params do not contain an array' do
|
@@ -116,7 +116,7 @@ RSpec.shared_context 'entity swagger example' do
|
|
116
116
|
expose :prop_time, documentation: { type: Time, desc: 'prop_time description' }
|
117
117
|
expose :prop_password, documentation: { type: 'password', desc: 'prop_password description' }
|
118
118
|
expose :prop_email, documentation: { type: 'email', desc: 'prop_email description' }
|
119
|
-
expose :prop_boolean, documentation: { type:
|
119
|
+
expose :prop_boolean, documentation: { type: Grape::API::Boolean, desc: 'prop_boolean description' }
|
120
120
|
expose :prop_file, documentation: { type: File, desc: 'prop_file description' }
|
121
121
|
expose :prop_json, documentation: { type: JSON, desc: 'prop_json description' }
|
122
122
|
end
|
@@ -186,7 +186,7 @@ RSpec.shared_context 'representable swagger example' do
|
|
186
186
|
property :prop_time, documentation: { type: Time, desc: 'prop_time description' }
|
187
187
|
property :prop_password, documentation: { type: 'password', desc: 'prop_password description' }
|
188
188
|
property :prop_email, documentation: { type: 'email', desc: 'prop_email description' }
|
189
|
-
property :prop_boolean, documentation: { type:
|
189
|
+
property :prop_boolean, documentation: { type: Grape::API::Boolean, desc: 'prop_boolean description' }
|
190
190
|
property :prop_file, documentation: { type: File, desc: 'prop_file description' }
|
191
191
|
property :prop_json, documentation: { type: JSON, desc: 'prop_json description' }
|
192
192
|
end
|
@@ -7,12 +7,19 @@ describe 'hidden flag enables a single endpoint parameter to be excluded from th
|
|
7
7
|
before :all do
|
8
8
|
module TheApi
|
9
9
|
class HideParamsApi < Grape::API
|
10
|
+
helpers do
|
11
|
+
def resource_owner
|
12
|
+
'123'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
10
16
|
namespace :flat_params_endpoint do
|
11
17
|
desc 'This is a endpoint with a flat parameter hierarchy'
|
12
18
|
params do
|
13
19
|
requires :name, type: String, documentation: { desc: 'name' }
|
14
20
|
optional :favourite_color, type: String, documentation: { desc: 'I should not be anywhere', hidden: true }
|
15
|
-
optional :proc_param, type: String, documentation: { desc: 'I should not be anywhere', hidden:
|
21
|
+
optional :proc_param, type: String, documentation: { desc: 'I should not be anywhere', hidden: proc { true } }
|
22
|
+
optional :proc_with_token, type: String, documentation: { desc: 'I may be somewhere', hidden: proc { |token_owner = nil| token_owner.nil? } }
|
16
23
|
end
|
17
24
|
|
18
25
|
post do
|
@@ -50,7 +57,7 @@ describe 'hidden flag enables a single endpoint parameter to be excluded from th
|
|
50
57
|
end
|
51
58
|
end
|
52
59
|
|
53
|
-
add_swagger_documentation
|
60
|
+
add_swagger_documentation token_owner: 'resource_owner'
|
54
61
|
end
|
55
62
|
end
|
56
63
|
end
|
@@ -63,9 +70,13 @@ describe 'hidden flag enables a single endpoint parameter to be excluded from th
|
|
63
70
|
JSON.parse(last_response.body)
|
64
71
|
end
|
65
72
|
|
66
|
-
|
73
|
+
it 'ignores parameters that are explicitly hidden' do
|
67
74
|
expect(subject['paths']['/flat_params_endpoint']['post']['parameters'].map { |p| p['name'] }).not_to include('favourite_color', 'proc_param')
|
68
75
|
end
|
76
|
+
|
77
|
+
it 'allows procs to consult the token_owner' do
|
78
|
+
expect(subject['paths']['/flat_params_endpoint']['post']['parameters'].map { |p| p['name'] }).to include('proc_with_token')
|
79
|
+
end
|
69
80
|
end
|
70
81
|
|
71
82
|
describe 'nested parameter hierarchy' do
|
metadata
CHANGED
@@ -1,49 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-swagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Vandecasteele
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.16.2
|
20
|
-
- - "<"
|
17
|
+
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: 1.3.0
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.16.2
|
30
|
-
- - "<"
|
24
|
+
- - "~>"
|
31
25
|
- !ruby/object:Gem::Version
|
32
26
|
version: 1.3.0
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: rack
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - '='
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: 2.0.8
|
40
|
-
type: :runtime
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - '='
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 2.0.8
|
47
27
|
description:
|
48
28
|
email:
|
49
29
|
- tim.vandecasteele@gmail.com
|