swagger_yard 1.0.0 → 1.0.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
2
  SHA1:
3
- metadata.gz: 9e95fe3850f449db0d3234e6b314bf76c3570f7d
4
- data.tar.gz: 9f2e1c1a9d2a3731431e6d606a4023d7ae692326
3
+ metadata.gz: e69ba8fc51e7c39ca9291c1e2917f28b5ed794fe
4
+ data.tar.gz: f00801cc7268c6faf6d1fdc22c8d9b14ccf55756
5
5
  SHA512:
6
- metadata.gz: 3609ee174c38e70038f0358b735c9c1ffdf73ca76c634d9e2f93f1d42f497d6f752b3cf0b1c9f18d58ce68ff426d8f254b09fb76da748dc8f2a5e87d3ea85b38
7
- data.tar.gz: de11893ad4b1293ad2955617ebd967c2030d7347beb15ea6ac486de6769f0a12fa2e334822dae4c2790b2c83b95abe8f251f12cce897209bab2106d9d1217bd5
6
+ metadata.gz: baa76a8eccd08176c057fb6d6969001899350d7f0ce8b5cf25ab00cd29d42bf81e554440e5517a1dd517c1bb4952f8deb6143127442e208f91c181825fec6faa
7
+ data.tar.gz: 7ddf6347f3a340ab921f0f576146fcd3709f8adbcbe049319ab63137fc156779998369f68b1612b97138434fccf9ae8198dde34b19e6463bc713df9d6038d375
@@ -28,5 +28,9 @@ module SwaggerYard
28
28
  end if mappings
29
29
  @external_schema
30
30
  end
31
+
32
+ def register_dsl_method(meth, options = {})
33
+ SwaggerYard::Handlers::DSLHandler.register_dsl_method(meth, options)
34
+ end
31
35
  end
32
36
  end
@@ -0,0 +1,35 @@
1
+ module SwaggerYard::Handlers
2
+ class DSLHandler < YARD::Handlers::Ruby::Base
3
+ include YARD::CodeObjects
4
+ namespace_only
5
+
6
+ def self.method_options
7
+ @method_options ||= {}
8
+ end
9
+
10
+ def self.reset
11
+ method_options.keys.each do |m|
12
+ handler = handlers.detect { |h| h.respond_to?(:name) && h.send(:name).to_s == m.to_s }
13
+ handlers.delete handler if handler
14
+ end
15
+ method_options.clear
16
+ end
17
+
18
+ def self.register_dsl_method(name, options = {})
19
+ return if self.method_options[name.to_s]
20
+ options[:args] ||= 0..-1
21
+ self.method_options[name.to_s] = options
22
+ handles method_call(name)
23
+ end
24
+
25
+ def process
26
+ options = self.class.method_options[caller_method]
27
+ return unless options
28
+ call_params[options[:args]].each do |method_name|
29
+ object = MethodObject.new(namespace, method_name, scope)
30
+ object.signature = "def #{method_name}"
31
+ register(object)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -11,6 +11,11 @@ module SwaggerYard
11
11
  new.tap do |model|
12
12
  model.add_info(yard_object)
13
13
  model.parse_tags(yard_object.tags)
14
+ yard_object.children.each do |child|
15
+ next unless child.is_a?(YARD::CodeObjects::MethodObject)
16
+ prop = Property.from_method(child)
17
+ model.properties << prop if prop
18
+ end
14
19
  end
15
20
  end
16
21
 
@@ -4,17 +4,56 @@ module SwaggerYard
4
4
  #
5
5
  class Property
6
6
  include Example
7
- attr_reader :name, :description, :required, :type, :nullable
7
+ attr_reader :name, :required, :type, :nullable
8
+ attr_accessor :description
9
+
10
+ NAME_OPTIONS_REGEXP = /[\(\)]/
11
+
12
+ def self.tag_name(tag)
13
+ if tag.object.is_a?(YARD::CodeObjects::MethodObject)
14
+ tag.object.name.to_s
15
+ else
16
+ tag = SwaggerYard.requires_name(tag)
17
+ return nil unless tag
18
+ tag.name.split(NAME_OPTIONS_REGEXP).first
19
+ end
20
+ end
21
+
22
+ def self.from_method(yard_method)
23
+ return nil unless yard_method.explicit || yard_method.parameters.empty?
24
+ tags = (yard_method.tags ||[]).dup
25
+ prop_tag = tags.detect { |t| t.tag_name == 'property' }
26
+ return nil unless prop_tag
27
+ tags.reject { |t| t.tag_name == 'property' }
28
+ from_tag(prop_tag).tap do |prop|
29
+ ex = tags.detect { |t| t.tag_name == 'example' }
30
+ prop.example = ex.text.empty? ? ex.name : ex.text if ex
31
+ prop.description = yard_method.docstring unless prop.description
32
+ end
33
+ end
8
34
 
9
35
  def self.from_tag(tag)
10
- tag = SwaggerYard.requires_name_and_type(tag)
36
+ tag = SwaggerYard.requires_type(tag)
11
37
  return nil unless tag
12
38
 
13
- name, options_string = tag.name.split(/[\(\)]/)
39
+ name = tag_name(tag)
40
+ return nil unless name
41
+
42
+ text = tag.text
43
+
44
+ if (options_src = (tag.name || '')) =~ NAME_OPTIONS_REGEXP
45
+ _, options_string = options_src.split(NAME_OPTIONS_REGEXP)
46
+ elsif tag.name && tag.object.is_a?(YARD::CodeObjects::MethodObject)
47
+ if text
48
+ text = tag.name + ' ' + text
49
+ else
50
+ text = tag.name
51
+ end
52
+ end
14
53
 
15
54
  options = options_string.to_s.split(',').map(&:strip)
16
55
 
17
- new(name, tag.types, tag.text, options)
56
+ new(name, tag.types, text, options)
18
57
  end
19
58
 
20
59
  def initialize(name, types, description, options)
@@ -1,3 +1,3 @@
1
1
  module SwaggerYard
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/swagger_yard.rb CHANGED
@@ -14,6 +14,7 @@ require "swagger_yard/model"
14
14
  require "swagger_yard/path_item"
15
15
  require "swagger_yard/swagger"
16
16
  require "swagger_yard/openapi"
17
+ require "swagger_yard/handlers"
17
18
 
18
19
  module SwaggerYard
19
20
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagger_yard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - chtrinh (Chris Trinh)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-28 00:00:00.000000000 Z
11
+ date: 2018-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -194,6 +194,7 @@ files:
194
194
  - lib/swagger_yard/authorization.rb
195
195
  - lib/swagger_yard/configuration.rb
196
196
  - lib/swagger_yard/example.rb
197
+ - lib/swagger_yard/handlers.rb
197
198
  - lib/swagger_yard/model.rb
198
199
  - lib/swagger_yard/openapi.rb
199
200
  - lib/swagger_yard/operation.rb