swagger_yard 0.4.0 → 0.4.1

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: ef1f9c99cbcdd6a637a1d68079ba1e2a0b1cb718
4
- data.tar.gz: 17849b615de17e9ec974f9905202a8097daf0eba
3
+ metadata.gz: 4162d53c786e05765654e3aad9162e8d765c481d
4
+ data.tar.gz: d7d01a44db14c45dc3e372c156a86a4440e5d313
5
5
  SHA512:
6
- metadata.gz: e200703aa74c246766ec9dbeb448ab6fd7f8b036376f82bd8ae60d0c7b6abe4d1d1149ec662c45d4ab1d34af0f38ece20e909a501bcdae78ee9b038687aa1f68
7
- data.tar.gz: 4877499f45c859a0d75ba2518d425a867f2dc072955c38ea49b5cbcaa13f8bd2322989a15f10cb39de1f8a6191057dfdb25333cdb6eef96bdf9aa339d54032e3
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 Pet
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 Pet
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 Dog
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
 
@@ -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 << Model.mangle(tag.text)
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 do |name|
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 if @description
70
+ h["description"] = @description unless @description.empty?
69
71
 
70
72
  h
71
73
  end
@@ -1,3 +1,3 @@
1
1
  module SwaggerYard
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  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: 0.4.0
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-05 00:00:00.000000000 Z
11
+ date: 2018-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard