rspec-autoswagger 0.4.1 → 0.5.1

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
- SHA256:
3
- metadata.gz: a745c33c8d2c88516c9a2c6654e13aaba7ac072e123e9b4658fab1fc53685c23
4
- data.tar.gz: a3b9d2743776ae91a5b4899e86844bdd1b6605b5e113c9689f893f0ac8fadaca
2
+ SHA1:
3
+ metadata.gz: 76c568faf41372d1f2c47bed9f0305ebdfecae2b
4
+ data.tar.gz: ab707fe34a2011e9671d0c2479091d5490bf84f8
5
5
  SHA512:
6
- metadata.gz: acbe392f133ec1f130ceace1215a34459cd66d8c7593e833ddbc9ea9c900d825255655d315a8a42535353c261865e9ea5835b7b34cb901b66ef8878db9c40c8a
7
- data.tar.gz: 4bf264f387794f4093f05183a21045fa737ea4ed32233f1f00d9c3dc98c103791a715de2d6bc8b135bf7ba719a2295afcd5b611243a5b184815bd167146aeb67
6
+ metadata.gz: 3c1290645d60f8b15c321228b1b3653a533d6d0904bf18eea60bd221c2b11a14eea3f94979cdaf6bc36dc530f079009199a1456e6f5c9e3a5d3c2b854eb64f97
7
+ data.tar.gz: 8130e944992f5ec08e3621a02e361f4642300dc8dc47d7b181c935095d93b038c516fce21056c9c16c68fa189a0faee3d492a9db25a80b3a2364ca0583220e38
@@ -5,6 +5,8 @@ require "rspec/autoswagger/doc_parts"
5
5
  module Rspec
6
6
  module Autoswagger
7
7
 
8
+ API_BASE_PATH = '/api/v1'
9
+
8
10
  def self.doc_parts
9
11
  @doc_parts ||= DocParts.new
10
12
  end
@@ -1,27 +1,51 @@
1
1
  require 'rspec/autoswagger/parts/path'
2
2
  require 'rspec/autoswagger/parts/info'
3
3
  require 'rspec/autoswagger/parts/definition'
4
+ require 'rspec/autoswagger/util'
4
5
 
5
6
  module Rspec
6
7
  module Autoswagger
7
8
  class DocPart
8
9
 
9
- attr_reader :rspec_core_obj, :example
10
+ attr_reader :rspec_core_obj, :example, :request
10
11
 
11
12
  def initialize(rspec_core_obj, example)
12
13
  @rspec_core_obj = rspec_core_obj
14
+ @request = rspec_core_obj.request
13
15
  @example = example
14
16
  end
15
17
 
16
18
  def response_name
17
19
  status = rspec_core_obj.response.status.to_s
18
20
  if status == '200'
19
- example.full_description[%r<(GET|POST|PATCH|PUT|DELETE) ([^ ]+)>, 2].gsub(/\/|:/, '').camelize
21
+ path = example.full_description[%r<(GET|POST|PATCH|PUT|DELETE) ([^ ]+)>, 2]
22
+ path = if path.blank?
23
+ path = request.path.gsub(Rspec::Autoswagger::API_BASE_PATH, '')
24
+ get_converted_path(path)
25
+ end
26
+ path.gsub(/\/|:/, '').camelize
20
27
  else
21
- example.full_description[%r<(GET|POST|PATCH|PUT|DELETE) ([^ ]+)>, 2].gsub(/\/|:/, '').camelize + '_' + status
28
+ path = example.full_description[%r<(GET|POST|PATCH|PUT|DELETE) ([^ ]+)>, 2]
29
+ path = if path.blank?
30
+ path = request.path.gsub(Rspec::Autoswagger::API_BASE_PATH, '')
31
+ get_converted_path(path)
32
+ end
33
+ path.gsub(/\/|:/, '').camelize + '_' + status
22
34
  end
23
35
  end
24
36
 
