grape-swagger 1.0.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a02b298de5d3db8a877e2d19c3a33d926793beea5f6de12f637a142593ebf6cd
4
- data.tar.gz: d794323888e880667ba53916e4b8e028c200910309da26fbbc823c5a1a11f4d9
3
+ metadata.gz: beb6baac3bba57a4fd27f01c8129fbd128c0c88426f1408784f1e77ef870c65a
4
+ data.tar.gz: 88234909ace085c8b63f0534630ae8856eb15d383bee856c9fcc57079d0060a1
5
5
  SHA512:
6
- metadata.gz: f52b468dcfc8bb22a52a2b0d3cb9609d9b512c31836c69644dfbfbb63ece456dfa9e0eb3200b54006bda1ebac848bf10538bed4ab7cc92241af19b63c01451e4
7
- data.tar.gz: ccf7750c17e52a0172b5c8d6df101ebad543e9960793267e6d607be4f812e7dd1d6d3fab8cd07919b4bee39dad80c6ac3f79628ece4d4fd45c51314a6cc6049c
6
+ metadata.gz: 3b50e2b60fb3d4a1876bac4587f740c27a624c02726153746dc79e76fb1a233d04a3b1b15844bf65a337484d551ac6ea84b04c85c1537138dfc4327149cbb654
7
+ data.tar.gz: 32a0e9014bf782a0f5a5417a307bf9325986d7d9df662e73174525792e9103d2a3ec3c4f8b3d7fbdc72829d7514ba299dd62adb361085020f37b104f9a29ee25
@@ -6,6 +6,8 @@ AllCops:
6
6
  - example/**/*
7
7
  TargetRubyVersion: 2.7
8
8
 
9
+ # Layout stuff
10
+ #
9
11
  Layout/EmptyLinesAroundArguments:
10
12
  Enabled: false
11
13
 
@@ -17,6 +19,19 @@ Layout/LineLength:
17
19
  Exclude:
18
20
  - spec/**/*
19
21
 
22
+ Layout/SpaceAroundMethodCallOperator:
23
+ Enabled: true
24
+
25
+ # Lint stuff
26
+ #
27
+ Lint/RaiseException:
28
+ Enabled: true
29
+
30
+ Lint/StructNewOverride:
31
+ Enabled: true
32
+
33
+ # Metrics stuff
34
+ #
20
35
  Metrics/BlockLength:
21
36
  Exclude:
22
37
  - spec/**/*
@@ -28,8 +43,24 @@ Metrics/MethodLength:
28
43
  Exclude:
29
44
  - spec/**/*
30
45
 
46
+ # Naming stuff
47
+ #
31
48
  Naming:
32
49
  Enabled: false
33
50
 
51
+ # Style stuff
52
+ #
53
+ Style/ExponentialNotation:
54
+ Enabled: true
55
+
56
+ Style/HashEachMethods:
57
+ Enabled: true
58
+
59
+ Style/HashTransformKeys:
60
+ Enabled: true
61
+
62
+ Style/HashTransformValues:
63
+ Enabled: true
64
+
34
65
  Style/RegexpLiteral:
35
66
  Enabled: false
@@ -9,9 +9,9 @@ after_success:
9
9
  - bundle exec danger
10
10
 
11
11
  rvm:
12
- - 2.5.7
13
- - 2.6.5
14
- - 2.7.0
12
+ - 2.5.8
13
+ - 2.6.6
14
+ - 2.7.1
15
15
  env:
16
16
  - GRAPE_VERSION=1.3.0 MODEL_PARSER=grape-swagger-entity
17
17
  - GRAPE_VERSION=1.3.0 MODEL_PARSER=grape-swagger-representable
@@ -22,7 +22,7 @@ jobs:
22
22
  fast_finish: true
23
23
 
24
24
  include:
25
- - rvm: 2.4.9
25
+ - rvm: 2.4.10
26
26
  env:
27
27
  - rvm: ruby-head
28
28
  env:
@@ -30,6 +30,6 @@ jobs:
30
30
  env:
31
31
 
32
32
  allow_failures:
33
- - rvm: 2.4.9
33
+ - rvm: 2.4.10
34
34
  - rvm: ruby-head
35
35
  - rvm: jruby-head
@@ -3,13 +3,29 @@
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).
8
6
 
9
7
  #### Fixes
10
8
 
11
9
  * Your contribution here.
12
10
 
