jdoc 0.0.9 → 0.1.0

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: 44f0091a8a36bc9270c3c13de5553c51051b1261
4
- data.tar.gz: 69173ed695ea55d08826cefe5c43eff342b81c07
3
+ metadata.gz: ecaf31b4e9cc6005cf7980e77b5f8967a9d1e4a1
4
+ data.tar.gz: 449ee41071bbf4467556d1150418f32bf686b530
5
5
  SHA512:
6
- metadata.gz: ed1792568d15ba8d43ea696b417ed3d009a241d8ab4c0c194b9d6794d1bf4007712ab766167097c90f6597daa1d0a7b400b571418173bbc7ff526a8be47acc78
7
- data.tar.gz: 71dc0edef70729432ecdfd651b2552ed057d4760f72b1c4ec84833b2cc7bde3d2d7224f70a56c4c63a5ed453e63e5295424e4b86bd072c2c3717ad77fbfa9af5
6
+ metadata.gz: 6f1bc864b397b9c4bd30ff0a936a5856e2a965d47773a195a91c00267e807231872831b85f4cef362578fce891dfdd00b3bc82312a58c924cd5070fbfb8419cd
7
+ data.tar.gz: f1788851e9708e9ffc34eb8a8adafc3775f63c1eb789da355e0035a4ae33047e810c9932e22487b7fa073a4900d3e6f2e17f3571193556b7f11147b13c694ef6
@@ -1,3 +1,6 @@
1
+ ## 0.1.0
2
+ * Show resources which have no links
3
+
1
4
  ## 0.0.9
2
5
  * Support array property
3
6
 
@@ -1,7 +1,7 @@
1
1
  module Jdoc
2
2
  class Link
3
3
  # @param link [JsonSchema::Schema::Link]
4
- def initialize(link: nil)
4
+ def initialize(link)
5
5
  @raw_link = link
6
6
  end
7
7
 
@@ -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 == @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
@@ -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 [Hash{Jdoc::Schema => Array}] Linkes table indexed by their schemata
19
- def links_indexed_by_resource
20
- @links_indexed_by_schema ||= links.inject(Hash.new {|h, k| h[k] = [] }) do |result, link|
21
- result[link.resource] << link
22
- result
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"
@@ -1,3 +1,3 @@
1
1
  module Jdoc
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -99,6 +99,8 @@ definitions:
99
99
  properties:
100
100
  app:
101
101
  "$ref": "#/definitions/app"
102
+ user:
103
+ "$ref": "#/definitions/user"
102
104
  type:
103
105
  - object
104
106
  description: A schema for a small example API.
@@ -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
- * [DELETE /apps/:id](#delete-appsid)
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
- ### GET /apps
52
- List existing apps.
52
+ ### POST /apps
53
+ Create a new app.
53
54
 
54
55
  ```
55
- GET /apps HTTP/1.1
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
- POST /apps HTTP/1.1
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 201
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
- ### PATCH /apps/:id
133
- Update an existing app.
133
+ ### GET /apps
134
+ List existing apps.
134
135
 
135
136
  ```
136
- PATCH /apps/:id HTTP/1.1
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 200
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
@@ -1,12 +1,12 @@
1
1
  # <%= schema.title %>
2
- <% schema.links_indexed_by_resource.each do |resource, links| %>
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.links_indexed_by_resource.each do |resource, links| %>
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura