swagger_yard 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/swagger_yard.rb +31 -0
- data/lib/swagger_yard/model.rb +23 -9
- data/lib/swagger_yard/operation.rb +8 -3
- data/lib/swagger_yard/parameter.rb +3 -0
- data/lib/swagger_yard/property.rb +3 -0
- data/lib/swagger_yard/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75d0e74a6ac517d09a0743edffa6ea2aa7ddf963
|
4
|
+
data.tar.gz: cbda242b96ac6e12646362d573f93b6becc050d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52ed18981ab935c658185407e57a65b70c8ecd711c844d1dcfd84dee2c21064dc98717d498f8101d169ed6bd9cf4fb9a80e4f6f442491d76919523d84f5cea90
|
7
|
+
data.tar.gz: ab50c39b04875a413514fda5a8ece2d021421768f97a42009f52fdc0f30f940bd910272f598efae73690cfa4054db4e3386d43622f02968c66dbc9ab8b6396ae
|
data/lib/swagger_yard.rb
CHANGED
@@ -41,6 +41,37 @@ module SwaggerYard
|
|
41
41
|
YARD::Logger.instance
|
42
42
|
end
|
43
43
|
|
44
|
+
# Validates that the tag has non-nil values for the given attribute methods.
|
45
|
+
# Logs a warning message and returns nil if the tag is not valid.
|
46
|
+
def requires_attrs(tag, *attrs)
|
47
|
+
valid = true
|
48
|
+
attrs.each do |a|
|
49
|
+
valid &&= tag.send(a)
|
50
|
+
break unless valid
|
51
|
+
end
|
52
|
+
unless valid
|
53
|
+
if tag.object
|
54
|
+
object = " in #{tag.object.to_s}"
|
55
|
+
location = " near #{tag.object.files.first.join(':')}" if tag.object.files.first
|
56
|
+
end
|
57
|
+
log.warn "invalid @#{tag.tag_name} tag#{object}#{location}"
|
58
|
+
return nil
|
59
|
+
end
|
60
|
+
tag
|
61
|
+
end
|
62
|
+
|
63
|
+
def requires_name(tag)
|
64
|
+
requires_attrs(tag, :name)
|
65
|
+
end
|
66
|
+
|
67
|
+
def requires_name_and_type(tag)
|
68
|
+
requires_attrs(tag, :name, :types)
|
69
|
+
end
|
70
|
+
|
71
|
+
def requires_type(tag)
|
72
|
+
requires_attrs(tag, :types)
|
73
|
+
end
|
74
|
+
|
44
75
|
#
|
45
76
|
# Use YARD to parse object tags from a file
|
46
77
|
#
|
data/lib/swagger_yard/model.rb
CHANGED
@@ -38,11 +38,14 @@ module SwaggerYard
|
|
38
38
|
@has_model_tag = true
|
39
39
|
@id = Model.mangle(tag.text) unless tag.text.empty?
|
40
40
|
when "property"
|
41
|
-
|
41
|
+
prop = Property.from_tag(tag)
|
42
|
+
@properties << prop if prop
|
42
43
|
when "discriminator"
|
43
44
|
prop = Property.from_tag(tag)
|
44
|
-
|
45
|
-
|
45
|
+
if prop
|
46
|
+
@properties << prop
|
47
|
+
@discriminator ||= prop.name
|
48
|
+
end
|
46
49
|
when "inherits"
|
47
50
|
@inherits << tag.text
|
48
51
|
end
|
@@ -56,16 +59,27 @@ module SwaggerYard
|
|
56
59
|
end
|
57
60
|
|
58
61
|
def to_h
|
59
|
-
h = {
|
60
|
-
|
61
|
-
|
62
|
-
|
62
|
+
h = {}
|
63
|
+
|
64
|
+
if !@properties.empty? || @inherits.empty?
|
65
|
+
h["type"] = "object"
|
66
|
+
h["properties"] = Hash[@properties.map {|p| [p.name, p.to_h]}]
|
67
|
+
h["required"] = @properties.select(&:required?).map(&:name) if @properties.detect(&:required?)
|
68
|
+
end
|
63
69
|
|
64
|
-
h["required"] = @properties.select(&:required?).map(&:name) if @properties.detect(&:required?)
|
65
70
|
h["discriminator"] = @discriminator if @discriminator
|
66
71
|
|
67
72
|
# Polymorphism
|
68
|
-
|
73
|
+
unless @inherits.empty?
|
74
|
+
all_of = inherits_references
|
75
|
+
all_of << h unless h.empty?
|
76
|
+
|
77
|
+
if all_of.length == 1 && @description.empty?
|
78
|
+
h.update(all_of.first)
|
79
|
+
else
|
80
|
+
h = { "allOf" => all_of }
|
81
|
+
end
|
82
|
+
end
|
69
83
|
|
70
84
|
# Description
|
71
85
|
h["description"] = @description unless @description.empty?
|
@@ -13,11 +13,13 @@ module SwaggerYard
|
|
13
13
|
yard_object.tags.each do |tag|
|
14
14
|
case tag.tag_name
|
15
15
|
when "path"
|
16
|
-
|
16
|
+
tag = SwaggerYard.requires_type(tag)
|
17
|
+
operation.add_path_params_and_method(tag) if tag
|
17
18
|
when "parameter"
|
18
19
|
operation.add_parameter(tag)
|
19
20
|
when "response_type"
|
20
|
-
|
21
|
+
tag = SwaggerYard.requires_type(tag)
|
22
|
+
operation.add_response_type(Type.from_type_list(tag.types), tag.text) if tag
|
21
23
|
when "error_message"
|
22
24
|
operation.add_error_message(tag)
|
23
25
|
when "summary"
|
@@ -110,7 +112,8 @@ module SwaggerYard
|
|
110
112
|
# Example: [Array] status(required, body) Filter by status. (e.g. status[]=1&status[]=2&status[]=3)
|
111
113
|
# Example: [Integer] media[media_type_id] ID of the desired media type.
|
112
114
|
def add_parameter(tag)
|
113
|
-
|
115
|
+
param = Parameter.from_yard_tag(tag, self)
|
116
|
+
add_or_update_parameter param if param
|
114
117
|
end
|
115
118
|
|
116
119
|
def add_or_update_parameter(parameter)
|
@@ -137,6 +140,8 @@ module SwaggerYard
|
|
137
140
|
end
|
138
141
|
|
139
142
|
def add_error_message(tag)
|
143
|
+
tag = SwaggerYard.requires_name(tag)
|
144
|
+
return unless tag
|
140
145
|
@error_messages << {
|
141
146
|
"code" => Integer(tag.name),
|
142
147
|
"message" => tag.text,
|
@@ -3,6 +3,9 @@ module SwaggerYard
|
|
3
3
|
attr_accessor :name, :type, :description, :param_type, :required, :allow_multiple
|
4
4
|
|
5
5
|
def self.from_yard_tag(tag, operation)
|
6
|
+
tag = SwaggerYard.requires_name_and_type(tag)
|
7
|
+
return nil unless tag
|
8
|
+
|
6
9
|
name, options_string = tag.name.split(/[\(\)]/)
|
7
10
|
description = tag.text
|
8
11
|
description = name if description.nil? || description.strip.empty?
|
@@ -6,6 +6,9 @@ module SwaggerYard
|
|
6
6
|
attr_reader :name, :description
|
7
7
|
|
8
8
|
def self.from_tag(tag)
|
9
|
+
tag = SwaggerYard.requires_name_and_type(tag)
|
10
|
+
return nil unless tag
|
11
|
+
|
9
12
|
name, options_string = tag.name.split(/[\(\)]/)
|
10
13
|
|
11
14
|
options = options_string.to_s.split(',').map(&:strip)
|
data/lib/swagger_yard/version.rb
CHANGED
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: 0.4.
|
4
|
+
version: 0.4.4
|
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-
|
11
|
+
date: 2018-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|