jdoc 0.0.8 → 0.0.9

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: 4fc087dc2403a8ae46e6345a6ac7272eed69dde5
4
- data.tar.gz: 0d6d68f56b63640504024d927d61db162804f93a
3
+ metadata.gz: 44f0091a8a36bc9270c3c13de5553c51051b1261
4
+ data.tar.gz: 69173ed695ea55d08826cefe5c43eff342b81c07
5
5
  SHA512:
6
- metadata.gz: cd7c71ab68fd9cde88de70bc5b6f1055129120a432683366f207ef9cf8508e611934b9651c036032aaec019fb01eeda4cf707e2ecbfd4378122a406666d14686
7
- data.tar.gz: 214d08b958202d211e3824043b4daf9bacc76db34ba049f6585fba364221d6e97f21a62b3cd546b378ef00b836f105596124aaa3d32fb0154c8f7611164f04e8
6
+ metadata.gz: ed1792568d15ba8d43ea696b417ed3d009a241d8ab4c0c194b9d6794d1bf4007712ab766167097c90f6597daa1d0a7b400b571418173bbc7ff526a8be47acc78
7
+ data.tar.gz: 71dc0edef70729432ecdfd651b2552ed057d4760f72b1c4ec84833b2cc7bde3d2d7224f70a56c4c63a5ed453e63e5295424e4b86bd072c2c3717ad77fbfa9af5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.0.9
2
+ * Support array property
3
+
1
4
  ## 0.0.8
2
5
  * Fix resource equality
3
6
 
data/lib/jdoc/link.rb CHANGED
@@ -64,7 +64,7 @@ module Jdoc
64
64
 
65
65
  # @return [String, nil] Example request body in JSON format
66
66
  def request_body
67
- JSON.pretty_generate(RequestGenerator.call(schema)) + "\n"
67
+ JSON.pretty_generate(RequestGenerator.call(schema.properties)) + "\n"
68
68
  end
69
69
 
70
70
  # @return [true, false] True if this endpoint must have request body
@@ -98,7 +98,7 @@ module Jdoc
98
98
  # @return [Hash]
99
99
  # @raise [Rack::Spec::Mock::ExampleNotFound]
100
100
  def response_hash
101
- ResponseGenerator.call(schema)
101
+ ResponseGenerator.call(schema.properties)
102
102
  end
103
103
 
104
104
  # @return [Fixnum] Order score, used to sort links by preferred method order
@@ -121,39 +121,24 @@ module Jdoc
121
121
 
122
122
  class RequestGenerator
123
123
  # Generates example request body from given schema
124
+ # @param properties [Hash]
124
125
  # @note Not includes properties that have readOnly property
125
126
  # @return [Hash]
126
127
  # @example
127
- # Jdoc::Link::RequestGenerator(schema) #=> { "name" => "example", "description" => "foo bar." }
128
- def self.call(schema)
129
- schema.properties.inject({}) do |result, (key, value)|
130
- if value.data["readOnly"]
131
- result
132
- else
133
- result.merge(
134
- key => case
135
- when !value.properties.empty?
136
- call(value)
137
- when !value.data["example"].nil?
138
- value.data["example"]
139
- when value.type.include?("null")
140
- nil
141
- else
142
- raise ExampleNotFound, "No example found for #{schema.pointer}/#{key}"
143
- end
144
- )
145
- end
146
- end
128
+ # Jdoc::Link::RequestGenerator(schema.properties) #=> { "name" => "example", "description" => "foo bar." }
129
+ def self.call(properties)
130
+ ResponseGenerator.call(properties.reject {|key, value| value.data["readOnly"] })
147
131
  end
148
132
  end
149
133
 
150
134
  class ResponseGenerator
151
135
  # Generates example response Hash from given schema
136
+ # @param properties [Hash]
152
137
  # @return [Hash]
153
138
  # @example
