restspec 0.2 → 0.2.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: aee8d567251582d1e11bf1360b2539e2d8f9621c
4
- data.tar.gz: 8746f5961969356e821728543118f4baa694b4aa
3
+ metadata.gz: d901b5b31ccd31cb10ed6aa3d3eb64dfc9817595
4
+ data.tar.gz: 62319f6fd801767b52842413f5200bd40baaeac7
5
5
  SHA512:
6
- metadata.gz: 275c8062f82f7b72fa200ecae179b5ef668fc6bd09b0eaa4b57a2d4322e43ce8a2aae6a0eb8a323d84ba6864dc8593eae7772c6f3ac175925f92fb8ab7c97ae1
7
- data.tar.gz: 8667413094c1599d61dbf84dd129a0a6b2cbd1abf9e0aeb7429f3052fbcbb2a7d6014b96f7effc7bbf479d7d04e780bb3a7579c1437a4918891b6e440405fe52
6
+ metadata.gz: df3d6838f88efe8fc53514d040aee2c93bb578a79265bc670b3ead0c82c124885a02b795c1be6c5e482bbb596b7fa8bc43d9b346d09dbecbd04bf343a3c68936
7
+ data.tar.gz: f9325534e3990ac883d5024d8f331448ae69cc31ccc520bf53be978e45d7d77388cc719fb005206178f82e164dc8643371eef20eb10ba52d2e6aad48f0495cc1
data/CHANGELOG.md CHANGED
@@ -1,6 +1,5 @@
1
1
  0.1
2
2
  ---
3
-
4
3
  - Added `:for` option to `schema` methods on the endpoint definition. This allows to specify schemas for payloads, schemas for responses and schemas for whatever. See: https://github.com/platanus/restspec/issues/2.
5
4
  - Added `no_schema` method to endpoint definitions. This is a subtask of https://github.com/platanus/restspec/issues/2..
6
5
 
data/bin/restspec CHANGED
@@ -10,8 +10,8 @@ require 'restspec/runners/install/install_runner'
10
10
  require 'restspec/runners/docs/docs_runner'
11
11
 
12
12
  class RestspecCLI < Thor
13
- register(Restspec::InstallRunner, 'install', 'install [your_test_folder]', 'Type restspec install for more help.')
14
- register(Restspec::DocsRunner, 'docs', 'docs [your_docs_location]', 'Type restspec docs for more help.')
13
+ register(Restspec::Install::InstallRunner, 'install', 'install [your_test_folder]', 'Type restspec install for more help.')
14
+ register(Restspec::Docs::DocsRunner, 'docs', 'docs [your_docs_location]', 'Type restspec docs for more help.')
15
15
  end
16
16
 
17
17
  RestspecCLI.start(ARGV)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ~/dev/projects/ruby/restspec
3
3
  specs:
4
- restspec (0.1)
4
+ restspec (0.2)
5
5
  activesupport (~> 4.0)
6
6
  faker (~> 1.4)
7
7
  hashie (~> 3.3)
@@ -12,7 +12,7 @@ PATH
12
12
  rspec-its (~> 1.0)
13
13
  ruby_deep_clone (~> 0.6)
14
14
  thor (~> 0.19)
15
- tilt (~> 2.0)
15
+ tilt (~> 1.1)
16
16
 
17
17
  GEM
18
18
  remote: https://rubygems.org/
@@ -62,7 +62,7 @@ GEM
62
62
  slop (3.6.0)
63
63
  thor (0.19.1)
64
64
  thread_safe (0.3.4)
65
- tilt (2.0.1)
65
+ tilt (1.4.1)
66
66
  tzinfo (1.2.2)
67
67
  thread_safe (~> 0.1)
68
68
 