37
+ def get_converted_path(path)
38
+ path.split("/").map do |path_element|
39
+ if Util.detect_uuid(path_element)
40
+ ":id"
41
+ elsif Util.detect_uuid(path_element)
42
+ ":id"
43
+ else
44
+ path_element
45
+ end
46
+ end.join("/")
47
+ end
48
+
25
49
  def create_path
26
50
  path = Parts::Path.new(rspec_core_obj, example, response_name)
27
51
  path.generate_hash
@@ -1,3 +1,5 @@
1
+ require 'rspec/autoswagger/util'
2
+
1
3
  module Rspec
2
4
  module Autoswagger
3
5
  module Parts
@@ -10,7 +12,6 @@ module Rspec
10
12
  begin
11
13
  @description = rspec_core_obj.description
12
14
  rescue RSpec::Core::ExampleGroup::WrongScopeError
13
- puts "[AUTOSWAGGER WARNING] please write description"
14
15
  @description = ''
15
16
  end
16
17
  @example = example
@@ -19,7 +20,24 @@ module Rspec
19
20
 
20
21
  def path
21
22
  path = example.full_description[%r<(GET|POST|PATCH|PUT|DELETE) ([^ ]+)>, 2]
22
- path.split("/").map { |name| name.include?(":") ? "{" + name.gsub(":", "") + "}" : name }.join("/")
23
+ if path.blank?
24
+ path = request.path.gsub(Rspec::Autoswagger::API_BASE_PATH, '')
25
+ get_converted_path(path)
26
+ else
27
+ path.split("/").map { |name| name.include?(":") ? "{" + name.gsub(":", "") + "}" : name }.join("/")
28
+ end
29
+ end
30
+
31
+ def get_converted_path(path)
32
+ path.split("/").map do |path_element|
33
+ if Util.detect_uuid(path_element)
34
+ "{id}"
35
+ elsif Util.detect_uuid(path_element)
36
+ "{id}"
37
+ else
38
+ path_element
39
+ end
40
+ end.join("/")
23
41
  end
24
42
 
25
43
  def tags
@@ -0,0 +1,9 @@
1
+ class Util
2
+ def self.detect_uuid(sentense)
3
+ sentense.match(/^([a-zA-Z0-9]+-[a-zA-Z0-9]+-[a-zA-Z0-9]++-[a-zA-Z0-9]+-[a-zA-Z0-9]+)$/)
4
+ end
5
+
6
+ def self.detect_integer_id(sentense)
7
+ sentense.match(/^(\d+)$/)
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  module Rspec
2
2
  module Autoswagger
3
- VERSION = "0.4.1"
3
+ VERSION = "0.5.1"
4
4
  end
5
5
  end
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
30
 
31
- spec.add_dependency "swagger_model", '0.4.6'
31
+ spec.add_dependency "swagger_model", '0.4.8'
32
32
  spec.add_dependency "rspec"
33
33
  spec.add_dependency "activesupport"
34
34
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-autoswagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - joooee0000
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-04 00:00:00.000000000 Z
11
+ date: 2018-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: swagger_model
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.4.6
19
+ version: 0.4.8
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.4.6
26
+ version: 0.4.8
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -104,6 +104,7 @@ files:
104
104
  - lib/rspec/autoswagger/parts/info.rb
105
105
  - lib/rspec/autoswagger/parts/path.rb
106
106
  - lib/rspec/autoswagger/rspec.rb
107
+ - lib/rspec/autoswagger/util.rb
107
108
  - lib/rspec/autoswagger/version.rb
108
109
  - rspec-autoswagger.gemspec
109
110
  homepage: https://github.com/joooee0000/rspec-autoswagger
@@ -126,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
127
  version: '0'
127
128
  requirements: []
128
129
  rubyforge_project:
129
- rubygems_version: 2.7.7
130
+ rubygems_version: 2.5.1
130
131
  signing_key:
131
132
  specification_version: 4
132
133
  summary: Rspec extension to auto generate swagger/openapi specification