grape-swagger 1.4.2 → 1.5.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: 5d7b364d5b11e9fb35f7c67ce09c2953a7dd50da37cde1bc5b323bbdf9a3b6e4
4
- data.tar.gz: 6c825fe6753c899c7f337253495677596acd40320e5e33f83c7c220e71e03e44
3
+ metadata.gz: c2826417c60f2f12c57698a03f03a15b9c1603c9c19a5cfc5c6594aec5512f13
4
+ data.tar.gz: ed6a07977e30c0ec647f41e60acf2d0184ba8f8531c626da87213aa1136fec1b
5
5
  SHA512:
6
- metadata.gz: d5e2a5c0d06216c3e2a474051b5986a9f8343a351714b3e255396bbef3984704d85436218fa87e39f0988fbb18b3f5227b2531d514a788f4a4b131028dc19de2
7
- data.tar.gz: 6bd210a20332285224d0d24036b9892c729fc84c435991b3e36dd81d8d1976d4ae35c406d3e9d742a82bd90acac75903355c6a827380870e6f1deb2af0b17b7f
6
+ metadata.gz: e032c09183d38e9ce114cb0c02f6c083a8d79339975678265ef2b6dc49945c8e977c4c2785a62f6aea0d0cc42ae72c8a6ece4cdd8d2fdb9db938eb27a819e25f
7
+ data.tar.gz: 42779db4d2991ddc177027f9ae4526dd6ff999faaf7abdd6a8f9cf44978878a19ce300b1440f32eaf562ca1575d1cc7f0c1a9215366eb66683d53a299767c5b0
@@ -12,3 +12,9 @@ updates:
12
12
  day: "friday"
13
13
  assignees:
14
14
  - "LeFnord"
15
+ - package-ecosystem: "github-actions"
16
+ directory: "/"
17
+ schedule:
18
+ interval: weekly
19
+ assignees:
20
+ - "LeFnord"
@@ -0,0 +1,45 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - '*'
7
+ pull_request:
8
+ branches:
9
+ - '*'
10
+
11
+ permissions:
12
+ contents: read
13
+
14
+ jobs:
15
+ rubocop:
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: actions/checkout@v3
19
+ - uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: '3.1'
22
+ bundler-cache: true
23
+ - name: Run rubocop
24
+ run: bundle exec rubocop --parallel --format progress
25
+
26
+ rspec:
27
+ runs-on: ubuntu-latest
28
+ needs: ['rubocop']
29
+ strategy:
30
+ matrix:
31
+ ruby-version: ['2.7', '3.0', '3.1', 'head']
32
+ grape-version: [1.6.2, 1.5.3]
33
+ model-parser: [grape-swagger-entity, grape-swagger-representable, '']
34
+ steps:
35
+ - name: Check out branch
36
+ uses: actions/checkout@v3
37
+ - name: Set up Ruby
38
+ uses: ruby/setup-ruby@v1
39
+ with:
40
+ ruby-version: ${{ matrix.ruby-version }}
41
+ GRAPE_VERSION: ${{ matrix.grape-version }}
42
+ MODEL_PARSER: ${{ matrix.model-parser }}
43
+ bundler-cache: true
44
+ - name: Run rspec rest of the suite
45
+ run: bundle exec rspec
data/.rubocop.yml CHANGED
@@ -5,7 +5,7 @@ AllCops:
5
5
  - vendor/**/*
6
6
  - example/**/*
7
7
  NewCops: enable
8
- TargetRubyVersion: 3.0
8
+ TargetRubyVersion: 3.1
9
9
  SuggestExtensions: false
10
10
 
11
11
  # Layout stuff
@@ -101,12 +101,19 @@ Style/HashEachMethods:
101
101
  Style/HashLikeCase:
102
102
  Enabled: true
103
103
 
104
+ Style/HashSyntax:
105
+ Enabled: false
106
+
104
107
  Style/HashTransformKeys:
105
108
  Enabled: true
106
109
 
107
110
  Style/HashTransformValues:
108
111
  Enabled: true
109
112
 
113
+ Style/OpenStructUse:
114
+ Exclude:
115
+ - spec/**/*
116
+
110
117
  Style/RegexpLiteral:
111
118
  Enabled: false
112
119
 