@@ -0,0 +1,357 @@
1
+ <!DOCTYPE html><html><head><title>API</title><link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.min.css" rel="stylesheet" /><style type="text/css">body {
2
+ font-family: Helvetica, arial, sans-serif;
3
+ font-size: 14px;
4
+ line-height: 1.6;
5
+ padding-top: 10px;
6
+ padding-bottom: 10px;
7
+ background-color: white;
8
+ padding: 30px; }
9
+
10
+ body > *:first-child {
11
+ margin-top: 0 !important; }
12
+ body > *:last-child {
13
+ margin-bottom: 0 !important; }
14
+
15
+ a {
16
+ color: #4183C4; }
17
+ a.absent {
18
+ color: #cc0000; }
19
+ a.anchor {
20
+ display: block;
21
+ padding-left: 30px;
22
+ margin-left: -30px;
23
+ cursor: pointer;
24
+ position: absolute;
25
+ top: 0;
26
+ left: 0;
27
+ bottom: 0; }
28
+
29
+ h1, h2, h3, h4, h5, h6 {
30
+ margin: 20px 0 10px;
31
+ padding: 0;
32
+ font-weight: bold;
33
+ -webkit-font-smoothing: antialiased;
34
+ cursor: text;
35
+ position: relative; }
36
+
37
+ h1:hover a.anchor, h2:hover a.anchor, h3:hover a.anchor, h4:hover a.anchor, h5:hover a.anchor, h6:hover a.anchor {
38
+ background: url("../../images/modules/styleguide/para.png") no-repeat 10px center;
39
+ text-decoration: none; }
40
+
41
+ h1 tt, h1 code {
42
+ font-size: inherit; }
43
+
44
+ h2 tt, h2 code {
45
+ font-size: inherit; }
46
+
47
+ h3 tt, h3 code {
48
+ font-size: inherit; }
49
+
50
+ h4 tt, h4 code {
51
+ font-size: inherit; }
52
+
53
+ h5 tt, h5 code {
54
+ font-size: inherit; }
55
+
56
+ h6 tt, h6 code {
57
+ font-size: inherit; }
58
+
59
+ h1 {
60
+ font-size: 28px;
61
+ color: black; }
62
+
63
+ h2 {
64
+ font-size: 24px;
65
+ border-bottom: 1px solid #cccccc;
66
+ color: black; }
67
+
68
+ h3 {
69
+ font-size: 18px; }
70
+
71
+ h4 {
72
+ font-size: 16px; }
73
+
74
+ h5 {
75
+ font-size: 14px; }
76
+
77
+ h6 {
78
+ color: #777777;
79
+ font-size: 14px; }
80
+
81
+ p, blockquote, ul, ol, dl, li, table, pre {
82
+ margin: 15px 0; }
83
+
84
+ hr {
85
+ background: transparent url("../../images/modules/pulls/dirty-shade.png") repeat-x 0 0;
86
+ border: 0 none;
87
+ color: #cccccc;
88
+ height: 4px;
89
+ padding: 0; }
90
+
91
+ body > h2:first-child {
92
+ margin-top: 0;
93
+ padding-top: 0; }
94
+ body > h1:first-child {
95
+ margin-top: 0;
96
+ padding-top: 0; }
97
+ body > h1:first-child + h2 {
98
+ margin-top: 0;
99
+ padding-top: 0; }
100
+ body > h3:first-child, body > h4:first-child, body > h5:first-child, body > h6:first-child {
101
+ margin-top: 0;
102
+ padding-top: 0; }
103
+
104
+ a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
105
+ margin-top: 0;
106
+ padding-top: 0; }
107
+
108
+ h1 p, h2 p, h3 p, h4 p, h5 p, h6 p {
109
+ margin-top: 0; }
110
+
111
+ li p.first {
112
+ display: inline-block; }
113
+
114
+ ul, ol {
115
+ padding-left: 30px; }
116
+
117
+ ul :first-child, ol :first-child {
118
+ margin-top: 0; }
119
+
120
+ ul :last-child, ol :last-child {
121
+ margin-bottom: 0; }
122
+
123
+ dl {
124
+ padding: 0; }
125
+ dl dt {
126
+ font-size: 14px;
127
+ font-weight: bold;
128
+ font-style: italic;
129
+ padding: 0;
130
+ margin: 15px 0 5px; }
131
+ dl dt:first-child {
132
+ padding: 0; }
133
+ dl dt > :first-child {
134
+ margin-top: 0; }
135
+ dl dt > :last-child {
136
+ margin-bottom: 0; }
137
+ dl dd {
138
+ margin: 0 0 15px;
139
+ padding: 0 15px; }
140
+ dl dd > :first-child {
141
+ margin-top: 0; }
142
+ dl dd > :last-child {
143
+ margin-bottom: 0; }
144
+
145
+ blockquote {
146
+ border-left: 4px solid #dddddd;
147
+ padding: 0 15px;
148
+ color: #777777; }
149
+ blockquote > :first-child {
150
+ margin-top: 0; }
151
+ blockquote > :last-child {
152
+ margin-bottom: 0; }
153
+
154
+ table {
155
+ padding: 0; }
156
+ table tr {
157
+ border-top: 1px solid #cccccc;
158
+ background-color: white;
159
+ margin: 0;
160
+ padding: 0; }
161
+ table tr:nth-child(2n) {
162
+ background-color: #f8f8f8; }
163
+ table tr th {
164
+ font-weight: bold;
165
+ border: 1px solid #cccccc;
166
+ text-align: left;
167
+ margin: 0;
168
+ padding: 6px 13px; }
169
+ table tr td {
170
+ border: 1px solid #cccccc;
171
+ text-align: left;
172
+ margin: 0;
173
+ padding: 6px 13px; }
174
+ table tr th :first-child, table tr td :first-child {
175
+ margin-top: 0; }
176
+ table tr th :last-child, table tr td :last-child {
177
+ margin-bottom: 0; }
178
+
179
+ img {
180
+ max-width: 100%; }
181
+
182
+ span.frame {
183
+ display: block;
184
+ overflow: hidden; }
185
+ span.frame > span {
186
+ border: 1px solid #dddddd;
187
+ display: block;
188
+ float: left;
189
+ overflow: hidden;
190
+ margin: 13px 0 0;
191
+ padding: 7px;
192
+ width: auto; }
193
+ span.frame span img {
194
+ display: block;
195
+ float: left; }
196
+ span.frame span span {
197
+ clear: both;
198
+ color: #333333;
199
+ display: block;
200
+ padding: 5px 0 0; }
201
+ span.align-center {
202
+ display: block;
203
+ overflow: hidden;
204
+ clear: both; }
205
+ span.align-center > span {
206
+ display: block;
207
+ overflow: hidden;
208
+ margin: 13px auto 0;
209
+ text-align: center; }
210
+ span.align-center span img {
211
+ margin: 0 auto;
212
+ text-align: center; }
213
+ span.align-right {
214
+ display: block;
215
+ overflow: hidden;
216
+ clear: both; }
217
+ span.align-right > span {
218
+ display: block;
219
+ overflow: hidden;
220
+ margin: 13px 0 0;
221
+ text-align: right; }
222
+ span.align-right span img {
223
+ margin: 0;
224
+ text-align: right; }
225
+ span.float-left {
226
+ display: block;
227
+ margin-right: 13px;
228
+ overflow: hidden;
229
+ float: left; }
230
+ span.float-left span {
231
+ margin: 13px 0 0; }
232
+ span.float-right {
233
+ display: block;
234
+ margin-left: 13px;
235
+ overflow: hidden;
236
+ float: right; }
237
+ span.float-right > span {
238
+ display: block;
239
+ overflow: hidden;
240
+ margin: 13px auto 0;
241
+ text-align: right; }
242
+
243
+ code, tt {
244
+ margin: 0 2px;
245
+ padding: 0 5px;
246
+ white-space: nowrap;
247
+ border: 1px solid #eaeaea;
248
+ background-color: #f8f8f8;
249
+ border-radius: 3px; }
250
+
251
+ pre code {
252
+ margin: 0;
253
+ padding: 0;
254
+ white-space: pre;
255
+ border: none;
256
+ background: transparent; }
257
+
258
+ .highlight pre {
259
+ background-color: #f8f8f8;
260
+ border: 1px solid #cccccc;
261
+ font-size: 13px;
262
+ line-height: 19px;
263
+ overflow: auto;
264
+ padding: 6px 10px;
265
+ border-radius: 3px; }
266
+
267
+ pre {
268
+ background-color: #f8f8f8;
269
+ border: 1px solid #cccccc;
270
+ font-size: 13px;
271
+ line-height: 19px;
272
+ overflow: auto;
273
+ padding: 6px 10px;
274
+ border-radius: 3px; }
275
+ pre code, pre tt {
276
+ background-color: transparent;
277
+ border: none; }</style></head></html><body><h1>API</h1><h2>Products</h2><h3>Create [POST /products]</h3><h4>Payload</h4><p>The payload is an instance of the <b>product</b> schema.</p><div class="highlight highlight-json">
278
+ <pre><code> {
279
+ "name": "alias",
280
+ "code": "tempore",
281
+ "price": 14.92,
282
+ "category_id": "4"
283
+ }</pre></code>
284
+ </div><h4>Response</h4><p>Returns schema <b>product</b>.</p><div class="highlight highlight-json">
285
+ <pre><code> {
286
+ "created_at": "2014-12-17T00:29:05-05:00",
287
+ "updated_at": "2014-12-10T22:55:46-05:00",
288
+ "name": "blanditiis",
289
+ "code": "quidem",
290
+ "price": 22.32,
291
+ "category_id": "6",
292
+ "category": {
293
+ "name": "quas"
294
+ }
295
+ }</pre></code>
296
+ </div><h3>Index [GET /products]</h3><h4>Response</h4><p>Returns schema <b>product</b>.</p><div class="highlight highlight-json">
297
+ <pre><code> {
298
+ "created_at": "2014-12-02T17:25:48-05:00",
299
+ "updated_at": "2014-11-29T07:01:10-05:00",
300
+ "name": "ipsa",
301
+ "code": "temporibus",
302
+ "price": 7.6,
303
+ "category_id": "2"
304
+ }</pre></code>
305
+ </div><h3>Show [GET /products/:id]</h3><h4>Response</h4><p>Returns schema <b>product</b>.</p><div class="highlight highlight-json">
306
+ <pre><code> {
307
+ "created_at": "2014-12-11T05:40:53-05:00",
308
+ "updated_at": "2014-12-10T22:10:15-05:00",
309
+ "name": "dolores",
310
+ "code": "est",
311
+ "price": 66.12,
312
+ "category_id": "7",
313
+ "category": {
314
+ "name": "dolor"
315
+ }
316
+ }</pre></code>
317
+ </div><h3>Update [PUT /products/:id]</h3><h4>Response</h4><p>Returns schema <b>product</b>.</p><div class="highlight highlight-json">
318
+ <pre><code> {
319
+ "created_at": "2014-12-16T07:50:21-05:00",
320
+ "updated_at": "2014-12-11T05:50:57-05:00",
321
+ "name": "et",
322
+ "code": "enim",
323
+ "price": 62.43,
324
+ "category_id": "7",
325
+ "category": {
326
+ "name": "voluptatem"
327
+ }
328
+ }</pre></code>
329
+ </div><h3>Destroy [DELETE /products/:id]</h3><h4>Response</h4><p>The response is empty.</p><h2>Categories</h2><h3>Create [POST /categories]</h3><h4>Response</h4><p>Returns schema <b>category</b>.</p><div class="highlight highlight-json">
330
+ <pre><code> {
331
+ "name": "sunt"
332
+ }</pre></code>
333
+ </div><h3>Index [GET /categories]</h3><h4>Response</h4><p>Returns schema <b>category</b>.</p><div class="highlight highlight-json">
334
+ <pre><code> {
335
+ "name": "et"
336
+ }</pre></code>
337
+ </div><h3>Show [GET /categories/:id]</h3><h4>Response</h4><p>Returns schema <b>category</b>.</p><div class="highlight highlight-json">
338
+ <pre><code> {
339
+ "name": "voluptas"
340
+ }</pre></code>
341
+ </div><h3>Update [PUT /categories/:id]</h3><h4>Response</h4><p>Returns schema <b>category</b>.</p><div class="highlight highlight-json">
342
+ <pre><code> {
343
+ "name": "eos"
344
+ }</pre></code>
345
+ </div><h3>Destroy [DELETE /categories/:id]</h3><h4>Response</h4><p>The response is empty.</p><h3>Products [GET /categories/:id/products]</h3><h4>Response</h4><p>Returns schema <b>product</b>.</p><div class="highlight highlight-json">
346
+ <pre><code> {
347
+ "created_at": "2014-12-11T17:49:26-05:00",
348
+ "updated_at": "2014-12-07T14:18:24-05:00",
349
+ "name": "dolore",
350
+ "code": "dolore",
351
+ "price": 53.35,
352
+ "category_id": "7",
353
+ "category": {
354
+ "name": "vel"
355
+ }
356
+ }</pre></code>
357
+ </div></body>
@@ -1,65 +1,56 @@
1
1
  require 'tilt'
2
2
  require 'erb'
3
3
 
4
- module Restspec
5
- class DocsRunner < Thor::Group
6
- TEMPLATE_BY_EXTENSION = {
7
- '.md' => 'docs.md.erb'
8
- }
4
+ require_relative './template_context'
9
5
 
10
- argument :file, :default => 'api_docs.md'
6
+ module Restspec
7
+ module Docs
8
+ class DocsRunner < Thor::Group
9
+ TEMPLATE_BY_EXTENSION = {
10
+ '.md' => 'docs.md.erb',
11
+ '.html' => 'docs.html.slim'
12
+ }
11
13
 
12
- def generate_docs
13
- require 'restspec'
14
- require config_file
14
+ argument :file, :default => 'api_docs.md'
15
15
 
16
- File.write(file, read_template(extension))
17
- end
16
+ def generate_docs
17
+ require 'restspec'
18
+ require config_file
18
19
 
19
- private
20
+ File.write(file, read_template(extension))
21
+ end
20
22
 
21
- def read_template(extension)
22
- template_file_name = "templates/#{template_name}"
23
- template_file = Pathname.new(File.dirname(__FILE__)).join(template_file_name)
23
+ private
24
24
 
25
- Tilt.new(template_file).render(TemplateContext.new)
26
- end
25
+ def read_template(extension)
26
+ template_file_name = "templates/#{template_name}"
27
+ template_file = Pathname.new(File.dirname(__FILE__)).join(template_file_name)
27
28
 
28
- def extension
29
- match = file.match(/\.[\w]+$/)
30
- raise NoValidExtensionError if match.blank?
31
- match[0]
32
- end
33
-
34
- def template_name
35
- TEMPLATE_BY_EXTENSION.fetch(extension) do
36
- raise NoValidExtensionError
29
+ Tilt.new(template_file).render(TemplateContext.new)
37
30
  end
38
- end
39
31
 
40
- def config_file
41
- Pathname.new(Dir.pwd).join('spec/api/restspec/restspec_config.rb')
42
- end
43
-
44
- class TemplateContext
45
- def namespace_store
46
- Restspec::NamespaceStore
32
+ def extension
33
+ match = file.match(/\.[\w]+$/)
34
+ raise NoValidExtensionError if match.blank?
35
+ match[0]
47
36
  end
48
37
 
49
- def endpoints_store
50
- Restspec::EndpointStore
38
+ def template_name
39
+ TEMPLATE_BY_EXTENSION.fetch(extension) do
40
+ raise NoValidExtensionError
41
+ end
51
42
  end
52
43
 
53
- def schema_store
54
- Restspec::SchemaStore
44
+ def config_file
45
+ Pathname.new(Dir.pwd).join('spec/api/restspec/restspec_config.rb')
55
46
  end
56
- end
57
47
 
58
- class NoValidExtensionError < StandardError
59
- ERROR_MESSAGE = "ERROR: The file passed as argument does not include a valid extension"
48
+ class NoValidExtensionError < StandardError
49
+ ERROR_MESSAGE = "ERROR: The file passed as argument does not include a valid extension"
60
50
 
61
- def initialize(msg = ERROR_MESSAGE)
62
- super(msg)
51
+ def initialize(msg = ERROR_MESSAGE)
52
+ super(msg)
53
+ end
63
54
  end
64
55
  end
65
56
  end
@@ -0,0 +1,28 @@
1
+ module Restspec
2
+ module Docs
3
+ class TemplateContext
4
+ def namespace_store
5
+ Restspec::NamespaceStore
6
+ end
7
+
8
+ def endpoints_store
9
+ Restspec::EndpointStore
10
+ end
11
+
12
+ def schema_store
13
+ Restspec::SchemaStore
14
+ end
15
+
16
+ def json_example(schema)
17
+ sample = Restspec::Schema::SchemaExample.new(schema).value
18
+ JSON.pretty_generate(sample).gsub(/^/, ' ')
19
+ end
20
+
21
+ def json_example_code(schema)
22
+ "<div class=\"highlight highlight-json\">
23
+ <pre><code>#{json_example(schema)}</pre></code>
24
+ </div>"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,307 @@
1
+ doctype 5
2
+ html
3
+ head
4
+ title API
5
+ link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.min.css"
6
+ css:
7
+ body {
8
+ font-family: Helvetica, arial, sans-serif;
9
+ font-size: 14px;
10
+ line-height: 1.6;
11
+ padding-top: 10px;
12
+ padding-bottom: 10px;
13
+ background-color: white;
14
+ padding: 30px; }
15
+
16
+ body > *:first-child {
17
+ margin-top: 0 !important; }
18
+ body > *:last-child {
19
+ margin-bottom: 0 !important; }
20
+
21
+ a {
22
+ color: #4183C4; }
23
+ a.absent {
24
+ color: #cc0000; }
25
+ a.anchor {
26
+ display: block;
27
+ padding-left: 30px;
28
+ margin-left: -30px;
29
+ cursor: pointer;
30
+ position: absolute;
31
+ top: 0;
32
+ left: 0;
33
+ bottom: 0; }
34
+
35
+ h1, h2, h3, h4, h5, h6 {
36
+ margin: 20px 0 10px;
37
+ padding: 0;
38
+ font-weight: bold;
39
+ -webkit-font-smoothing: antialiased;
40
+ cursor: text;
41
+ position: relative; }
42
+
43
+ h1:hover a.anchor, h2:hover a.anchor, h3:hover a.anchor, h4:hover a.anchor, h5:hover a.anchor, h6:hover a.anchor {
44
+ background: url("../../images/modules/styleguide/para.png") no-repeat 10px center;
45
+ text-decoration: none; }
46
+
47
+ h1 tt, h1 code {
48
+ font-size: inherit; }
49
+
50
+ h2 tt, h2 code {
51
+ font-size: inherit; }
52
+
53
+ h3 tt, h3 code {
54
+ font-size: inherit; }
55
+
56
+ h4 tt, h4 code {
57
+ font-size: inherit; }
58
+
59
+ h5 tt, h5 code {
60
+ font-size: inherit; }
61
+
62
+ h6 tt, h6 code {
63
+ font-size: inherit; }
64
+
65
+ h1 {
66
+ font-size: 28px;
67
+ color: black; }
68
+
69
+ h2 {
70
+ font-size: 24px;
71
+ border-bottom: 1px solid #cccccc;
72
+ color: black; }
73
+
74
+ h3 {
75
+ font-size: 18px; }
76
+
77
+ h4 {
78
+ font-size: 16px; }
79
+
80
+ h5 {
81
+ font-size: 14px; }
82
+
83
+ h6 {
84
+ color: #777777;
85
+ font-size: 14px; }
86
+
87
+ p, blockquote, ul, ol, dl, li, table, pre {
88
+ margin: 15px 0; }
89
+
90
+ hr {
91
+ background: transparent url("../../images/modules/pulls/dirty-shade.png") repeat-x 0 0;
92
+ border: 0 none;
93
+ color: #cccccc;
94
+ height: 4px;
95
+ padding: 0; }
96
+
97
+ body > h2:first-child {
98
+ margin-top: 0;
99
+ padding-top: 0; }
100
+ body > h1:first-child {
101
+ margin-top: 0;
102
+ padding-top: 0; }
103
+ body > h1:first-child + h2 {
104
+ margin-top: 0;
105
+ padding-top: 0; }
106
+ body > h3:first-child, body > h4:first-child, body > h5:first-child, body > h6:first-child {
107
+ margin-top: 0;
108
+ padding-top: 0; }
109
+
110
+ a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
111
+ margin-top: 0;
112
+ padding-top: 0; }
113
+
114
+ h1 p, h2 p, h3 p, h4 p, h5 p, h6 p {
115
+ margin-top: 0; }
116
+
117
+ li p.first {
118
+ display: inline-block; }
119
+
120
+ ul, ol {
121
+ padding-left: 30px; }
122
+
123
+ ul :first-child, ol :first-child {
124
+ margin-top: 0; }
125
+
126
+ ul :last-child, ol :last-child {
127
+ margin-bottom: 0; }
128
+
129
+ dl {
130
+ padding: 0; }
131
+ dl dt {
132
+ font-size: 14px;
133
+ font-weight: bold;
134
+ font-style: italic;
135
+ padding: 0;
136
+ margin: 15px 0 5px; }
137
+ dl dt:first-child {
138
+ padding: 0; }
139
+ dl dt > :first-child {
140
+ margin-top: 0; }
141
+ dl dt > :last-child {
142
+ margin-bottom: 0; }
143
+ dl dd {
144
+ margin: 0 0 15px;
145
+ padding: 0 15px; }
146
+ dl dd > :first-child {
147
+ margin-top: 0; }
148
+ dl dd > :last-child {
149
+ margin-bottom: 0; }
150
+
151
+ blockquote {
152
+ border-left: 4px solid #dddddd;
153
+ padding: 0 15px;
154
+ color: #777777; }
155
+ blockquote > :first-child {
156
+ margin-top: 0; }
157
+ blockquote > :last-child {
158
+ margin-bottom: 0; }
159
+
160
+ table {
161
+ padding: 0; }
162
+ table tr {
163
+ border-top: 1px solid #cccccc;
164
+ background-color: white;
165
+ margin: 0;
166
+ padding: 0; }
167
+ table tr:nth-child(2n) {
168
+ background-color: #f8f8f8; }
169
+ table tr th {
170
+ font-weight: bold;
171
+ border: 1px solid #cccccc;
172
+ text-align: left;
173
+ margin: 0;
174
+ padding: 6px 13px; }
175
+ table tr td {
176
+ border: 1px solid #cccccc;
177
+ text-align: left;
178
+ margin: 0;
179
+ padding: 6px 13px; }
180
+ table tr th :first-child, table tr td :first-child {
181
+ margin-top: 0; }
182
+ table tr th :last-child, table tr td :last-child {
183
+ margin-bottom: 0; }
184
+
185
+ img {
186
+ max-width: 100%; }
187
+
188
+ span.frame {
189
+ display: block;
190
+ overflow: hidden; }
191
+ span.frame > span {
192
+ border: 1px solid #dddddd;
193
+ display: block;
194
+ float: left;
195
+ overflow: hidden;
196
+ margin: 13px 0 0;
197
+ padding: 7px;
198
+ width: auto; }
199
+ span.frame span img {
200
+ display: block;
201
+ float: left; }
202
+ span.frame span span {
203
+ clear: both;
204
+ color: #333333;
205
+ display: block;
206
+ padding: 5px 0 0; }
207
+ span.align-center {
208
+ display: block;
209
+ overflow: hidden;
210
+ clear: both; }
211
+ span.align-center > span {
212
+ display: block;
213
+ overflow: hidden;
214
+ margin: 13px auto 0;
215
+ text-align: center; }
216
+ span.align-center span img {
217
+ margin: 0 auto;
218
+ text-align: center; }
219
+ span.align-right {
220
+ display: block;
221
+ overflow: hidden;
222
+ clear: both; }
223
+ span.align-right > span {
224
+ display: block;
225
+ overflow: hidden;
226
+ margin: 13px 0 0;
227
+ text-align: right; }
228
+ span.align-right span img {
229
+ margin: 0;
230
+ text-align: right; }
231
+ span.float-left {
232
+ display: block;
233
+ margin-right: 13px;
234
+ overflow: hidden;
235
+ float: left; }
236
+ span.float-left span {
237
+ margin: 13px 0 0; }
238
+ span.float-right {
239
+ display: block;
240
+ margin-left: 13px;
241
+ overflow: hidden;
242
+ float: right; }
243
+ span.float-right > span {
244
+ display: block;
245
+ overflow: hidden;
246
+ margin: 13px auto 0;
247
+ text-align: right; }
248
+
249
+ code, tt {
250
+ margin: 0 2px;
251
+ padding: 0 5px;
252
+ white-space: nowrap;
253
+ border: 1px solid #eaeaea;
254
+ background-color: #f8f8f8;
255
+ border-radius: 3px; }
256
+
257
+ pre code {
258
+ margin: 0;
259
+ padding: 0;
260
+ white-space: pre;
261
+ border: none;
262
+ background: transparent; }
263
+
264
+ .highlight pre {
265
+ background-color: #f8f8f8;
266
+ border: 1px solid #cccccc;
267
+ font-size: 13px;
268
+ line-height: 19px;
269
+ overflow: auto;
270
+ padding: 6px 10px;
271
+ border-radius: 3px; }
272
+
273
+ pre {
274
+ background-color: #f8f8f8;
275
+ border: 1px solid #cccccc;
276
+ font-size: 13px;
277
+ line-height: 19px;
278
+ overflow: auto;
279
+ padding: 6px 10px;
280
+ border-radius: 3px; }
281
+ pre code, pre tt {
282
+ background-color: transparent;
283
+ border: none; }
284
+ body
285
+ h1 API
286
+
287
+ - namespace_store.each do |name, namespace|
288
+ h2= name.capitalize
289
+
290
+ - namespace.all_endpoints.each do |endpoint|
291
+ h3
292
+ | #{endpoint.name.capitalize} [#{endpoint.method.upcase} #{endpoint.full_path}]
293
+
294
+ - if payload_schema = endpoint.schema_for(:payload)
295
+ h4 Payload
296
+
297
+ p The payload is an instance of the <b>#{payload_schema.name}</b> schema.
298
+
299
+ == json_example_code(payload_schema)
300
+
301
+ h4 Response
302
+ - if response_schema = endpoint.schema_for(:response)
303
+ p Returns schema <b>#{response_schema.name}</b>.
304
+
305
+ == json_example_code(response_schema)
306
+ - else
307
+ p The response is empty.
@@ -12,25 +12,20 @@
12
12
 
13
13
  The payload is an instance of the **<%= payload_schema.name %>** schema.
14
14
 
15
- <% sample = Restspec::Schema::SchemaExample.new(payload_schema).value %>
16
-
17
15
  ```json
18
- <%= JSON.pretty_generate(sample).gsub(/^/, ' ') %>
16
+ <%= json_example payload_schema %>
19
17
  ```
20
-
21
18
  <% end %>
22
19
 
23
20
  #### Response
24
21
  <% if response_schema = endpoint.schema_for(:response) %>
25
- Returns schema **<%= response_schema.name %>**
26
-
27
- <% sample = Restspec::Schema::SchemaExample.new(response_schema).value %>
22
+ Returns schema **<%= response_schema.name %>**
28
23
 
29
24
  ```json
30
- <%= JSON.pretty_generate(sample).gsub(/^/, ' ') %>
25
+ <%= json_example response_schema %>
31
26
  ```
32
27
  <% else %>
33
- The response is empty.
28
+ The response is empty.
34
29
  <% end %>
35
30
 
36
31
  <% end %>
@@ -1,50 +1,52 @@
1
1
  module Restspec
2
- class InstallRunner < Thor::Group
3
- include Thor::Actions
4
-
5
- argument :project
6
-
7
- class_option :api_prefix, :desc => "api prefix to use", :required => true
8
-
9
- def self.source_root
10
- File.dirname(__FILE__)
11
- end
12
-
13
- def create_project_dir
14
- empty_directory project
15
- end
16
-
17
- def copy_gemfile
18
- copy_file 'templates/Gemfile', "#{project}/Gemfile"
19
- end
20
-
21
- def create_spec_folders
22
- empty_directory "#{project}/spec"
23
- empty_directory "#{project}/spec/api"
24
- empty_directory "#{project}/spec/support"
25
- end
26
-
27
- def create_spec_helper
28
- template 'templates/spec_helper.rb', "#{project}/spec/spec_helper.rb"
29
- end
30
-
31
- def create_rspec_config
32
- template 'templates/restspec_config.rb', "#{project}/spec/api/restspec/restspec_config.rb"
33
- end
34
-
35
- def create_api_dsl_files
36
- create_file "#{project}/spec/api/restspec/api_endpoints.rb"
37
- create_file "#{project}/spec/api/restspec/api_schemas.rb"
38
- create_file "#{project}/spec/api/restspec/api_requirements.rb"
39
- end
40
-
41
- def create_support_files
42
- create_file "#{project}/spec/support/custom_matchers.rb"
43
- copy_file "templates/custom_macros.rb", "#{project}/spec/support/custom_macros.rb"
44
- end
45
-
46
- def install_gems
47
- inside(project) { run 'bundle install' }
2
+ module Install
3
+ class InstallRunner < Thor::Group
4
+ include Thor::Actions
5
+
6
+ argument :project
7
+
8
+ class_option :api_prefix, :desc => "api prefix to use", :required => true
9
+
10
+ def self.source_root
11
+ File.dirname(__FILE__)
12
+ end
13
+
14
+ def create_project_dir
15
+ empty_directory project
16
+ end
17
+
18
+ def copy_gemfile
19
+ copy_file 'templates/Gemfile', "#{project}/Gemfile"
20
+ end
21
+
22
+ def create_spec_folders
23
+ empty_directory "#{project}/spec"
24
+ empty_directory "#{project}/spec/api"
25
+ empty_directory "#{project}/spec/support"
26
+ end
27
+
28
+ def create_spec_helper
29
+ template 'templates/spec_helper.rb', "#{project}/spec/spec_helper.rb"
30
+ end
31
+
32
+ def create_rspec_config
33
+ template 'templates/restspec_config.rb', "#{project}/spec/api/restspec/restspec_config.rb"
34
+ end
35
+
36
+ def create_api_dsl_files
37
+ create_file "#{project}/spec/api/restspec/api_endpoints.rb"
38
+ create_file "#{project}/spec/api/restspec/api_schemas.rb"
39
+ create_file "#{project}/spec/api/restspec/api_requirements.rb"
40
+ end
41
+
42
+ def create_support_files
43
+ create_file "#{project}/spec/support/custom_matchers.rb"
44
+ copy_file "templates/custom_macros.rb", "#{project}/spec/support/custom_macros.rb"
45
+ end
46
+
47
+ def install_gems
48
+ inside(project) { run 'bundle install' }
49
+ end
48
50
  end
49
51
  end
50
52
  end
@@ -1,3 +1,3 @@
1
1
  module Restspec
2
- VERSION = "0.2"
2
+ VERSION = "0.2.1"
3
3
  end
data/restspec.gemspec CHANGED
@@ -35,6 +35,6 @@ Gem::Specification.new do |spec|
35
35
  spec.add_dependency "rspec-its", "~> 1.0"
36
36
  spec.add_dependency "rspec-collection_matchers", "~> 1.0"
37
37
  spec.add_dependency "thor", "~> 0.19"
38
- spec.add_dependency "tilt", "~> 2.0"
38
+ spec.add_dependency "tilt", "~> 1.1"
39
39
  spec.add_dependency "ruby_deep_clone", "~> 0.6"
40
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restspec
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - juliogarciag
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-28 00:00:00.000000000 Z
11
+ date: 2015-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -254,14 +254,14 @@ dependencies:
254
254
  requirements:
255
255
  - - ~>
256
256
  - !ruby/object:Gem::Version
257
- version: '2.0'
257
+ version: '1.1'
258
258
  type: :runtime
259
259
  prerelease: false
260
260
  version_requirements: !ruby/object:Gem::Requirement
261
261
  requirements:
262
262
  - - ~>
263
263
  - !ruby/object:Gem::Version
264
- version: '2.0'
264
+ version: '1.1'
265
265
  - !ruby/object:Gem::Dependency
266
266
  name: ruby_deep_clone
267
267
  requirement: !ruby/object:Gem::Requirement
@@ -300,7 +300,7 @@ files:
300
300
  - examples/store-api-tests/.rspec
301
301
  - examples/store-api-tests/Gemfile
302
302
  - examples/store-api-tests/Gemfile.lock
303
- - examples/store-api-tests/api.md
303
+ - examples/store-api-tests/api.html
304
304
  - examples/store-api-tests/spec/api/category_spec.rb
305
305
  - examples/store-api-tests/spec/api/product_spec.rb
306
306
  - examples/store-api-tests/spec/api/restspec/endpoints.rb
@@ -444,6 +444,8 @@ files:
444
444
  - lib/restspec/rspec/matchers/include_where.rb
445
445
  - lib/restspec/rspec/shared_examples.rb
446
446
  - lib/restspec/runners/docs/docs_runner.rb
447
+ - lib/restspec/runners/docs/template_context.rb
448
+ - lib/restspec/runners/docs/templates/docs.html.slim
447
449
  - lib/restspec/runners/docs/templates/docs.md.erb
448
450
  - lib/restspec/runners/install/install_runner.rb
449
451
  - lib/restspec/runners/install/templates/Gemfile
@@ -1,189 +0,0 @@
1
- # API
2
- ## Hello World
3
-
4
- ## Products
5
-
6
- ### Create [POST /products]
7
-
8
- #### Payload
9
-
10
- The payload is an instance of the **product** schema.
11
-
12
-
13
- ```json
14
- {
15
- "name": "consequatur",
16
- "code": "corporis",
17
- "price": 86.56,
18
- "category_id": "5"
19
- }
20
- ```
21
-
22
-
23
- #### Response
24
- Returns schema **product**
25
-
26
-
27
- ```json
28
- {
29
- "created_at": "2014-12-08T20:04:00-05:00",
30
- "updated_at": "2014-12-02T21:02:47-05:00",
31
- "name": "ut",
32
- "code": "nobis",
33
- "price": 13.52,
34
- "category_id": "1",
35
- "category": {
36
- "name": "delectus"
37
- }
38
- }
39
- ```
40
-
41
- ### Index [GET /products]
42
-
43
-
44
- #### Response
45
- Returns schema **product**
46
-
47
-
48
- ```json
49
- {
50
- "created_at": "2014-12-27T12:23:04-05:00",
51
- "updated_at": "2014-12-04T23:20:43-05:00",
52
- "name": "voluptatem",
53
- "code": "facilis",
54
- "price": 41.47,
55
- "category_id": "8"
56
- }
57
- ```
58
-
59
- ### Show [GET /products/:id]
60
-
61
-
62
- #### Response
63
- Returns schema **product**
64
-
65
-
66
- ```json
67
- {
68
- "created_at": "2014-11-28T20:21:40-05:00",
69
- "updated_at": "2014-12-28T08:10:27-05:00",
70
- "name": "quasi",
71
- "code": "rerum",
72
- "price": 39.48,
73
- "category_id": "0",
74
- "category": {
75
- "name": "saepe"
76
- }
77
- }
78
- ```
79
-
80
- ### Update [PUT /products/:id]
81
-
82
-
83
- #### Response
84
- Returns schema **product**
85
-
86
-
87
- ```json
88
- {
89
- "created_at": "2014-12-27T02:32:32-05:00",
90
- "updated_at": "2014-12-05T22:31:32-05:00",
91
- "name": "iure",
92
- "code": "autem",
93
- "price": 47.17,
94
- "category_id": "1",
95
- "category": {
96
- "name": "ut"
97
- }
98
- }
99
- ```
100
-
101
- ### Destroy [DELETE /products/:id]
102
-
103
-
104
- #### Response
105
- The response is empty.
106
-
107
-
108
- ## Categories
109
-
110
- ### Create [POST /categories]
111
-
112
-
113
- #### Response
114
- Returns schema **category**
115
-
116
-
117
- ```json
118
- {
119
- "name": "quaerat"
120
- }
121
- ```
122
-
123
- ### Index [GET /categories]
124
-
125
-
126
- #### Response
127
- Returns schema **category**
128
-
129
-
130
- ```json
131
- {
132
- "name": "amet"
133
- }
134
- ```
135
-
136
- ### Show [GET /categories/:id]
137
-
138
-
139
- #### Response
140
- Returns schema **category**
141
-
142
-
143
- ```json
144
- {
145
- "name": "consequatur"
146
- }
147
- ```
148
-
149
- ### Update [PUT /categories/:id]
150
-
151
-
152
- #### Response
153
- Returns schema **category**
154
-
155
-
156
- ```json
157
- {
158
- "name": "voluptatem"
159
- }
160
- ```
161
-
162
- ### Destroy [DELETE /categories/:id]
163
-
164
-
165
- #### Response
166
- The response is empty.
167
-
168
- ### Products [GET /categories/:id/products]
169
-
170
-
171
- #### Response
172
- Returns schema **product**
173
-
174
-
175
- ```json
176
- {
177
- "created_at": "2014-12-13T00:42:13-05:00",
178
- "updated_at": "2014-12-12T18:31:59-05:00",
179
- "name": "labore",
180
- "code": "exercitationem",
181
- "price": 15.84,
182
- "category_id": "0",
183
- "category": {
184
- "name": "incidunt"
185
- }
186
- }
187
- ```
188
-
189
-