11
+
12
+ ### 1.1.0 (April 20, 2020)
13
+
14
+ #### Features
15
+
16
+ * [#785](https://github.com/ruby-grape/grape-swagger/pull/785): Add extensions for params - [@MaximeRDY](https://github.com/MaximeRDY).
17
+ * [#782](https://github.com/ruby-grape/grape-swagger/pull/782): Allow passing class name as string for rake task initializer - [@misdoro](https://github.com/misdoro).
18
+ * [#786](https://github.com/ruby-grape/grape-swagger/pull/786): Use full entity name as a default - [@mrexox](https://github.com/mrexox).
19
+
20
+
21
+ ### 1.0.0 (February 10, 2020)
22
+
23
+ #### Features
24
+
25
+ * [#777](https://github.com/ruby-grape/grape-swagger/pull/777): Make usage of grape >= 1.3, rack >= 2.1 - [@LeFnord](https://github.com/LeFnord).
26
+ * [#775](https://github.com/ruby-grape/grape-swagger/pull/775): Add in token_owner support to param hidden procs - [@urkle](https://github.com/urkle).
27
+
28
+
13
29
  ### 0.34.2 (January 20, 2020)
14
30
 
15
31
  #### Fixes
@@ -42,10 +58,6 @@
42
58
  * [#743](https://github.com/ruby-grape/grape-swagger/pull/743): CI: use 2.4.6, 2.5.5 - [@olleolleolle](https://github.com/olleolleolle).
43
59
  * [#737](https://github.com/ruby-grape/grape-swagger/pull/737): Add swagger endpoint guard to both doc endpoints - [@urkle](https://github.com/urkle).
44
60
 
45
- #### Changes
46
-
47
- * [#749](https://github.com/ruby-grape/grape-swagger/pull/749) Drop support for Ruby 2.3 and below - [@LeFnord](https://github.com/LeFnord).
48
-
49
61
 
50
62
  ### 0.32.1 (December 7, 2018)
51
63
 
data/Gemfile CHANGED
@@ -20,13 +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
+ gem 'rack', '~> 2.2'
24
24
  gem 'rack-cors'
25
25
  gem 'rack-test'
26
26
  gem 'rake'
27
27
  gem 'rdoc'
28
28
  gem 'rspec', '~> 3.9'
29
- gem 'rubocop', '~> 0.79', require: false
29
+ gem 'rubocop', '~> 0.82', require: false
30
30
  end
31
31
 
32
32
  group :test do
data/README.md CHANGED
@@ -52,7 +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
+ >= 1.0.0 | 2.0 | >= 1.3.0 | >= 0.5.0 | >= 2.4.1 |
56
56
 
57
57
 
58
58
  ## Swagger-Spec <a name="swagger-spec"></a>
@@ -1084,6 +1084,20 @@ or, for more definitions:
1084
1084
  route_setting :x_def, [{ for: 422, other: 'stuff' }, { for: 200, some: 'stuff' }]
1085
1085
  ```
1086
1086
 
1087
+ - `params` extension, add a `x` key to the `documentation` hash :
1088
+ ```ruby
1089
+ requires :foo, type: String, documentation: { x: { some: 'stuff' } }
1090
+ ```
1091
+ this would generate:
1092
+ ```json
1093
+ {
1094
+ "in": "formData",
1095
+ "name": "foo",
1096
+ "type": "string",
1097
+ "required": true,
1098
+ "x-some": "stuff"
1099
+ }
1100
+ ```
1087
1101
 
1088
1102
  #### Response examples documentation <a name="response-examples"></a>
1089
1103
 
@@ -1486,13 +1500,19 @@ end
1486
1500
 
1487
1501
  ## Rake Tasks <a name="rake"></a>
1488
1502
 
1489
- Add these lines to your Rakefile, and initialize the Task class with your Api class – be sure your Api class is available.
1503
+ Add these lines to your Rakefile, and initialize the Task class with your Api class.
1490
1504
 
1491
1505
  ```ruby
1492
1506
  require 'grape-swagger/rake/oapi_tasks'
1493
1507
  GrapeSwagger::Rake::OapiTasks.new(::Api::Base)
1494
1508
  ```
1495
1509
 
1510
+ You may initialize with the class name as a string if the class is not yet loaded at the time Rakefile is parsed:
1511
+ ```ruby
1512
+ require 'grape-swagger/rake/oapi_tasks'
1513
+ GrapeSwagger::Rake::OapiTasks.new('::Api::Base')
1514
+ ```
1515
+
1496
1516
  #### OpenApi/Swagger Documentation
1497
1517
 
1498
1518
  ```
@@ -1,5 +1,9 @@
1
1
  ## Upgrading Grape-swagger
2
2
 
3
+ ### Upgrading to >= 1.1.0
4
+
5
+ Full class name is used for referencing entity by default (e.g. `A::B::C` instead of just `C`). `Entity` and `Entities` suffixes and prefixes are omitted (e.g. if entity name is `Entities::SomeScope::MyFavourite::Entity` only `SomeScope::MyFavourite` will be used).
6
+
3
7
  ### Upgrading to >= 0.26.1
4
8
 
5
9
  The format can now be specified,
@@ -51,11 +51,11 @@ module GrapeSwagger
51
51
  if model.methods(false).include?(:entity_name)
52
52
  model.entity_name
53
53
  elsif model.to_s.end_with?('::Entity', '::Entities')
54
- model.to_s.split('::')[-2]
55
- elsif model.respond_to?(:name)
56
- model.name.demodulize.camelize
54
+ model.to_s.split('::')[0..-2].join('::')
55
+ elsif model.to_s.start_with?('Entity::', 'Entities::', 'Representable::')
56
+ model.to_s.split('::')[1..-1].join('::')
57
57
  else
58
- model.to_s.split('::').last
58
+ model.to_s
59
59
  end
60
60
  end
61
61
 
@@ -26,6 +26,7 @@ module GrapeSwagger
26
26
  document_range_values(settings) unless value_type[:is_array]
27
27
  document_required(settings)
28
28
  document_additional_properties(settings)
29
+ document_add_extensions(settings)
29
30
 
30
31
  @parsed_param
31
32
  end
@@ -62,6 +63,10 @@ module GrapeSwagger
62
63
  @parsed_param[:format] = settings[:format] if settings[:format].present?
63
64
  end
64
65
 
66
+ def document_add_extensions(settings)
67
+ GrapeSwagger::DocMethods::Extensions.add_extensions_to_root(settings, @parsed_param)
68
+ end
69
+
65
70
  def document_array_param(value_type, definitions)
66
71
  if value_type[:documentation].present?
67
72
  param_type = value_type[:documentation][:param_type]
@@ -345,7 +345,6 @@ module Grape
345
345
  raise GrapeSwagger::Errors::SwaggerSpec,
346
346
  "Empty model #{model_name}, swagger 2.0 doesn't support empty definitions."
347
347
  end
348
-
349
348
  @definitions[model_name] = GrapeSwagger::DocMethods::BuildModelDefinition.build(model, properties, required)
350
349
 
351
350
  model_name
@@ -10,17 +10,25 @@ module GrapeSwagger
10
10
  include Rack::Test::Methods
11
11
 
12
12
  attr_reader :oapi
13
- attr_reader :api_class
14
13
 
15
14
  def initialize(api_class)
16
15
  super()
17
16
 
18
- @api_class = api_class
17
+ if api_class.is_a? String
18
+ @api_class_name = api_class
19
+ else
20
+ @api_class = api_class
21
+ end
22
+
19
23
  define_tasks
20
24
  end
21
25
 
22
26
  private
23
27
 
28
+ def api_class
29
+ @api_class ||= @api_class_name.constantize
30
+ end
31
+
24
32
  def define_tasks
25
33
  namespace :oapi do
26
34
  fetch
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrapeSwagger
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
@@ -35,5 +35,5 @@ describe '#427 nested entity given as string' do
35
35
  JSON.parse(last_response.body)['definitions']
36
36
  end
37
37
 
38
- specify { expect(subject.keys).to include 'RoleEntity', 'WithoutRole' }
38
+ specify { expect(subject.keys).to include 'RoleEntity', 'Permission::WithoutRole' }
39
39
  end
@@ -82,11 +82,11 @@ describe 'definition names' do
82
82
  JSON.parse(last_response.body)['definitions']
83
83
  end
84
84
 
85
- specify { expect(subject).to include 'Class1' }
86
- specify { expect(subject).to include 'Class2' }
85
+ specify { expect(subject).to include 'TestDefinition::DummyEntities::WithVeryLongName::AnotherGroupingModule::Class1' }
86
+ specify { expect(subject).to include 'TestDefinition::DummyEntities::WithVeryLongName::AnotherGroupingModule::Class2' }
87
87
  specify { expect(subject).to include 'FooKlass' }
88
- specify { expect(subject).to include 'FourthEntity' }
89
- specify { expect(subject).to include 'FithEntity' }
88
+ specify { expect(subject).to include 'TestDefinition::DummyEntities::WithVeryLongName::AnotherGroupingModule::Class4::FourthEntity' }
89
+ specify { expect(subject).to include 'TestDefinition::DummyEntities::WithVeryLongName::AnotherGroupingModule::Class5::FithEntity' }
90
90
  specify { expect(subject).to include 'BarKlass' }
91
- specify { expect(subject).to include 'SeventhEntity' }
91
+ specify { expect(subject).to include 'TestDefinition::DummyEntities::WithVeryLongName::AnotherGroupingModule::Class7::SeventhEntity' }
92
92
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe '#532 allow custom format' do
6
+ let(:app) do
7
+ Class.new(Grape::API) do
8
+ namespace :issue_784 do
9
+ params do
10
+ requires :logs, type: String, documentation: { format: 'log', x: { name: 'Log' } }
11
+ optional :phone_number, type: Integer, documentation: { format: 'phone_number', x: { name: 'PhoneNumber' } }
12
+ end
13
+
14
+ post do
15
+ present params
16
+ end
17
+ end
18
+
19
+ add_swagger_documentation format: :json
20
+ end
21
+ end
22
+
23
+ subject do
24
+ get '/swagger_doc'
25
+ JSON.parse(last_response.body)
26
+ end
27
+
28
+ let(:parameters) { subject['paths']['/issue_784']['post']['parameters'] }
29
+
30
+ specify do
31
+ expect(parameters).to eql(
32
+ [
33
+ { 'in' => 'formData', 'name' => 'logs', 'type' => 'string', 'format' => 'log', 'required' => true, 'x-name' => 'Log' },
34
+ { 'in' => 'formData', 'name' => 'phone_number', 'type' => 'integer', 'format' => 'phone_number', 'required' => false, 'x-name' => 'PhoneNumber' }
35
+ ]
36
+ )
37
+ end
38
+ end
@@ -3,8 +3,8 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe GrapeSwagger::Rake::OapiTasks do
6
- let(:api) do
7
- item = Class.new(Grape::API) do
6
+ module Api
7
+ class Item < Grape::API
8
8
  version 'v1', using: :path
9
9
 
10
10
  namespace :item do
@@ -16,14 +16,24 @@ RSpec.describe GrapeSwagger::Rake::OapiTasks do
16
16
  end
17
17
  end
18
18
 
19
- Class.new(Grape::API) do
19
+ class Base < Grape::API
20
20
  prefix :api
21
- mount item
21
+ mount Api::Item
22
22
  add_swagger_documentation add_version: true
23
23
  end
24
24
  end
25
25
 
26
- subject { described_class.new(api) }
26
+ subject { described_class.new(Api::Base) }
27
+
28
+ describe '.new' do
29
+ it 'accepts class name as a constant' do
30
+ expect(described_class.new(::Api::Base).send(:api_class)).to eq(Api::Base)
31
+ end
32
+
33
+ it 'accepts class name as a string' do
34
+ expect(described_class.new('::Api::Base').send(:api_class)).to eq(Api::Base)
35
+ end
36
+ end
27
37
 
28
38
  describe '#make_request' do
29
39
  describe 'complete documentation' do
@@ -189,7 +189,7 @@ describe 'setting of param type, such as `query`, `path`, `formData`, `body`, `h
189
189
  'type' => 'object',
190
190
  'properties' => {
191
191
  'data' => {
192
- '$ref' => '#/definitions/ApiResponse',
192
+ '$ref' => '#/definitions/NestedModule::ApiResponse',
193
193
  'description' => 'request data'
194
194
  }
195
195
  },
@@ -207,7 +207,7 @@ describe 'setting of param type, such as `query`, `path`, `formData`, `body`, `h
207
207
  end
208
208
 
209
209
  specify do
210
- expect(subject['definitions']['ApiResponse']).not_to be_nil
210
+ expect(subject['definitions']['NestedModule::ApiResponse']).not_to be_nil
211
211
  end
212
212
 
213
213
  specify do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-swagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.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-02-09 00:00:00.000000000 Z
11
+ date: 2020-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
@@ -95,6 +95,7 @@ files:
95
95
  - spec/issues/650_params_array_spec.rb
96
96
  - spec/issues/680_keep_204_error_schemas_spec.rb
97
97
  - spec/issues/751_deeply_nested_objects_spec.rb
98
+ - spec/issues/784_extensions_on_params_spec.rb
98
99
  - spec/lib/data_type_spec.rb
99
100
  - spec/lib/endpoint/params_parser_spec.rb
100
101
  - spec/lib/endpoint_spec.rb
@@ -217,6 +218,7 @@ test_files:
217
218
  - spec/issues/650_params_array_spec.rb
218
219
  - spec/issues/680_keep_204_error_schemas_spec.rb
219
220
  - spec/issues/751_deeply_nested_objects_spec.rb
221
+ - spec/issues/784_extensions_on_params_spec.rb
220
222
  - spec/lib/data_type_spec.rb
221
223
  - spec/lib/endpoint/params_parser_spec.rb
222
224
  - spec/lib/endpoint_spec.rb