swagger_docs_generator 0.3.5 → 0.3.6.pre.34

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
  SHA1:
3
- metadata.gz: 27fde121cf7c356443ed2dae43ad719e059a1f50
4
- data.tar.gz: bbe30b62e53b12fba3327d8ed37d6f7c9e281897
3
+ metadata.gz: b0d5baad818850dbd3ff75f23ffb8560e5063521
4
+ data.tar.gz: 2832ad4e8d604d6517ae8983df8d07a3baf8e8e0
5
5
  SHA512:
6
- metadata.gz: c9e2423b38ecbe6b5e36f2d4103e0a6c569636688d97ae4ee7bbc4b01330f798cd7748f3284502171fbd4706d38ba4360e7fa16da0f0006c39324185f2becb1f
7
- data.tar.gz: aa0815acac4205505fe4a235a7cf03bd7819ac7bc8a65bc7d6ddc87da29283a596a5bf5b38f943fec31b9b47f663936b244b63d9dd6bee30f2678ead0cdc7ffe
6
+ metadata.gz: cd0c15b13abb397a8437fdef01f55448c8b9cde9689faa7e34b26709d12b1c08ec5a1c5f2f97d8f8deae141808131f234739eb656743a713e7ab17ea532fcefa
7
+ data.tar.gz: 16e02dfd9f2431c26d7d4c7788a80d725b9aa125624c9ad036b72da3d840b2965bc4e8029bbaea9d6911e533a604a687fd773f8a0724c7ad70e736b03e910229
@@ -7,12 +7,12 @@ module SwaggerDocsGenerator
7
7
  class EnvironmentGenerator < Rails::Generators::Base
8
8
  desc 'Generate a Environment `doc` for Swagger Docs Generator'
9
9
  ENVIRONMENT = <<-INIT
10
- # frozen_string_literal: true
10
+ # frozen_string_literal: true
11
11
 
12
- Rails.application.configure do
13
- # Do not eader load code on boot.
14
- config.eager_load = false
15
- end
12
+ Rails.application.configure do
13
+ # Do not eader load code on boot.
14
+ config.eager_load = false
15
+ end
16
16
  INIT
17
17
 
18
18
  # Create a new environment
@@ -7,20 +7,20 @@ module SwaggerDocsGenerator
7
7
  class InitializerGenerator < Rails::Generators::Base
8
8
  desc 'Generate a initializer for Swagger Docs Generator'
9
9
  INITIALIZER = <<-INIT
10
- # frozen_string_literal: true
10
+ # frozen_string_literal: true
11
11
 
12
- if Rails.env.doc?
13
- SwaggerDocsGenerator.configure do |config|
14
- config.swagger = '2.2.4' # Swagger version used
15
- config.base_path = '/' # Base to API
16
- config.host = 'localhost:3000' # Host api
17
- end
12
+ if Rails.env.doc?
13
+ SwaggerDocsGenerator.configure do |config|
14
+ config.swagger = '2.2.4' # Swagger version used
15
+ config.base_path = '/' # Base to API
16
+ config.host = 'localhost:3000' # Host api
17
+ end
18
18
 
19
- SwaggerDocsGenerator.configure_info do |info|
20
- info.title = 'API example.com' # Title to API
21
- info.version = 'v1' # Version to API
19
+ SwaggerDocsGenerator.configure_info do |info|
20
+ info.title = 'API example.com' # Title to API
21
+ info.version = 'v1' # Version to API
22
+ end
22
23
  end
23
- end
24
24
  INIT
25
25
 
26
26
  # Create initializer
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # :reek:NestedIterators
4
+ # :reek:TooManyStatements
5
+ # :reek:UtilityFunction
4
6
 
5
7
  module SwaggerDocsGenerator
6
8
  # # Extractor routes info
@@ -22,12 +24,14 @@ module SwaggerDocsGenerator
22
24
 
23
25
  # Extract path to routes and change format to parameter path
24
26
  def path
27
+ temporary = []
28
+ actual_route = nil
25
29
  router do |route|
26
- route.path.spec.to_s.gsub('(.:format)',
27
- '.json').gsub(/:[a-z1-9_A-Z]*/) do |word|
28
- "{#{word.delete(':')}}"
29
- end
30
+ actual_route = extract_and_format_route(route)
31
+ temporary.push(actual_route) unless temporary.include?(actual_route)
32
+ actual_route
30
33
  end
34
+ temporary
31
35
  end
32
36
 
33
37
  private
@@ -52,5 +56,12 @@ module SwaggerDocsGenerator
52
56
  end
53
57
  data.downcase
54
58
  end
59
+
60
+ def extract_and_format_route(route)
61
+ route.path.spec.to_s.gsub('(.:format)',
62
+ '.json').gsub(/:[a-z1-9_A-Z]*/) do |word|
63
+ "{#{word.delete(':')}}"
64
+ end
65
+ end
55
66
  end
56
67
  end
@@ -5,7 +5,7 @@ module SwaggerDocsGenerator
5
5
  # Name to gem
6
6
  GEM = 'swagger_docs_generator'
7
7
  # Version to gem
8
- VERSION = '0.3.5'
8
+ VERSION = '0.3.6'
9
9
  # Authors contributed to gem
10
10
  AUTHORS = ['VAILLANT Jeremy'].freeze
11
11
  # Email to ahuthors
@@ -5,8 +5,8 @@ module SwaggerDocsGenerator
5
5
  #