154
- # Jdoc::Link::ResponseGenerator(schema) #=> { "id" => 1, "name" => "example" }
155
- def self.call(schema)
156
- schema.properties.inject({}) do |result, (key, value)|
139
+ # Jdoc::Link::ResponseGenerator(schema.properties) #=> { "id" => 1, "name" => "example" }
140
+ def self.call(properties)
141
+ properties.inject({}) do |result, (key, value)|
157
142
  result.merge(
158
143
  key => case
159
144
  when !value.properties.empty?
@@ -162,6 +147,8 @@ module Jdoc
162
147
  value.data["example"]
163
148
  when value.type.include?("null")
164
149
  nil
150
+ when value.type.include?("array")
151
+ call(value.items.properties)
165
152
  else
166
153
  raise ExampleNotFound, "No example found for #{schema.pointer}/#{key}"
167
154
  end
data/lib/jdoc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jdoc
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -82,6 +82,20 @@ definitions:
82
82
  "$ref": "#/definitions/app/definitions/private"
83
83
  deleted_at:
84
84
  "$ref": "#/definitions/app/definitions/deleted_at"
85
+ users:
86
+ type: array
87
+ items:
88
+ "$ref": "#/definitions/user"
89
+ user:
90
+ title: User
91
+ type: object
92
+ definitions:
93
+ name:
94
+ type: string
95
+ example: alice
96
+ properties:
97
+ name:
98
+ "$ref": "#/definitions/user/definitions/name"
85
99
  properties:
86
100
  app:
87
101
  "$ref": "#/definitions/app"
@@ -45,6 +45,8 @@ describe Jdoc::Generator do
45
45
  * deleted_at - When this resource was deleted at
46
46
  * Example: `nil`
47
47
  * Type: null
48
+ * users -
49
+ * Type: array
48
50
 
49
51
  ### GET /apps
50
52
  List existing apps.
@@ -63,7 +65,10 @@ describe Jdoc::Generator do
63
65
  "id": "01234567-89ab-cdef-0123-456789abcdef",
64
66
  "name": "example",
65
67
  "private": false,
66
- "deleted_at": null
68
+ "deleted_at": null,
69
+ "users": {
70
+ "name": "alice"
71
+ }
67
72
  }
68
73
  ```
69
74
 
@@ -78,7 +83,10 @@ describe Jdoc::Generator do
78
83
  {
79
84
  "name": "example",
80
85
  "private": false,
81
- "deleted_at": null
86
+ "deleted_at": null,
87
+ "users": {
88
+ "name": "alice"
89
+ }
82
90
  }
83
91
  ```
84
92
 
@@ -90,7 +98,10 @@ describe Jdoc::Generator do
90
98
  "id": "01234567-89ab-cdef-0123-456789abcdef",
91
99
  "name": "example",
92
100
  "private": false,
93
- "deleted_at": null
101
+ "deleted_at": null,
102
+ "users": {
103
+ "name": "alice"
104
+ }
94
105
  }
95
106
  ```
96
107
 
@@ -111,7 +122,10 @@ describe Jdoc::Generator do
111
122
  "id": "01234567-89ab-cdef-0123-456789abcdef",
112
123
  "name": "example",
113
124
  "private": false,
114
- "deleted_at": null
125
+ "deleted_at": null,
126
+ "users": {
127
+ "name": "alice"
128
+ }
115
129
  }
116
130
  ```
117
131
 
@@ -126,7 +140,10 @@ describe Jdoc::Generator do
126
140
  {
127
141
  "name": "example",
128
142
  "private": false,
129
- "deleted_at": null
143
+ "deleted_at": null,
144
+ "users": {
145
+ "name": "alice"
146
+ }
130
147
  }
131
148
  ```
132
149
 
@@ -138,7 +155,10 @@ describe Jdoc::Generator do
138
155
  "id": "01234567-89ab-cdef-0123-456789abcdef",
139
156
  "name": "example",
140
157
  "private": false,
141
- "deleted_at": null
158
+ "deleted_at": null,
159
+ "users": {
160
+ "name": "alice"
161
+ }
142
162
  }
143
163
  ```
144
164
 
@@ -159,7 +179,10 @@ describe Jdoc::Generator do
159
179
  "id": "01234567-89ab-cdef-0123-456789abcdef",
160
180
  "name": "example",
161
181
  "private": false,
162
- "deleted_at": null
182
+ "deleted_at": null,
183
+ "users": {
184
+ "name": "alice"
185
+ }
163
186
  }
164
187
  ```
165
188
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-15 00:00:00.000000000 Z
11
+ date: 2014-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis