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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1adc600f72fbf0b270ca597d538fc692ab1b06d96aec051dd5aac93b0d9541e4
4
- data.tar.gz: 90b38eef4b8736e686c57b9ae3a0a047c3be752076a3c51fe81a2b2ace4534d7
3
+ metadata.gz: a02b298de5d3db8a877e2d19c3a33d926793beea5f6de12f637a142593ebf6cd
4
+ data.tar.gz: d794323888e880667ba53916e4b8e028c200910309da26fbbc823c5a1a11f4d9
5
5
  SHA512:
6
- metadata.gz: becc52b89b55eaf20b8e17c39b2a2d53592fbe6a92feb1c50d6f1b80d4ee0b14edb16dbcb5e6168a5d7830b80f8d412af19c78fc0a645aabd1ca3570ed3e34fb
7
- data.tar.gz: c6da9f8e4818368d67f525898d69b9d15fe46d429cb4223fb44ff1f4d2c52aefff99f8487cf8ecdf702153d1a3d7dbaed93756a0967bbdadd871fdc26f8af229
6
+ metadata.gz: f52b468dcfc8bb22a52a2b0d3cb9609d9b512c31836c69644dfbfbb63ece456dfa9e0eb3200b54006bda1ebac848bf10538bed4ab7cc92241af19b63c01451e4
7
+ data.tar.gz: ccf7750c17e52a0172b5c8d6df101ebad543e9960793267e6d607be4f812e7dd1d6d3fab8cd07919b4bee39dad80c6ac3f79628ece4d4fd45c51314a6cc6049c
@@ -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.2.5 MODEL_PARSER=grape-swagger-entity
15
- - GRAPE_VERSION=1.2.5 MODEL_PARSER=grape-swagger-representable
16
- - GRAPE_VERSION=1.0.3
17
- - GRAPE_VERSION=1.2.5
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
- matrix:
21
+ jobs:
20
22
  fast_finish: true
21
23
 
22
24
  include:
23
25
  - rvm: 2.4.9
24
- env: GRAPE_VERSION=1.2.5
26
+ env:
25
27
  - rvm: ruby-head
26
- env: GRAPE_VERSION=HEAD
28
+ env:
27
29
  - rvm: jruby-head
28
30
  env:
29
31
 
@@ -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'] || '< 1.3.0'
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.75', require: false
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
  ...
@@ -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', '>= 0.16.2', '< 1.3.0'
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")
@@ -16,7 +16,7 @@ module GrapeSwagger
16
16
  'object'
17
17
  when 'Rack::Multipart::UploadedFile', 'File'
18
18
  'file'
19
- when 'Virtus::Attribute::Boolean'
19
+ when 'Grape::API::Boolean'
20
20
  'boolean'
21
21
  when 'BigDecimal'
22
22
  'double'
@@ -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
- param_hidden = param_hidden.call if param_hidden.is_a?(Proc)
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrapeSwagger
4
- VERSION = '0.34.2'
4
+ VERSION = '1.0.0'
5
5
  end
@@ -55,8 +55,8 @@ describe GrapeSwagger::DocMethods::DataType do
55
55
  it { is_expected.to eq 'file' }
56
56
  end
57
57
 
58
- describe 'Virtus::Attribute::Boolean' do
59
- let(:value) { { type: Virtus::Attribute::Boolean } }
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 }
@@ -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: Virtus::Attribute::Boolean, desc: 'prop_boolean description' }
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: Virtus::Attribute::Boolean, desc: 'prop_boolean description' }
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: -> { true } }
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
- specify do
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
@@ -8,7 +8,7 @@ describe 'Boolean Params' do
8
8
  format :json
9
9
 
10
10
  params do
11
- requires :a_boolean, type: Virtus::Attribute::Boolean
11
+ requires :a_boolean, type: Grape::API::Boolean
12
12
  end
13
13
  post :splines do
14
14
  end
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.34.2
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-01-20 00:00:00.000000000 Z
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