data/.rubocop_todo.yml CHANGED
@@ -1,11 +1,19 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-06-05 12:13:59 +0000 using RuboCop version 0.71.0.
3
+ # on 2022-01-14 10:22:29 UTC using RuboCop version 1.24.1.
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: 1
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: Include.
12
+ # Include: **/*.gemspec
13
+ Gemspec/RequireMFA:
14
+ Exclude:
15
+ - 'grape-swagger.gemspec'
16
+
9
17
  # Offense count: 1
10
18
  # Configuration parameters: Include.
11
19
  # Include: **/*.gemspec
@@ -13,20 +21,18 @@ Gemspec/RequiredRubyVersion:
13
21
  Exclude:
14
22
  - 'grape-swagger.gemspec'
15
23
 
16
- # Offense count: 30
24
+ # Offense count: 31
25
+ # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
17
26
  Metrics/AbcSize:
18
- Max: 59
19
-
20
- # Offense count: 10
21
- Metrics/CyclomaticComplexity:
22
- Max: 13
27
+ Max: 56
23
28
 
24
- # Offense count: 22
25
- # Configuration parameters: CountComments, ExcludedMethods.
29
+ # Offense count: 30
30
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
26
31
  Metrics/MethodLength:
27
- Max: 45
32
+ Max: 28
28
33
 
29
34
  # Offense count: 7
35
+ # Configuration parameters: IgnoredMethods.
30
36
  Metrics/PerceivedComplexity:
31
37
  Max: 16
32
38
 
@@ -35,6 +41,20 @@ Style/ClassVars:
35
41
  Exclude:
36
42
  - 'lib/grape-swagger/doc_methods.rb'
37
43
 
38
- # Offense count: 22
44
+ # Offense count: 23
45
+ # Configuration parameters: AllowedConstants.
39
46
  Style/Documentation:
40
47
  Enabled: false
48
+
49
+ # Offense count: 43
50
+ Style/OpenStructUse:
51
+ Exclude:
52
+ - 'spec/lib/endpoint_spec.rb'
53
+ - 'spec/lib/version_spec.rb'
54
+ - 'spec/support/mock_parser.rb'
55
+ - 'spec/support/model_parsers/mock_parser.rb'
56
+ - 'spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb'
57
+ - 'spec/swagger_v2/api_swagger_v2_mounted_spec.rb'
58
+ - 'spec/swagger_v2/api_swagger_v2_spec.rb'
59
+ - 'spec/swagger_v2/errors_spec.rb'
60
+ - 'spec/swagger_v2/reference_entity_spec.rb'
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### Next
1
+ ### next
2
2
 
3
3
  #### Features
4
4
 
@@ -9,6 +9,38 @@
9
9
  * Your contribution here.
10
10
 
11
11
 
