jdoc 0.0.9 → 0.1.0
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/CHANGELOG.md +3 -0
- data/lib/jdoc/link.rb +1 -1
- data/lib/jdoc/resource.rb +13 -1
- data/lib/jdoc/schema.rb +5 -23
- data/lib/jdoc/version.rb +1 -1
- data/spec/fixtures/schema.yml +2 -0
- data/spec/jdoc/generator_spec.rb +40 -31
- data/template.md.erb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecaf31b4e9cc6005cf7980e77b5f8967a9d1e4a1
|
4
|
+
data.tar.gz: 449ee41071bbf4467556d1150418f32bf686b530
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f1bc864b397b9c4bd30ff0a936a5856e2a965d47773a195a91c00267e807231872831b85f4cef362578fce891dfdd00b3bc82312a58c924cd5070fbfb8419cd
|
7
|
+
data.tar.gz: f1788851e9708e9ffc34eb8a8adafc3775f63c1eb789da355e0035a4ae33047e810c9932e22487b7fa073a4900d3e6f2e17f3571193556b7f11147b13c694ef6
|
data/CHANGELOG.md
CHANGED
data/lib/jdoc/link.rb
CHANGED
data/lib/jdoc/resource.rb
CHANGED
@@ -49,7 +49,19 @@ module Jdoc
|
|
49
49
|
|
50
50
|
# Defined to change uniqueness in Hash key
|
51
51
|
def eql?(other)
|
52
|
-
@schema.title ==
|
52
|
+
@schema.title == other.title
|
53
|
+
end
|
54
|
+
|
55
|
+
def <=>(other)
|
56
|
+
@schema.title <=> other.title
|
57
|
+
end
|
58
|
+
|
59
|
+
def links
|
60
|
+
@links ||= @schema.links.map do |link|
|
61
|
+
if link.method && link.href
|
62
|
+
Link.new(link)
|
63
|
+
end
|
64
|
+
end.compact
|
53
65
|
end
|
54
66
|
end
|
55
67
|
end
|
data/lib/jdoc/schema.rb
CHANGED
@@ -2,25 +2,16 @@ module Jdoc
|
|
2
2
|
class Schema
|
3
3
|
DEFAULT_ENDPOINT = "https://api.example.com"
|
4
4
|
|
5
|
-
# Recursively extracts all links in given JSON schema
|
6
|
-
# @param json_schema [JsonSchema::Schema]
|
7
|
-
# @return [Array] An array of JsonSchema::Schema::Link
|
8
|
-
def self.extract_links(json_schema)
|
9
|
-
links = json_schema.links.select {|link| link.method && link.href }
|
10
|
-
links + json_schema.properties.map {|key, schema| extract_links(schema) }.flatten
|
11
|
-
end
|
12
|
-
|
13
5
|
# @param schema [Hash] JSON Schema
|
14
6
|
def initialize(schema)
|
15
7
|
@json_schema = JsonSchema.parse!(schema).tap(&:expand_references!)
|
16
8
|
end
|
17
9
|
|
18
|
-
# @return [
|
19
|
-
def
|
20
|
-
@
|
21
|
-
|
22
|
-
|
23
|
-
end
|
10
|
+
# @return [Array<Jdoc::Resource>] All top-level properties in its title order
|
11
|
+
def resources
|
12
|
+
@resources ||= @json_schema.properties.map do |key, property|
|
13
|
+
Resource.new(property)
|
14
|
+
end.sort
|
24
15
|
end
|
25
16
|
|
26
17
|
# @return [String, nil] Title property of this schema
|
@@ -56,15 +47,6 @@ module Jdoc
|
|
56
47
|
root_uri.host
|
57
48
|
end
|
58
49
|
|
59
|
-
# @return [Array] All links defined in given JSON schema
|
60
|
-
# @example
|
61
|
-
# links #=> [#<JsonSchema::Schema::Link>]
|
62
|
-
def links
|
63
|
-
@links ||= self.class.extract_links(@json_schema).map do |link|
|
64
|
-
Link.new(link: link)
|
65
|
-
end.sort
|
66
|
-
end
|
67
|
-
|
68
50
|
# @return [URI::Generic] Root endpoint for the API
|
69
51
|
# @example
|
70
52
|
# root_uri #=> "https://api.example.com"
|
data/lib/jdoc/version.rb
CHANGED
data/spec/fixtures/schema.yml
CHANGED
data/spec/jdoc/generator_spec.rb
CHANGED
@@ -20,11 +20,12 @@ describe Jdoc::Generator do
|
|
20
20
|
should == <<-EOS.strip_heredoc
|
21
21
|
# Example API
|
22
22
|
* [App](#app)
|
23
|
-
* [GET /apps](#get-apps)
|
24
23
|
* [POST /apps](#post-apps)
|
24
|
+
* [DELETE /apps/:id](#delete-appsid)
|
25
25
|
* [GET /apps/:id](#get-appsid)
|
26
|
+
* [GET /apps](#get-apps)
|
26
27
|
* [PATCH /apps/:id](#patch-appsid)
|
27
|
-
|
28
|
+
* [User](#user)
|
28
29
|
|
29
30
|
## App
|
30
31
|
An app is a program to be deployed.
|
@@ -48,21 +49,15 @@ describe Jdoc::Generator do
|
|
48
49
|
* users -
|
49
50
|
* Type: array
|
50
51
|
|
51
|
-
###
|
52
|
-
|
52
|
+
### POST /apps
|
53
|
+
Create a new app.
|
53
54
|
|
54
55
|
```
|
55
|
-
|
56
|
+
POST /apps HTTP/1.1
|
56
57
|
Content-Type: application/json
|
57
58
|
Host: api.example.com
|
58
|
-
```
|
59
|
-
|
60
|
-
```
|
61
|
-
HTTP/1.1 200
|
62
|
-
Content-Type: application/json
|
63
59
|
|
64
60
|
{
|
65
|
-
"id": "01234567-89ab-cdef-0123-456789abcdef",
|
66
61
|
"name": "example",
|
67
62
|
"private": false,
|
68
63
|
"deleted_at": null,
|
@@ -72,15 +67,12 @@ describe Jdoc::Generator do
|
|
72
67
|
}
|
73
68
|
```
|
74
69
|
|
75
|
-
### POST /apps
|
76
|
-
Create a new app.
|
77
|
-
|
78
70
|
```
|
79
|
-
|
71
|
+
HTTP/1.1 201
|
80
72
|
Content-Type: application/json
|
81
|
-
Host: api.example.com
|
82
73
|
|
83
74
|
{
|
75
|
+
"id": "01234567-89ab-cdef-0123-456789abcdef",
|
84
76
|
"name": "example",
|
85
77
|
"private": false,
|
86
78
|
"deleted_at": null,
|
@@ -90,8 +82,17 @@ describe Jdoc::Generator do
|
|
90
82
|
}
|
91
83
|
```
|
92
84
|
|
85
|
+
### DELETE /apps/:id
|
86
|
+
Delete an existing app.
|
87
|
+
|
93
88
|
```
|
94
|
-
HTTP/1.1
|
89
|
+
DELETE /apps/:id HTTP/1.1
|
90
|
+
Content-Type: application/json
|
91
|
+
Host: api.example.com
|
92
|
+
```
|
93
|
+
|
94
|
+
```
|
95
|
+
HTTP/1.1 200
|
95
96
|
Content-Type: application/json
|
96
97
|
|
97
98
|
{
|
@@ -129,15 +130,21 @@ describe Jdoc::Generator do
|
|
129
130
|
}
|
130
131
|
```
|
131
132
|
|
132
|
-
###
|
133
|
-
|
133
|
+
### GET /apps
|
134
|
+
List existing apps.
|
134
135
|
|
135
136
|
```
|
136
|
-
|
137
|
+
GET /apps HTTP/1.1
|
137
138
|
Content-Type: application/json
|
138
139
|
Host: api.example.com
|
140
|
+
```
|
141
|
+
|
142
|
+
```
|
143
|
+
HTTP/1.1 200
|
144
|
+
Content-Type: application/json
|
139
145
|
|
140
146
|
{
|
147
|
+
"id": "01234567-89ab-cdef-0123-456789abcdef",
|
141
148
|
"name": "example",
|
142
149
|
"private": false,
|
143
150
|
"deleted_at": null,
|
@@ -147,12 +154,15 @@ describe Jdoc::Generator do
|
|
147
154
|
}
|
148
155
|
```
|
149
156
|
|
157
|
+
### PATCH /apps/:id
|
158
|
+
Update an existing app.
|
159
|
+
|
150
160
|
```
|
151
|
-
HTTP/1.1
|
161
|
+
PATCH /apps/:id HTTP/1.1
|
152
162
|
Content-Type: application/json
|
163
|
+
Host: api.example.com
|
153
164
|
|
154
165
|
{
|
155
|
-
"id": "01234567-89ab-cdef-0123-456789abcdef",
|
156
166
|
"name": "example",
|
157
167
|
"private": false,
|
158
168
|
"deleted_at": null,
|
@@ -162,15 +172,6 @@ describe Jdoc::Generator do
|
|
162
172
|
}
|
163
173
|
```
|
164
174
|
|
165
|
-
### DELETE /apps/:id
|
166
|
-
Delete an existing app.
|
167
|
-
|
168
|
-
```
|
169
|
-
DELETE /apps/:id HTTP/1.1
|
170
|
-
Content-Type: application/json
|
171
|
-
Host: api.example.com
|
172
|
-
```
|
173
|
-
|
174
175
|
```
|
175
176
|
HTTP/1.1 200
|
176
177
|
Content-Type: application/json
|
@@ -186,6 +187,14 @@ describe Jdoc::Generator do
|
|
186
187
|
}
|
187
188
|
```
|
188
189
|
|
190
|
+
## User
|
191
|
+
|
192
|
+
|
193
|
+
### Properties
|
194
|
+
* name -
|
195
|
+
* Example: `"alice"`
|
196
|
+
* Type: string
|
197
|
+
|
189
198
|
EOS
|
190
199
|
end
|
191
200
|
end
|
data/template.md.erb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# <%= schema.title %>
|
2
|
-
<% schema.
|
2
|
+
<% schema.resources.each do |resource| %>
|
3
3
|
* <%= resource.hyperlink %>
|
4
|
-
<% links.each do |link| %>
|
4
|
+
<% resource.links.each do |link| %>
|
5
5
|
* <%= link.hyperlink %>
|
6
6
|
<% end %>
|
7
7
|
<% end %>
|
8
8
|
|
9
|
-
<% schema.
|
9
|
+
<% schema.resources.each do |resource| %>
|
10
10
|
## <%= resource.title %>
|
11
11
|
<%= resource.description %>
|
12
12
|
|
@@ -18,7 +18,7 @@
|
|
18
18
|
<% end %>
|
19
19
|
<% end %>
|
20
20
|
|
21
|
-
<% links.each do |link| %>
|
21
|
+
<% resource.links.each do |link| %>
|
22
22
|
### <%= link.endpoint %>
|
23
23
|
<%= link.description %>
|
24
24
|
|