6
6
  # Metadata generated in swagger json file
7
7
  class Metadata
8
- ACCEPT = %i(title version contact description host schemes base_path
9
- swagger).freeze
8
+ ACCEPT = %i[title version contact description host schemes base_path
9
+ swagger].freeze
10
10
 
11
11
  def initialize
12
12
  @config = nil
@@ -6,9 +6,15 @@ require 'swagger_docs_generator/parser/actions/actions'
6
6
  # :reek:InstanceVariableAssumption
7
7
  # :reek:TooManyInstanceVariables
8
8
  # :reek:TooManyStatements
9
+ # :reek:DuplicateMethodCall
10
+ # :reek:FeatureEnvy
11
+ # :reek:TooManyMethods
12
+ # :reek:LongParameterList
9
13
 
10
14
  # rubocop:disable Metrics/AbcSize
11
15
  # rubocop:disable Metrics/CyclomaticComplexity
16
+ # rubocop:disable Style/MultilineIfModifier
17
+ # rubocop:disable Metrics/ClassLength
12
18
  module SwaggerDocsGenerator
13
19
  # # Parse action in controller classe to Rails application. It's adding
14
20
  # paths to swagger docs file.
@@ -36,26 +42,52 @@ module SwaggerDocsGenerator
36
42
  old_route = json['paths']
37
43
 
38
44
  keys_new = hash.keys[0]
39
- index = keys_new.to_s
45
+ paths = hash.keys.split.first
40
46
 
47
+ test_tags(paths, hash)
48
+ merge_hashes(old_route, keys_new.to_s, paths, hash)
49
+ end
50
+
51
+ def test_tags(paths, hash)
52
+ paths.each do |path|
53
+ tag = extract_tag(path)
54
+ next unless path.downcase.include?(tag.downcase) &&
55
+ !hash[path][@verb][:tags].include?(tag) &&
56
+ !tag.include?('.json')
57
+ add_tag(hash, path, tag)
58
+ end if paths.count <= 2
59
+ end
60
+
61
+ def add_tag(hash, path, tag)
62
+ hash[path][@verb][:tags].push(tag)
63
+ hash[path]['patch'][:tags].push(tag) if @verb.eql?('put')
64
+ end
65
+
66
+ def merge_hashes(old_route, index, paths, hash)
41
67
  if !old_route.blank? && old_route.keys.include?(index)
42
- old_route[index].merge!(hash[keys_new])
68
+ paths.each do |path|
69
+ old_route[path].merge!(hash[path])
70
+ end
43
71
  else
44
72
  old_route.merge!(hash)
45
73
  end
46
74
  end
47
75
 
48
76
  def construct_routes
77
+ yop = {}
49
78
  extract = Extractor.new(controller, @action)
50
79
  @verb = extract.verb
51
80
  @route = extract.path
52
- @verb.eql?('put') ? route_update : route
81
+ @route.each do |rte|
82
+ yop.merge!(@verb.eql?('put') ? route_update(rte) : route(rte))
83
+ end
84
+ yop
53
85
  end
54
86
 
55
87
  def construct_path
56
88
  element = {}
57
- summary_text = @summary.present? ? @summary : @action.to_s.humanize
58
- element.merge!(summary: summary_text)
89
+ summary_text = @summary.present? ? @summary : @action.to_s
90
+ element.merge!(summary: summary_text.humanize)
59
91
  element.merge!(description: @description) if @description.present?
60
92
  element.merge!(parameters: @parameter) if @parameter.present?
61
93
  element.merge!(consumes: @consume) if @consume.present?
@@ -65,16 +97,20 @@ module SwaggerDocsGenerator
65
97
  element.merge!(tags: write_tag)
66
98
  end
67
99
 
68
- def route
69
- { @route => { @verb => construct_path } }
100
+ def route(rte)
101
+ { rte => { @verb => construct_path } }
70
102
  end
71
103
 
72
- def route_update
73
- { @route => { @verb => construct_path }.merge!(patch: construct_path) }
104
+ def route_update(rte)
105
+ { rte => { @verb => construct_path }.merge!('patch' => construct_path) }
74
106
  end
75
107
 
76
108
  def write_tag
77
- [@tag_name]
109
+ [@tag_name.humanize]
110
+ end
111
+
112
+ def extract_tag(route)
113
+ route.split('/').reject(&:empty?).first.humanize
78
114
  end
79
115
 
80
116
  def summary(text)
@@ -110,3 +146,5 @@ module SwaggerDocsGenerator
110
146
  end
111
147
  # rubocop:enable Metrics/AbcSize
112
148
  # rubocop:enable Metrics/CyclomaticComplexity
149
+ # rubocop:enable Style/MultilineIfModifier
150
+ # rubocop:enable Metrics/ClassLength
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagger_docs_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6.pre.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - VAILLANT Jeremy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-28 00:00:00.000000000 Z
11
+ date: 2017-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.42.0
75
+ version: 0.48.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.42.0
82
+ version: 0.48.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: yard
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -325,9 +325,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
325
325
  version: '0'
326
326
  required_rubygems_version: !ruby/object:Gem::Requirement
327
327
  requirements:
328
- - - ">="
328
+ - - ">"
329
329
  - !ruby/object:Gem::Version
330
- version: '0'
330
+ version: 1.3.1
331
331
  requirements: []
332
332
  rubyforge_project:
333
333
  rubygems_version: 2.4.5