api_sketch 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +7 -2
- data/README.md +63 -9
- data/api_sketch.gemspec +0 -1
- data/examples/api_project/config/initializers/shared_blocks.rb +15 -0
- data/examples/api_project/resources/places.rb +138 -0
- data/examples/api_project/resources/users/points/stats.rb +30 -0
- data/examples/api_project/resources/users/points.rb +32 -0
- data/examples/api_project/resources/users.rb +341 -0
- data/lib/api_sketch/config.rb +1 -1
- data/lib/api_sketch/dsl/attribute_parser.rb +19 -0
- data/lib/api_sketch/dsl/attributes.rb +45 -0
- data/lib/api_sketch/dsl/base.rb +8 -0
- data/lib/api_sketch/dsl/complex_attribute_parser.rb +11 -0
- data/lib/api_sketch/dsl/headers.rb +17 -0
- data/lib/api_sketch/dsl/parameters.rb +31 -0
- data/lib/api_sketch/dsl/responses.rb +22 -0
- data/lib/api_sketch/dsl.rb +27 -165
- data/lib/api_sketch/examples_server.rb +1 -1
- data/lib/api_sketch/generators/base.rb +42 -0
- data/lib/api_sketch/{generators.rb → generators/bootstrap.rb} +2 -46
- data/lib/api_sketch/model/attribute.rb +42 -0
- data/lib/api_sketch/model/base.rb +17 -0
- data/lib/api_sketch/model/header.rb +7 -0
- data/lib/api_sketch/model/parameters.rb +50 -0
- data/lib/api_sketch/model/resource.rb +99 -0
- data/lib/api_sketch/model/response.rb +12 -0
- data/lib/api_sketch/model/shared_block.rb +17 -0
- data/lib/api_sketch/model.rb +0 -242
- data/lib/api_sketch/{renderers.rb → response_renderer.rb} +0 -0
- data/lib/api_sketch/version.rb +1 -1
- data/lib/api_sketch.rb +20 -3
- data/spec/lib/api_sketch/dsl/attribute_parser_spec.rb +14 -0
- data/spec/lib/api_sketch/dsl/attributes_spec.rb +14 -0
- data/spec/lib/api_sketch/dsl/complex_attribute_parser_spec.rb +14 -0
- data/spec/lib/api_sketch/dsl/headers_spec.rb +14 -0
- data/spec/lib/api_sketch/dsl/parameters_spec.rb +14 -0
- data/spec/lib/api_sketch/dsl/responses_spec.rb +14 -0
- data/spec/lib/api_sketch/dsl_spec.rb +5 -3
- data/spec/lib/api_sketch/model/parameters_spec.rb +28 -0
- data/spec/lib/api_sketch/{renderers_spec.rb → response_renderer_spec.rb} +51 -1
- data/spec/spec_helper.rb +3 -1
- data/spec/support/shared_examples.rb +9 -0
- metadata +43 -9
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90161a84fafcc80e8b44bf641e4c40a865a22eed
|
4
|
+
data.tar.gz: 0642fda7b9fb81ab9802f2671d830871497a7e97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 829d920527e420846256e6bf8ff95426da47b7c9c5ba2679a9bec20dc6a85cdf2a91ff30e77220a44bcf9ea40e44d4cf214b70db9e8a09d0cf3643fbb63bc646
|
7
|
+
data.tar.gz: 04df4fc5c7fd28268223ea6a6f28f457d9d3d4f62b33ac6509f21ad0c137826d8ce2198ccd4d52088fc2067a177d963072ce16c2f7f490421a9962c125adb031
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
# 0.1.
|
1
|
+
# 0.1.2 / 2015-05-31
|
2
|
+
|
3
|
+
- Add `shared_block "shared block name"` (definition keyword) search keyword by it's to blocks. Keyword `use_shared_block "shared block name"` is used to find and use previously definded block. Shared blocks are be placed into special directory 'config/shared' at input folder to be loaded before all examples.
|
4
|
+
- Reorganize internal gem structure.
|
5
|
+
|
6
|
+
# 0.1.1 / 2015-05-03
|
2
7
|
|
3
8
|
- Bootstrap template: put all generated pages data into `{output_folder}/docs` directory. Left `assets` directory outside since it may clash with generated files/folders names.
|
4
9
|
- Add endpoint search by conjuction of request `path` & `http_method` for API examples server (Works like normal api server now).
|
@@ -12,4 +17,4 @@
|
|
12
17
|
|
13
18
|
# 0.0.1 / 2015-01-24
|
14
19
|
|
15
|
-
Initial release
|
20
|
+
Initial release
|
data/README.md
CHANGED
@@ -107,12 +107,19 @@ Definitions
|
|
107
107
|
|
108
108
|
API definitions files should be placed into directory with structure similar to `definitions` folder in this example. Directory may have only one file or many files and folders with files. Resurce's `namespace` is derived from this hierachical structure.
|
109
109
|
|
110
|
+
`config` folder is loaded before `resources` folder. Some initial data as shared definition blocks may be placed at config folder.
|
111
|
+
|
110
112
|
```
|
111
113
|
definitions
|
112
|
-
├──
|
113
|
-
|
114
|
-
│
|
115
|
-
|
114
|
+
├── config
|
115
|
+
│ └── initializers
|
116
|
+
│ └── shared_blocks.rb
|
117
|
+
│
|
118
|
+
└── resources
|
119
|
+
├── places.rb
|
120
|
+
├── users
|
121
|
+
│ └── points.rb
|
122
|
+
└── users.rb
|
116
123
|
```
|
117
124
|
##### DSL
|
118
125
|
|
@@ -172,9 +179,7 @@ resource "Update user profile" do # Resource name
|
|
172
179
|
integer "repeat_times" do
|
173
180
|
description "times to repeat hello message"
|
174
181
|
end
|
175
|
-
end
|
176
182
|
|
177
|
-
query :document do
|
178
183
|
integer "page" do
|
179
184
|
description "page number"
|
180
185
|
required false
|
@@ -369,7 +374,57 @@ resource "Update user profile" do # Resource name
|
|
369
374
|
end
|
370
375
|
```
|
371
376
|
|
372
|
-
For more detailed DSL features examples check DSL test files at spec
|
377
|
+
For more detailed DSL features examples check DSL test files at `spec` and `examples` folders.
|
378
|
+
|
379
|
+
#####DSL: Shared exmples
|
380
|
+
|
381
|
+
This feature is designed to reduce definition duplications.
|
382
|
+
Here is shared block definition example. It's defintion should be placed into `config` directory.
|
383
|
+
|
384
|
+
```ruby
|
385
|
+
shared_block "place fields" do
|
386
|
+
integer "id" do
|
387
|
+
description "Place database ID"
|
388
|
+
end
|
389
|
+
|
390
|
+
string "name" do
|
391
|
+
description "Place name"
|
392
|
+
example { ["Cafe", "Market", "Restaurant", "Parking", "Park", "Palace", "Stadium"].sample }
|
393
|
+
end
|
394
|
+
|
395
|
+
float "area" do
|
396
|
+
description "Place area in square meters"
|
397
|
+
example { rand(100) + rand.round(2) }
|
398
|
+
end
|
399
|
+
end
|
400
|
+
```
|
401
|
+
|
402
|
+
Shared block usage example. Keyword `use_shared_block` is available at `headers`, `parameters`, `attributes` and `responses` definitions.
|
403
|
+
|
404
|
+
```ruby
|
405
|
+
resource "Get places list" do
|
406
|
+
action "index"
|
407
|
+
path "/api/places.json"
|
408
|
+
http_method "GET"
|
409
|
+
format "json"
|
410
|
+
|
411
|
+
responses do
|
412
|
+
context "Success" do
|
413
|
+
http_status :ok
|
414
|
+
|
415
|
+
parameters do
|
416
|
+
body :array do
|
417
|
+
document do
|
418
|
+
content do
|
419
|
+
use_shared_block "place fields"
|
420
|
+
end
|
421
|
+
end
|
422
|
+
end
|
423
|
+
end
|
424
|
+
end
|
425
|
+
end
|
426
|
+
end
|
427
|
+
```
|
373
428
|
|
374
429
|
TODO
|
375
430
|
----
|
@@ -384,7 +439,6 @@ TODO
|
|
384
439
|
- Add realtime viewable page with log for this api examples server application to let client side developers see what data they have sent and how server received it
|
385
440
|
- Add more validations to models.
|
386
441
|
- Add more specs and tests.
|
387
|
-
- Add `shared_block "shared block name"` (definition keyword) search keyword by it's to blocks. Maybe `uses_shared_block "shared block name"`. Maybe shared blocks should be placed into special directory at definitions to be loaded before all examples
|
388
442
|
- Add more complex example values autogeneration for API examples server. Derive values from key names. For example string "email" should have some email value as response example.
|
389
443
|
- rDoc documentation for code.
|
390
444
|
|
@@ -408,4 +462,4 @@ Inspirations
|
|
408
462
|
License
|
409
463
|
-------
|
410
464
|
|
411
|
-
ApiSketch is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
465
|
+
ApiSketch is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
data/api_sketch.gemspec
CHANGED
@@ -12,7 +12,6 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.homepage = "https://github.com/suhovius/api_sketch"
|
13
13
|
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.post_install_message = "Thanks for installing!"
|
16
15
|
|
17
16
|
spec.files = `git ls-files -z`.split("\x0")
|
18
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -0,0 +1,15 @@
|
|
1
|
+
shared_block "place fields" do
|
2
|
+
integer "id" do
|
3
|
+
description "Place database ID"
|
4
|
+
end
|
5
|
+
|
6
|
+
string "name" do
|
7
|
+
description "Place name"
|
8
|
+
example { ["Cafe", "Market", "Restaurant", "Parking", "Park", "Palace", "Stadium"].sample }
|
9
|
+
end
|
10
|
+
|
11
|
+
float "area" do
|
12
|
+
description "Place area in square meters"
|
13
|
+
example { rand(100) + rand.round(2) }
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
resource "Get place details" do
|
2
|
+
action "show"
|
3
|
+
description "Place details"
|
4
|
+
path "/api/places/:place_id.json"
|
5
|
+
http_method "GET"
|
6
|
+
format "json"
|
7
|
+
|
8
|
+
parameters do
|
9
|
+
query :array do
|
10
|
+
string do
|
11
|
+
description "place name"
|
12
|
+
end
|
13
|
+
|
14
|
+
integer do
|
15
|
+
description "search radius"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
responses do
|
21
|
+
context "Success" do
|
22
|
+
http_status :ok # 200
|
23
|
+
|
24
|
+
parameters do
|
25
|
+
body :document do
|
26
|
+
use_shared_block "place fields"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
resource "Create place" do
|
35
|
+
action "create"
|
36
|
+
path "/api/places.json"
|
37
|
+
http_method "POST"
|
38
|
+
format "json"
|
39
|
+
|
40
|
+
parameters do
|
41
|
+
body :document do
|
42
|
+
string "name" do
|
43
|
+
description "Place name"
|
44
|
+
example { ["Cafe", "Market", "Restaurant", "Parking", "Park", "Palace", "Stadium"].sample }
|
45
|
+
end
|
46
|
+
|
47
|
+
float "area" do
|
48
|
+
description "Place area in square meters"
|
49
|
+
example { rand(100) + rand.round(2) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
responses do
|
55
|
+
context "Success" do
|
56
|
+
http_status :ok # 200
|
57
|
+
|
58
|
+
parameters do
|
59
|
+
body :document do
|
60
|
+
use_shared_block "place fields"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
resource "Update place" do
|
70
|
+
action "update"
|
71
|
+
path "/api/places/:place_id.json"
|
72
|
+
http_method "PUT"
|
73
|
+
format "json"
|
74
|
+
|
75
|
+
parameters do
|
76
|
+
body :document do
|
77
|
+
string "name" do
|
78
|
+
description "Place name"
|
79
|
+
example { ["Cafe", "Market", "Restaurant", "Parking", "Park", "Palace", "Stadium"].sample }
|
80
|
+
end
|
81
|
+
|
82
|
+
float "area" do
|
83
|
+
description "Place area in square meters"
|
84
|
+
example { rand(100) + rand.round(2) }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
responses do
|
90
|
+
context "Success" do
|
91
|
+
http_status :ok # 200
|
92
|
+
|
93
|
+
parameters do
|
94
|
+
body :document do
|
95
|
+
use_shared_block "place fields"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
resource "Get places list" do
|
104
|
+
action "index"
|
105
|
+
path "/api/places.json"
|
106
|
+
http_method "GET"
|
107
|
+
format "json"
|
108
|
+
|
109
|
+
parameters do
|
110
|
+
query :document do
|
111
|
+
integer "page" do
|
112
|
+
description "Pagination page"
|
113
|
+
default 1
|
114
|
+
end
|
115
|
+
|
116
|
+
integer "per_page" do
|
117
|
+
description "Pagination place per page"
|
118
|
+
default 25
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
responses do
|
124
|
+
context "Success" do
|
125
|
+
http_status :ok # 200
|
126
|
+
|
127
|
+
parameters do
|
128
|
+
body :array do
|
129
|
+
document do
|
130
|
+
content do
|
131
|
+
use_shared_block "place fields"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
resource "Get user points stats" do
|
2
|
+
action "index"
|
3
|
+
description "User points stats"
|
4
|
+
path "/api/users/username/points/stats.json"
|
5
|
+
http_method "GET"
|
6
|
+
format "json"
|
7
|
+
|
8
|
+
responses do
|
9
|
+
context "Success" do
|
10
|
+
http_status :ok # 200
|
11
|
+
|
12
|
+
parameters do
|
13
|
+
body :document do
|
14
|
+
document "stats" do
|
15
|
+
content do
|
16
|
+
string "total" do
|
17
|
+
description "total amount"
|
18
|
+
example { rand(100) }
|
19
|
+
end
|
20
|
+
string "rank" do
|
21
|
+
description "user's rank"
|
22
|
+
example { ["Junior", "Middle", "Senior"].sample }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
resource "Get user points" do
|
2
|
+
action "index"
|
3
|
+
description "User points"
|
4
|
+
path "/api/users/username/points.json"
|
5
|
+
http_method "GET"
|
6
|
+
format "json"
|
7
|
+
|
8
|
+
responses do
|
9
|
+
context "Success" do
|
10
|
+
http_status :ok # 200
|
11
|
+
|
12
|
+
parameters do
|
13
|
+
body :array do
|
14
|
+
document do
|
15
|
+
content do
|
16
|
+
integer "items" do
|
17
|
+
description "user's items"
|
18
|
+
example { rand(1000) }
|
19
|
+
end
|
20
|
+
|
21
|
+
integer "rank" do
|
22
|
+
description "user's rank"
|
23
|
+
example { ["Test User", "Real User"].sample }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|