discoverydoc 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +21 -0
- data/LICENSE +22 -0
- data/README.md +103 -0
- data/bin/discoverydoc +7 -0
- data/discoverydoc.gemspec +14 -0
- data/lib/discovery_doc/discovery_doc.rb +159 -0
- data/spec/discovery-1.0.0.yml +100 -0
- data/spec/sample-1.0.0.yml +36 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d51024b7e141eee992dd64b1021008e3d12b267e
|
4
|
+
data.tar.gz: fb149b32b39e8d4ac1cd992d23b2775eaa96f799
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2746d3e1357bd86aa4aa40f82e704bdf12f2cc605e05402c6dff8df15354841fb19af19ef94fa4d5f93d57512bf34d27b466bd04db77252d7920f105e6c3d53a
|
7
|
+
data.tar.gz: f7fd8303ba768cad52a50afac01bdb7a2e2c6720dc22211af0a7531ba28ff708753fdbbbdc3c5a2e5b81de8010df50deea6dd3a5619c00d52e3702bf24d2a8cf
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gem "rspec"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
GEM
|
2
|
+
specs:
|
3
|
+
diff-lcs (1.2.5)
|
4
|
+
rspec (3.1.0)
|
5
|
+
rspec-core (~> 3.1.0)
|
6
|
+
rspec-expectations (~> 3.1.0)
|
7
|
+
rspec-mocks (~> 3.1.0)
|
8
|
+
rspec-core (3.1.7)
|
9
|
+
rspec-support (~> 3.1.0)
|
10
|
+
rspec-expectations (3.1.2)
|
11
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
12
|
+
rspec-support (~> 3.1.0)
|
13
|
+
rspec-mocks (3.1.3)
|
14
|
+
rspec-support (~> 3.1.0)
|
15
|
+
rspec-support (3.1.2)
|
16
|
+
|
17
|
+
PLATFORMS
|
18
|
+
ruby
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 kaiinui
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
discoverydoc
|
2
|
+
============
|
3
|
+
|
4
|
+
Generate markdown document from discovery file.
|
5
|
+
|
6
|
+
From following YAML Dicovery file,
|
7
|
+
|
8
|
+
```yaml
|
9
|
+
service:
|
10
|
+
name: BookService
|
11
|
+
id: com.example.book_service
|
12
|
+
base_url: http://example.com/book_service/api
|
13
|
+
|
14
|
+
endpoint:
|
15
|
+
ListBook:
|
16
|
+
path: GET /books
|
17
|
+
response: [Book]
|
18
|
+
GetBook:
|
19
|
+
path: GET /books/{id}
|
20
|
+
response: Book
|
21
|
+
PostBook:
|
22
|
+
path: POST /books
|
23
|
+
body: Book
|
24
|
+
response: Book
|
25
|
+
PatchBook:
|
26
|
+
path: PATCH /books/{id}
|
27
|
+
body: Book
|
28
|
+
response: Book
|
29
|
+
SearchBook:
|
30
|
+
path: GET /books/search
|
31
|
+
params:
|
32
|
+
query: String
|
33
|
+
response: [Book]
|
34
|
+
|
35
|
+
entity:
|
36
|
+
Book:
|
37
|
+
title: String
|
38
|
+
author_name: String
|
39
|
+
published_at: Date
|
40
|
+
|
41
|
+
error:
|
42
|
+
id: String
|
43
|
+
message: String
|
44
|
+
url: String
|
45
|
+
```
|
46
|
+
|
47
|
+
Following markdown documentation is generated.
|
48
|
+
|
49
|
+
---
|
50
|
+
|
51
|
+
## BookService Service
|
52
|
+
|
53
|
+
### Base URL
|
54
|
+
|
55
|
+
http://example.com/book_service/api
|
56
|
+
|
57
|
+
## Endpoint
|
58
|
+
|
59
|
+
### `GET /books` (ListBook)
|
60
|
+
|
61
|
+
#### Response
|
62
|
+
|
63
|
+
[Array(Book)](#book)
|
64
|
+
|
65
|
+
### `GET /books/{id}` (GetBook)
|
66
|
+
|
67
|
+
#### Response
|
68
|
+
|
69
|
+
[Book](#book)
|
70
|
+
|
71
|
+
### `POST /books` (PostBook)
|
72
|
+
|
73
|
+
#### Response
|
74
|
+
|
75
|
+
[Book](#book)
|
76
|
+
|
77
|
+
### `PATCH /books/{id}` (PatchBook)
|
78
|
+
|
79
|
+
#### Response
|
80
|
+
|
81
|
+
[Book](#book)
|
82
|
+
|
83
|
+
### `GET /books/search` (SearchBook)
|
84
|
+
|
85
|
+
#### Parameters
|
86
|
+
|
87
|
+
|Field|Type|
|
88
|
+
|-----|----|
|
89
|
+
|query|`String`|
|
90
|
+
|
91
|
+
#### Response
|
92
|
+
|
93
|
+
[Array(Book)](#book)
|
94
|
+
|
95
|
+
## Entity
|
96
|
+
|
97
|
+
### Book
|
98
|
+
|
99
|
+
|Field|Type|
|
100
|
+
|-----|----|
|
101
|
+
|title|`String`|
|
102
|
+
|author_name|`String`|
|
103
|
+
|published_at|`Date`|
|
data/bin/discoverydoc
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'discoverydoc'
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.summary = 'Generates Markdown documentation from YAML discovery file.'
|
5
|
+
s.author = 'Kai INUI'
|
6
|
+
s.email = 'lied.der.optik@gmail.com'
|
7
|
+
s.homepage = 'https://github.com/kaiinui/discoverydoc'
|
8
|
+
s.files = `git ls-files`.split("\n")
|
9
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
10
|
+
s.license = 'MIT'
|
11
|
+
s.executables << 'discoverydoc'
|
12
|
+
|
13
|
+
s.add_development_dependency 'rspec'
|
14
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module DiscoveryDoc
|
4
|
+
class DocBuilder
|
5
|
+
## Returns Markdown document from a file that specified by given filepath.
|
6
|
+
##
|
7
|
+
## @param filepath [String] File path to a discovery file.
|
8
|
+
## @return String
|
9
|
+
def from_file(filepath)
|
10
|
+
discovery = YAML.load_file(filepath)
|
11
|
+
parse(discovery)
|
12
|
+
end
|
13
|
+
|
14
|
+
## Returns built Markdown document.
|
15
|
+
##
|
16
|
+
## @param discovery [Hash]
|
17
|
+
## @return String
|
18
|
+
def parse(discovery)
|
19
|
+
doc = ""
|
20
|
+
doc << parse_service(discovery["service"])
|
21
|
+
doc << parse_endpoints(discovery["endpoint"])
|
22
|
+
doc << parse_entities(discovery["entity"])
|
23
|
+
doc
|
24
|
+
end
|
25
|
+
|
26
|
+
## Working with Service
|
27
|
+
|
28
|
+
def parse_service(service)
|
29
|
+
name = service["name"]
|
30
|
+
base_url = service["base_url"]
|
31
|
+
|
32
|
+
doc = ""
|
33
|
+
|
34
|
+
doc << "## #{name} Service \n\n"
|
35
|
+
|
36
|
+
doc << "### Base URL \n\n"
|
37
|
+
|
38
|
+
doc << base_url
|
39
|
+
|
40
|
+
doc << "\n\n"
|
41
|
+
|
42
|
+
doc
|
43
|
+
end
|
44
|
+
|
45
|
+
## Working with Entity
|
46
|
+
|
47
|
+
def parse_entities(entities)
|
48
|
+
doc = ""
|
49
|
+
|
50
|
+
doc << "## Entity\n\n"
|
51
|
+
|
52
|
+
entities.each do |name, entity|
|
53
|
+
doc << "### #{name} \n\n"
|
54
|
+
|
55
|
+
doc << table_from_field_type_hash(entity)
|
56
|
+
end
|
57
|
+
|
58
|
+
doc
|
59
|
+
end
|
60
|
+
|
61
|
+
## Working with Endpoint
|
62
|
+
|
63
|
+
## @param endpoints [Hash]
|
64
|
+
def parse_endpoints(endpoints)
|
65
|
+
doc = ""
|
66
|
+
doc << "## Endpoint\n\n"
|
67
|
+
|
68
|
+
endpoints.each do |name, endpoint|
|
69
|
+
doc << parse_endpoint(name, endpoint)
|
70
|
+
end
|
71
|
+
|
72
|
+
doc
|
73
|
+
end
|
74
|
+
|
75
|
+
## @param name [String] Endpoint's name
|
76
|
+
## @param endpoint [Hash]
|
77
|
+
## @return String
|
78
|
+
def parse_endpoint(name, endpoint)
|
79
|
+
doc = ""
|
80
|
+
path = endpoint["path"]
|
81
|
+
parameters = endpoint["params"]
|
82
|
+
response = endpoint["response"]
|
83
|
+
content_type = endpoint["content_type"]
|
84
|
+
|
85
|
+
doc << "### `#{path}` (#{name}) \n\n"
|
86
|
+
|
87
|
+
if content_type
|
88
|
+
doc << "Content-Type: #{content_type}\n\n"
|
89
|
+
end
|
90
|
+
doc << parse_parameters(parameters)
|
91
|
+
|
92
|
+
doc << parse_response(response)
|
93
|
+
|
94
|
+
doc
|
95
|
+
end
|
96
|
+
|
97
|
+
## @param parameters [Hash]
|
98
|
+
def parse_parameters(parameters)
|
99
|
+
return "" unless parameters
|
100
|
+
|
101
|
+
doc = ""
|
102
|
+
doc << "#### Parameters \n\n"
|
103
|
+
|
104
|
+
if parameters.is_a?(String) or parameters.is_a?(Array)
|
105
|
+
doc << link_to_entity(parameters)
|
106
|
+
elsif parameters.is_a?(Hash)
|
107
|
+
doc << table_from_field_type_hash(parameters)
|
108
|
+
end
|
109
|
+
|
110
|
+
doc
|
111
|
+
end
|
112
|
+
|
113
|
+
## @param response [String|Hash|Array]
|
114
|
+
def parse_response(response)
|
115
|
+
doc = ""
|
116
|
+
|
117
|
+
doc << "#### Response \n\n"
|
118
|
+
|
119
|
+
if response.is_a?(String)
|
120
|
+
doc << "[#{response}](##{response.downcase})\n\n"
|
121
|
+
elsif response.is_a?(Array)
|
122
|
+
doc << "[Array<#{response[0]}>](##{response[0].downcase})\n\n"
|
123
|
+
else
|
124
|
+
doc << table_from_field_type_hash(response)
|
125
|
+
end
|
126
|
+
|
127
|
+
doc
|
128
|
+
end
|
129
|
+
|
130
|
+
## Helpers (Working with Markdown)
|
131
|
+
|
132
|
+
|
133
|
+
## @param entity [String|Array]
|
134
|
+
def link_to_entity(entity)
|
135
|
+
if entity.is_a?(String)
|
136
|
+
"[#{entity}](##{entity.downcase})"
|
137
|
+
elsif entity.is_a?(Array)
|
138
|
+
"[Array(#{entity[0]})](##{entity[0].downcase})"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
## Returns table markdown with Field to Type hash.
|
143
|
+
##
|
144
|
+
## @param field_type_hash [Hash]
|
145
|
+
## @return String
|
146
|
+
def table_from_field_type_hash(field_type_hash)
|
147
|
+
doc = ""
|
148
|
+
doc << "|Field|Type|\n"
|
149
|
+
doc << "|-----|----|\n"
|
150
|
+
field_type_hash.each do |field, type|
|
151
|
+
type = "Array<#{type[0]}>" if type.is_a?(Array) ## For [Entity] literal.
|
152
|
+
doc << "|#{field}|`#{type}`|\n"
|
153
|
+
end
|
154
|
+
doc << "\n"
|
155
|
+
|
156
|
+
doc
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
service:
|
2
|
+
name: FilmAPI
|
3
|
+
id: net.filmapp.api
|
4
|
+
base_url: https://filmappapi.appspot.com
|
5
|
+
|
6
|
+
endpoint:
|
7
|
+
### Deltas API ###
|
8
|
+
GetDeltas:
|
9
|
+
path: GET /deltas
|
10
|
+
params:
|
11
|
+
ust: Integer
|
12
|
+
device_token: String
|
13
|
+
response: DeltaPack
|
14
|
+
PostDeltas:
|
15
|
+
path: POST /deltas
|
16
|
+
body: DeltaPack
|
17
|
+
response:
|
18
|
+
id: String
|
19
|
+
message: String
|
20
|
+
|
21
|
+
### Photo Upload API ###
|
22
|
+
UploadPhoto:
|
23
|
+
path: POST /upload/photos/{gid}
|
24
|
+
content_type: multipart/form-data
|
25
|
+
params:
|
26
|
+
image: Image
|
27
|
+
response: PhotoUploadResponse
|
28
|
+
|
29
|
+
### Entity API ###
|
30
|
+
GetPhoto:
|
31
|
+
path: GET /photos/{gid}
|
32
|
+
response: Photo
|
33
|
+
GetMultiplePhotos:
|
34
|
+
path: GET /photos/{comma_separated_gids}
|
35
|
+
response: [Photo]
|
36
|
+
GetAlbum:
|
37
|
+
path: GET /albums/{gid}
|
38
|
+
response: Album
|
39
|
+
|
40
|
+
entity:
|
41
|
+
DeltaPack:
|
42
|
+
_id: String
|
43
|
+
_ust: Integer
|
44
|
+
Photo: [Photo]
|
45
|
+
Album: [Album]
|
46
|
+
Photo:
|
47
|
+
gid: Key
|
48
|
+
localIdentifier: String
|
49
|
+
assetURL: String
|
50
|
+
albumIdentifier: String
|
51
|
+
burstIdentifier: String
|
52
|
+
collectionIdentifier: String
|
53
|
+
mediaType: Integer
|
54
|
+
mediaSubType: Integer
|
55
|
+
pixelWidth: Integer
|
56
|
+
pixelHeight: Integer
|
57
|
+
duration: Integer
|
58
|
+
latitude: Double
|
59
|
+
longitude: Double
|
60
|
+
hasUploaded: Boolean
|
61
|
+
remoteImageURL: String
|
62
|
+
aq_gid: String
|
63
|
+
aq_deviceToken: String
|
64
|
+
aq_localTimestamp: Long
|
65
|
+
aq_idDeleted: Boolean
|
66
|
+
aq_ust: Long
|
67
|
+
creationTimestamp: Long
|
68
|
+
modificationTimestamp: Long
|
69
|
+
Album:
|
70
|
+
gid: Key
|
71
|
+
assetsGroupURL: String
|
72
|
+
localIdentifier: String
|
73
|
+
headerPhotoIdentifier: String
|
74
|
+
title: String
|
75
|
+
tintColorHex: String
|
76
|
+
backgroundColorHex: String
|
77
|
+
themeColorHex: String
|
78
|
+
layoutThemeIdentifier: String
|
79
|
+
themeIdentifier: String
|
80
|
+
aq_gid: String
|
81
|
+
aq_deviceToken: String
|
82
|
+
aq_localTimestamp: Long
|
83
|
+
aq_idDeleted: Boolean
|
84
|
+
aq_ust: Long
|
85
|
+
latestPhotoCreationTimestamp: Long
|
86
|
+
creationTimestamp: Long
|
87
|
+
modificationTimestamp: Long
|
88
|
+
User:
|
89
|
+
userToken: String
|
90
|
+
secretKey: String
|
91
|
+
Device:
|
92
|
+
deviceToken: String
|
93
|
+
secretKey: String
|
94
|
+
PhotoUploadResponse:
|
95
|
+
id: String
|
96
|
+
image_url: String
|
97
|
+
|
98
|
+
error:
|
99
|
+
id: String
|
100
|
+
message: String
|
@@ -0,0 +1,36 @@
|
|
1
|
+
service:
|
2
|
+
name: BookService
|
3
|
+
id: com.example.book_service
|
4
|
+
base_url: http://example.com/book_service/api
|
5
|
+
|
6
|
+
endpoint:
|
7
|
+
ListBook:
|
8
|
+
path: GET /books
|
9
|
+
response: [Book]
|
10
|
+
GetBook:
|
11
|
+
path: GET /books/{id}
|
12
|
+
response: Book
|
13
|
+
PostBook:
|
14
|
+
path: POST /books
|
15
|
+
body: Book
|
16
|
+
response: Book
|
17
|
+
PatchBook:
|
18
|
+
path: PATCH /books/{id}
|
19
|
+
body: Book
|
20
|
+
response: Book
|
21
|
+
SearchBook:
|
22
|
+
path: GET /books/search
|
23
|
+
params:
|
24
|
+
query: String
|
25
|
+
response: [Book]
|
26
|
+
|
27
|
+
entity:
|
28
|
+
Book:
|
29
|
+
title: String
|
30
|
+
author_name: String
|
31
|
+
published_at: Date
|
32
|
+
|
33
|
+
error:
|
34
|
+
id: String
|
35
|
+
message: String
|
36
|
+
url: String
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: discoverydoc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kai INUI
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email: lied.der.optik@gmail.com
|
29
|
+
executables:
|
30
|
+
- discoverydoc
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
37
|
+
- LICENSE
|
38
|
+
- README.md
|
39
|
+
- bin/discoverydoc
|
40
|
+
- discoverydoc.gemspec
|
41
|
+
- lib/discovery_doc/discovery_doc.rb
|
42
|
+
- spec/discovery-1.0.0.yml
|
43
|
+
- spec/sample-1.0.0.yml
|
44
|
+
homepage: https://github.com/kaiinui/discoverydoc
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata: {}
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 2.2.2
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: Generates Markdown documentation from YAML discovery file.
|
68
|
+
test_files:
|
69
|
+
- spec/discovery-1.0.0.yml
|
70
|
+
- spec/sample-1.0.0.yml
|
71
|
+
has_rdoc:
|