swagger_yard 0.4.0 → 0.4.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 +4 -4
- data/README.md +13 -3
- data/lib/swagger_yard/model.rb +11 -9
- 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: 4162d53c786e05765654e3aad9162e8d765c481d
|
4
|
+
data.tar.gz: d7d01a44db14c45dc3e372c156a86a4440e5d313
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 077fadda0f1b63175e75bbe296b3701e36d491a36f1a8becc33dee816052ef919f6b296cb44474d59e3347b15d9d8ec427b18a76958f9ffaa2702ff5e084462e
|
7
|
+
data.tar.gz: eda7883fc961b1d47f73e600803ea0a3fa1b1c77541b9a67c7219b36d9232904bd886dfa6b01dfbe859d988a726faa3c5e31f7808265ab4890375f9bd614b78e
|
data/README.md
CHANGED
@@ -139,7 +139,7 @@ end
|
|
139
139
|
|
140
140
|
```ruby
|
141
141
|
#
|
142
|
-
# @model
|
142
|
+
# @model
|
143
143
|
#
|
144
144
|
# @property id(required) [integer] the identifier for the pet
|
145
145
|
# @property name [Array<string>] the names for the pet
|
@@ -160,7 +160,7 @@ To support Swagger Polymorphism, use `@discriminator` and `@inherits`:
|
|
160
160
|
|
161
161
|
```ruby
|
162
162
|
#
|
163
|
-
# @model
|
163
|
+
# @model
|
164
164
|
#
|
165
165
|
# @property id(required) [integer] the identifier for the pet
|
166
166
|
# @property name [Array<string>] the names for the pet
|
@@ -172,7 +172,7 @@ class Pet
|
|
172
172
|
end
|
173
173
|
|
174
174
|
#
|
175
|
-
# @model
|
175
|
+
# @model
|
176
176
|
#
|
177
177
|
# @inherits Pet
|
178
178
|
#
|
@@ -182,6 +182,16 @@ class Dog < Pet
|
|
182
182
|
end
|
183
183
|
```
|
184
184
|
|
185
|
+
If you wish to name your model differently from the underlying ruby class, add the name as text to the `@model` tag. In the example here, if we did not specify `Dog` as the model name, it would have been named `Models_Dog`.
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
# @model Dog
|
189
|
+
module Models
|
190
|
+
class Dog
|
191
|
+
end
|
192
|
+
end
|
193
|
+
```
|
194
|
+
|
185
195
|
## Authorization ##
|
186
196
|
### API Key auth ###
|
187
197
|
|
data/lib/swagger_yard/model.rb
CHANGED
@@ -4,10 +4,11 @@ module SwaggerYard
|
|
4
4
|
# complex model object as defined by swagger schema
|
5
5
|
#
|
6
6
|
class Model
|
7
|
-
attr_reader :id, :discriminator, :inherits
|
7
|
+
attr_reader :id, :discriminator, :inherits, :description
|
8
8
|
|
9
9
|
def self.from_yard_object(yard_object)
|
10
10
|
new.tap do |model|
|
11
|
+
model.add_info(yard_object)
|
11
12
|
model.parse_tags(yard_object.tags)
|
12
13
|
end
|
13
14
|
end
|
@@ -25,11 +26,16 @@ module SwaggerYard
|
|
25
26
|
!id.nil?
|
26
27
|
end
|
27
28
|
|
29
|
+
def add_info(yard_object)
|
30
|
+
@description = yard_object.docstring
|
31
|
+
@id = Model.mangle(yard_object.path)
|
32
|
+
end
|
33
|
+
|
28
34
|
def parse_tags(tags)
|
29
35
|
tags.each do |tag|
|
30
36
|
case tag.tag_name
|
31
37
|
when "model"
|
32
|
-
@id = Model.mangle(tag.text)
|
38
|
+
@id = Model.mangle(tag.text) unless tag.text.empty?
|
33
39
|
when "property"
|
34
40
|
@properties << Property.from_tag(tag)
|
35
41
|
when "discriminator"
|
@@ -37,7 +43,7 @@ module SwaggerYard
|
|
37
43
|
@properties << prop
|
38
44
|
@discriminator ||= prop.name
|
39
45
|
when "inherits"
|
40
|
-
@inherits <<
|
46
|
+
@inherits << tag.text
|
41
47
|
end
|
42
48
|
end
|
43
49
|
|
@@ -45,11 +51,7 @@ module SwaggerYard
|
|
45
51
|
end
|
46
52
|
|
47
53
|
def inherits_references
|
48
|
-
@inherits.map
|
49
|
-
{
|
50
|
-
"$ref" => "#/definitions/#{name}"
|
51
|
-
}
|
52
|
-
end
|
54
|
+
@inherits.map { |name| Type.new(name).to_h }
|
53
55
|
end
|
54
56
|
|
55
57
|
def to_h
|
@@ -65,7 +67,7 @@ module SwaggerYard
|
|
65
67
|
h = { "allOf" => inherits_references + [h] } unless @inherits.empty?
|
66
68
|
|
67
69
|
# Description
|
68
|
-
h["description"] = @description
|
70
|
+
h["description"] = @description unless @description.empty?
|
69
71
|
|
70
72
|
h
|
71
73
|
end
|
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.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-04-
|
11
|
+
date: 2018-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|