12
+ ### 1.5.0 (July 28, 2022)
13
+
14
+ #### Features
15
+
16
+ * [#862](https://github.com/ruby-grape/grape-swagger/pull/862): Allow using nicknames for body definitions - [@magni-](https://github.com/magni-)
17
+
18
+ #### Fixes
19
+
20
+ * [#860](https://github.com/ruby-grape/grape-swagger/pull/860) chore: Included githubactions in the dependabot config [@naveensrinivasan](https://github.com/naveensrinivasan)
21
+ * [#843](https://github.com/ruby-grape/grape-swagger/pull/843) Syntax errors in README.md examples [@remvee](https://github.com/remvee)
22
+ * [#844](https://github.com/ruby-grape/grape-swagger/pull/844) Fixes the regexp used for parsing routes [@senhalil](https://github.com/senhalil)
23
+ * [#847](https://github.com/ruby-grape/grape-swagger/pull/847) Parse route_param type for nested endpoints [@dmoss18](https://github.com/dmoss18)
24
+ * [#856](https://github.com/ruby-grape/grape-swagger/pull/856) Remove unused methods in GrapeSwagger::DocMethods::BuildModelDefinition [@takahashim](https://github.com/takahashim)
25
+ * [#858](https://github.com/ruby-grape/grape-swagger/pull/858): Set permissions for GitHub actions [@naveensrinivasan](https://github.com/naveensrinivasan)
26
+ * [#853](https://github.com/ruby-grape/grape-swagger/pull/853): Add webrick to support Ruby 3.x [@takahashim](https://github.com/takahashim)
27
+ * [#852](https://github.com/ruby-grape/grape-swagger/pull/852): Fix example to work [@takahashim](https://github.com/takahashim)
28
+ * [#846](https://github.com/ruby-grape/grape-swagger/pull/846): Refactor oapi fetch task [@Vachman](https://github.com/Vachman)
29
+ * [#850](https://github.com/ruby-grape/grape-swagger/pull/850): Fix value of enum to be Array [@takahashim](https://github.com/takahashim)
30
+
31
+
32
+ ### 1.4.3 (January 5, 2022)
33
+
34
+ #### Fixes
35
+
36
+ * [#850](https://github.com/ruby-grape/grape-swagger/pull/850): Fix value of `enum` to be `Array` - [@takahashim](https://github.com/takahashim)
37
+ * [#846](https://github.com/ruby-grape/grape-swagger/pull/846): Fixes oapi rake tasks, allows generating sepcs for different API versions.
38
+ * [#852](https://github.com/ruby-grape/grape-swagger/pull/852): Fix example to work without error - [@takahashim](https://github.com/takahashim)
39
+ * [#853](https://github.com/ruby-grape/grape-swagger/pull/853): Add webrick gem so that example works in Ruby 3.x - [@takahashim](https://github.com/takahashim)
40
+ * [#844](https://github.com/ruby-grape/grape-swagger/pull/844): Fixes the regexp used for parsing routes - [@senhalil](https://github.com/senhalil)
41
+ * [#862](https://github.com/ruby-grape/grape-swagger/pull/862): Allow using nicknames for body definitions - [@magni-](https://github.com/magni-)
42
+ * Your contribution here.
43
+
12
44
  ### 1.4.2 (October 22, 2021)
13
45
 
14
46
  #### Fixes
data/CONTRIBUTING.md CHANGED
@@ -115,7 +115,7 @@ git push origin my-feature-branch -f
115
115
 
116
116
  ## Check on Your Pull Request
117
117
 
118
- Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
118
+ Go back to your pull request after a few minutes and see whether it passed muster with GitHub Actions. Everything should look green, otherwise fix issues and amend your commit as described above.
119
119
 
120
120
  ## Be Patient
121
121
 
data/Gemfile CHANGED
@@ -6,14 +6,14 @@ ruby RUBY_VERSION
6
6
 
7
7
  gemspec
8
8
 
9
- gem 'grape', case version = ENV['GRAPE_VERSION'] || '>= 1.5.0'
9
+ gem 'grape', case version = ENV.fetch('GRAPE_VERSION', '~> 1.6')
10
10
  when 'HEAD'
11
11
  { git: 'https://github.com/ruby-grape/grape' }
12
12
  else
13
13
  version
14
14
  end
15
15
 
16
- gem ENV['MODEL_PARSER'] if ENV.key?('MODEL_PARSER')
16
+ gem ENV.fetch('MODEL_PARSER', nil) if ENV.key?('MODEL_PARSER')
17
17
 
18
18
  group :development, :test do
19
19
  gem 'bundler'
@@ -28,6 +28,7 @@ group :development, :test do
28
28
  gem 'rdoc'
29
29
  gem 'rspec', '~> 3.9'
30
30
  gem 'rubocop', '~> 1.0', require: false
31
+ gem 'webrick'
31
32
  end
32
33
 
33
34
  group :test do
@@ -35,7 +36,9 @@ group :test do
35
36
 
36
37
  gem 'ruby-grape-danger', '~> 0.2.0', require: false
37
38
  gem 'simplecov', require: false
39
+ end
38
40
 
41
+ group :test, :development do
39
42
  unless ENV['MODEL_PARSER'] == 'grape-swagger-entity'
40
43
  gem 'grape-swagger-entity', git: 'https://github.com/ruby-grape/grape-swagger-entity'
41
44
  end
data/README.md CHANGED
@@ -817,7 +817,7 @@ The example parameter will populate the Swagger UI with the example value, and c
817
817
  ```ruby
818
818
  params do
819
819
  requires :id, type: Integer, documentation: { example: 123 }
820
- optional :name, type String, documentation: { example: 'Buddy Guy' }
820
+ optional :name, type: String, documentation: { example: 'Buddy Guy' }
821
821
  end
822
822
  ```
823
823
 
@@ -843,7 +843,7 @@ namespace 'store/order', desc: 'Order operations within a store', swagger: { nes
843
843
  get :order_id do
844
844
  ...
845
845
  end
846
- namespace 'actions', desc: 'Order actions' do, nested: false
846
+ namespace 'actions', desc: 'Order actions', nested: false do
847
847
  get 'evaluate' do
848
848
  ...
849
849
  end
@@ -1265,7 +1265,7 @@ end
1265
1265
 
1266
1266
  The result will look like following:
1267
1267
 
1268
- ```
1268
+ ```json
1269
1269
  "responses": {
1270
1270
  "200": {
1271
1271
  "description": "Get a kitten",
@@ -1292,7 +1292,7 @@ end
1292
1292
 
1293
1293
  The result will look like following:
1294
1294
 
1295
- ```
1295
+ ```json
1296
1296
  "responses": {
1297
1297
  "200": {
1298
1298
  "description": "Get kittens",
@@ -1319,7 +1319,7 @@ get '/things' do
1319
1319
  end
1320
1320
  ```
1321
1321
  The result will look like following:
1322
- ```
1322
+ ```json
1323
1323
  "responses": {
1324
1324
  "200": {
1325
1325
  "description": "Multiple response",
@@ -1351,7 +1351,7 @@ get '/things' do
1351
1351
  end
1352
1352
  ```
1353
1353
  The result will look like following:
1354
- ```
1354
+ ```json
1355
1355
  "responses": {
1356
1356
  "200": {
1357
1357
  "description": "Multiple response with array",
@@ -1525,7 +1525,7 @@ end
1525
1525
  ```
1526
1526
 
1527
1527
  Should generate this definitions:
1528
- ```JSON
1528
+ ```json
1529
1529
  {
1530
1530
  "definitions": {
1531
1531
  "Pet": {
@@ -1718,9 +1718,10 @@ GrapeSwagger::Rake::OapiTasks.new('::Api::Base')
1718
1718
  ```
1719
1719
  rake oapi:fetch
1720
1720
  params:
1721
- - store={ true | file_name } – save as JSON (optional)
1721
+ - store={ true | file_name.json } – save as JSON (optional)
1722
1722
  - resource=resource_name – get only for this one (optional)
1723
1723
  ```
1724
+ For mutliversion API it creates several files with following naming: file_name_`API_VERSION`.json
1724
1725
 
1725
1726
  #### OpenApi/Swagger Validation
1726
1727
 
data/UPGRADING.md CHANGED
@@ -1,8 +1,19 @@
1
1
  ## Upgrading Grape-swagger
2
2
 
3
+ ### Upgrading to >= 1.5.0
4
+
5
+ - The names generated for body parameter definitions and their references has changed. It'll now include the HTTP action as well as any path parameters.
6
+ - E.g, given a `PUT /things/:id` endpoint, `paths.things/{id}.put.parameters` in the generated Swaggerfile will contain the following:
7
+ - With `grape-swagger < 1.5.0`: `{ "name": "Things", ..., "schema": { "$ref": "#/definitions/putThings" } }`
8
+ - With `grape-swagger >= 1.5.0`: `{ "name": "putThingsId", ..., "schema": { "$ref": "#/definitions/putThingsId" } }`
9
+ - If you use the `nickname` option for an endpoint, that nickname will be used for both the parameter name and its definition reference.
10
+ - E.g., if the endpoint above were nicknamed `put-thing`, the generated Swaggerfile will contain `{ "name": "put-thing", ..., "schema": { "$ref": "#/definitions/put-thing" } }`
11
+
12
+
3
13
  ### Upgrading to >= 1.4.2
4
14
 
5
15
  - `additionalProperties` has been deprecated and will be removed in a future version of `grape-swagger`. It has been replaced with `additional_properties`.
16
+ - The value of the `enum` attribute is now always an Array. If it has only one value, it will be a one-element Array.
6
17
 
7
18
  ### Upgrading to >= 1.4.0
8
19
 
data/example/config.ru CHANGED
@@ -1,4 +1,5 @@
1
- require 'rack/cors'
1
+ Bundler.require ENV['RACK_ENV']
2
+
2
3
  use Rack::Cors do
3
4
  allow do
4
5
  origins '*'
@@ -12,7 +13,6 @@ require './api/endpoints'
12
13
  require './api/entities'
13
14
 
14
15
  class Base < Grape::API
15
- require 'grape-entity'
16
16
  require '../lib/grape-swagger'
17
17
  format :json
18
18
 
@@ -13,10 +13,11 @@ Gem::Specification.new do |s|
13
13
  s.summary = 'Add auto generated documentation to your Grape API that can be displayed with Swagger.'
14
14
  s.license = 'MIT'
15
15
 
16
- s.required_ruby_version = '>= 2.5'
16
+ s.metadata['rubygems_mfa_required'] = 'true'
17
+
18
+ s.required_ruby_version = '>= 2.7'
17
19
  s.add_runtime_dependency 'grape', '~> 1.3'
18
20
 
19
21
  s.files = `git ls-files`.split("\n")
20
- s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
21
22
  s.require_paths = ['lib']
22
23
  end
@@ -4,14 +4,9 @@ module GrapeSwagger
4
4
  module DocMethods
5
5
  class BuildModelDefinition
6
6
  class << self
7
- def build(model, properties, required, other_def_properties = {})
7
+ def build(_model, properties, required, other_def_properties = {})
8
8
  definition = { type: 'object', properties: properties }.merge(other_def_properties)
9
9
 
10
- if required.nil?
11
- required_attrs = required_attributes(model)
12
- definition[:required] = required_attrs unless required_attrs.blank?
13
- end
14
-
15
10
  definition[:required] = required if required.is_a?(Array) && required.any?
16
11
 
17
12
  definition
@@ -67,20 +62,6 @@ module GrapeSwagger
67
62
  end
68
63
  end
69
64
  end
70
-
71
- private
72
-
73
- def required_attributes(model)
74
- parse_entity(model) || parse_representable(model)
75
- end
76
-
77
- def parse_entity(model)
78
- return unless model.respond_to?(:documentation)
79
- end
80
-
81
- def parse_representable(model)
82
- return unless model.respond_to?(:map)
83
- end
84
65
  end
85
66
  end
86
67
  end
@@ -38,15 +38,15 @@ module GrapeSwagger
38
38
  end
39
39
 
40
40
  def parent_definition_of_params(params, path, route)
41
- definition_name = OperationId.manipulate(parse_model(path))
42
- referenced_definition = build_definition(definition_name, params, route.request_method.downcase)
43
- definition = @definitions[referenced_definition]
41
+ definition_name = OperationId.build(route, path)
42
+ build_definition(definition_name, params)
43
+ definition = @definitions[definition_name]
44
44
 
45
45
  move_params_to_new(definition, params)
46
46
 
47
47
  definition[:description] = route.description if route.try(:description)
48
48
 
49
- build_body_parameter(referenced_definition, definition_name, route.options)
49
+ build_body_parameter(definition_name, route.options)
50
50
  end
51
51
 
52
52
  def move_params_to_new(definition, params)
@@ -142,17 +142,16 @@ module GrapeSwagger
142
142
  definition[:required].push(*value)
143
143
  end
144
144
 
145
- def build_body_parameter(reference, name, options)
145
+ def build_body_parameter(name, options)
146
146
  {}.tap do |x|
147
147
  x[:name] = options[:body_name] || name
148
148
  x[:in] = 'body'
149
149
  x[:required] = true
150
- x[:schema] = { '$ref' => "#/definitions/#{reference}" }
150
+ x[:schema] = { '$ref' => "#/definitions/#{name}" }
151
151
  end
152
152
  end
153
153
 
154
- def build_definition(name, params, verb = nil)
155
- name = "#{verb}#{name}" if verb
154
+ def build_definition(name, params)
156
155
  @definitions[name] = should_expose_as_array?(params) ? array_type : object_type
157
156
 
158
157
  name
@@ -163,8 +163,10 @@ module GrapeSwagger
163
163
  parse_enum_or_range_values(values.call) if values.parameters.empty?
164
164
  when Range
165
165
  parse_range_values(values) if values.first.is_a?(Integer)
166
+ when Array
167
+ { enum: values }
166
168
  else
167
- { enum: values } if values
169
+ { enum: [values] } if values
168
170
  end
169
171
  end
170
172
 
@@ -348,13 +348,39 @@ module Grape
348
348
  end
349
349
 
350
350
  def merge_params(route)
351
+ path_params = get_path_params(route.app&.inheritable_setting&.namespace_stackable)
351
352
  param_keys = route.params.keys
353
+
354
+ # Merge path params options into route params
355
+ route_params = route.params
356
+ route_params.each_key do |key|
357
+ path = path_params[key] || {}
358
+ params = route_params[key]
359
+ params = {} unless params.is_a? Hash
360
+ route_params[key] = path.merge(params)
361
+ end
362
+
352
363
  route.params.delete_if { |key| key.is_a?(String) && param_keys.include?(key.to_sym) }.to_a
353
364
  end
354
365
 
366
+ # Iterates over namespaces recursively
367
+ # to build a hash of path params with options, including type
368
+ def get_path_params(stackable_values)
369
+ params = {}
370
+ return param unless stackable_values
371
+ return params unless stackable_values.is_a? Grape::Util::StackableValues
372
+
373
+ stackable_values&.new_values&.dig(:namespace)&.each do |namespace|
374
+ space = namespace.space.to_s.gsub(':', '')
375
+ params[space] = namespace.options || {}
376
+ end
377
+ inherited_params = get_path_params(stackable_values.inherited_values)
378
+ inherited_params.merge(params)
379
+ end
380
+
355
381
  def default_type(params)
356
382
  default_param_type = { required: true, type: 'Integer' }
357
- params.each { |param| param[-1] = param.last == '' ? default_param_type : param.last }
383
+ params.each { |param| param[-1] = param.last.empty? ? default_param_type : param.last }
358
384
  end
359
385
 
360
386
  def expose_params(value)
@@ -46,9 +46,12 @@ module GrapeSwagger
46
46
  resource - if given only for that it would be generated (optional)'
47
47
  task fetch: :environment do
48
48
  # :nocov:
49
- make_request
49
+ urls_for(api_class).each do |url|
50
+ make_request(url)
51
+
52
+ save_to_file? ? File.write(file(url), @oapi) : $stdout.print(@oapi)
53
+ end
50
54
 
51
- save_to_file? ? File.write(file, @oapi) : $stdout.print(@oapi)
52
55
  # :nocov:
53
56
  end
54
57
  end
@@ -64,10 +67,15 @@ module GrapeSwagger
64
67
  ::Rake::Task['oapi:fetch'].invoke
65
68
  exit if error?
66
69
 
67
- output = system "swagger-cli validate #{file}"
70
+ urls_for(api_class).each do |url|
71
+ @output = system "swagger-cli validate #{file(url)}"
72
+
73
+ FileUtils.rm(
74
+ file(url)
75
+ )
76
+ end
68
77
 
69
- $stdout.puts 'install swagger-cli with `npm install swagger-cli -g`' if output.nil?
70
- FileUtils.rm(file)
78
+ $stdout.puts 'install swagger-cli with `npm install swagger-cli -g`' if @output.nil?
71
79
  # :nocov:
72
80
  end
73
81
  end
@@ -75,23 +83,28 @@ module GrapeSwagger
75
83
  # helper methods
76
84
  #
77
85
  # rubocop:disable Style/StringConcatenation
78
- def make_request
79
- get url_for
86
+ def make_request(url)
87
+ get url
80
88
 
81
89
  @oapi = JSON.pretty_generate(
82
- JSON.parse(
83
- last_response.body, symolize_names: true
84
- )
90
+ JSON.parse(last_response.body, symolize_names: true)
85
91
  ) + "\n"
86
92
  end
87
93
  # rubocop:enable Style/StringConcatenation
88
94
 
89
- def url_for
90
- oapi_route = api_class.routes[-2]
91
- path = oapi_route.path.sub(/\(\.\w+\)$/, '').sub(/\(\.:\w+\)$/, '')
92
- path.sub!(':version', oapi_route.version.to_s)
95
+ def urls_for(api_class)
96
+ api_class.routes
97
+ .map(&:path)
98
+ .select { |e| e.include?('doc') }
99
+ .reject { |e| e.include?(':name') }
100
+ .map { |e| format_path(e) }
101
+ .map { |e| [e, ENV.fetch('resource', nil)].join('/').chomp('/') }
102
+ end
93
103
 
94
- [path, ENV['resource']].join('/').chomp('/')
104
+ def format_path(path)
105
+ oapi_route = api_class.routes.select { |e| e.path == path }.first
106
+ path = path.sub(/\(\.\w+\)$/, '').sub(/\(\.:\w+\)$/, '')
107
+ path.sub(':version', oapi_route.version.to_s)
95
108
  end
96
109
 
97
110
  def save_to_file?
@@ -102,8 +115,15 @@ module GrapeSwagger
102
115
  JSON.parse(@oapi).keys.first == 'error'
103
116
  end
104
117
 
105
- def file
106
- name = ENV['store'] == 'true' || ENV['store'].blank? ? 'swagger_doc.json' : ENV['store']
118
+ def file(url)
119
+ api_version = url.split('/').last
120
+
121
+ name = if ENV['store'] == 'true' || ENV['store'].blank?
122
+ "swagger_doc_#{api_version}.json"
123
+ else
124
+ ENV['store'].sub('.json', "_#{api_version}.json")
125
+ end
126
+
107
127
  File.join(Dir.getwd, name)
108
128
  end
109
129
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrapeSwagger
4
- VERSION = '1.4.2'
4
+ VERSION = '1.5.0'
5
5
  end
data/lib/grape-swagger.rb CHANGED
@@ -31,8 +31,8 @@ module SwaggerRouting
31
31
 
32
32
  # want to match emojis … ;)
33
33
  # route_match = route_match
34
- # .match('\/([\p{Alnum}|\p{Emoji}|\-|\_]*?)[\.\/\(]') || route_match.match('\/([\p{Alpha}|\p{Emoji}|\-|\_]*)$')
35
- route_match = route_match.match('\/([\p{Alnum}|\-|\_]*?)[\.\/\(]') || route_match.match('\/([\p{Alpha}|\-|\_]*)$')
34
+ # .match('\/([\p{Alnum}p{Emoji}\-\_]*?)[\.\/\(]') || route_match.match('\/([\p{Alpha}\p{Emoji}\-\_]*)$')
35
+ route_match = route_match.match('\/([\p{Alnum}\-\_]*?)[\.\/\(]') || route_match.match('\/([\p{Alpha}\-\_]*)$')
36
36
  next unless route_match
37
37
 
38
38
  resource = route_match.captures.first
@@ -103,8 +103,8 @@ describe '#579 put / post parameters spec' do
103
103
  [
104
104
  { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
105
105
  {
106
- 'name' => 'Issue579ImplicitBodyParameter', 'in' => 'body', 'required' => true, 'schema' => {
107
- '$ref' => '#/definitions/putIssue579ImplicitBodyParameter'
106
+ 'name' => 'putIssue579ImplicitBodyParameterGuid', 'in' => 'body', 'required' => true, 'schema' => {
107
+ '$ref' => '#/definitions/putIssue579ImplicitBodyParameterGuid'
108
108
  }
109
109
  }
110
110
  ]
@@ -130,8 +130,8 @@ describe '#579 put / post parameters spec' do
130
130
  [
131
131
  { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
132
132
  {
133
- 'name' => 'Issue579ExplicitBodyParameter', 'in' => 'body', 'required' => true, 'schema' => {
134
- '$ref' => '#/definitions/putIssue579ExplicitBodyParameter'
133
+ 'name' => 'putIssue579ExplicitBodyParameterGuid', 'in' => 'body', 'required' => true, 'schema' => {
134
+ '$ref' => '#/definitions/putIssue579ExplicitBodyParameterGuid'
135
135
  }
136
136
  }
137
137
  ]
@@ -157,7 +157,7 @@ describe '#579 put / post parameters spec' do
157
157
  [
158
158
  { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
159
159
  {
160
- 'name' => 'Issue579NamespaceParamGuidBodyParameter', 'in' => 'body', 'required' => true, 'schema' => {
160
+ 'name' => 'putIssue579NamespaceParamGuidBodyParameter', 'in' => 'body', 'required' => true, 'schema' => {
161
161
  '$ref' => '#/definitions/putIssue579NamespaceParamGuidBodyParameter'
162
162
  }
163
163
  }