dictum 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +70 -0
- data/.rspec +1 -0
- data/.rubocop.yml +12 -0
- data/.travis.yml +33 -0
- data/Gemfile +11 -0
- data/LICENSE.md +21 -0
- data/README.md +181 -0
- data/Rakefile +1 -0
- data/TODO.md +7 -0
- data/dictum.gemspec +26 -0
- data/lib/dictum.rb +73 -0
- data/lib/dictum/documenter.rb +59 -0
- data/lib/dictum/markdown_writer.rb +73 -0
- data/lib/dictum/version.rb +3 -0
- data/lib/tasks/dictum.rake +8 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d6c5ff3c6e60436b079a7686e5ac902c0667dd16
|
4
|
+
data.tar.gz: 1e01d5c17f6c352d49f3b701dc6f574ad5bbad81
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5d10b7d5b8a4f91682e0a40424bae391b1c12269e6b4b6080d90cb73ebe9e8ec62a26529b2e002df6b8f189d2fa5317f76db87d67fdbb1176d578cd4842512c5
|
7
|
+
data.tar.gz: af6203c9ea677dca51c9fbf1fe14b7dc451d36ef3c745a51f795ce7d209c603a1df1f0198dfa150b24254734956e7858720486e5350b672197b20aa301a84c0b
|
data/.gitignore
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Created by https://www.gitignore.io/api/ruby,osx
|
2
|
+
|
3
|
+
*.log
|
4
|
+
.byebug_history
|
5
|
+
/spec/test_files
|
6
|
+
*.test
|
7
|
+
|
8
|
+
### Ruby ###
|
9
|
+
*.gem
|
10
|
+
*.rbc
|
11
|
+
/.config
|
12
|
+
/coverage/
|
13
|
+
/InstalledFiles
|
14
|
+
/pkg/
|
15
|
+
/spec/reports/
|
16
|
+
/spec/examples.txt
|
17
|
+
/test/tmp/
|
18
|
+
/test/version_tmp/
|
19
|
+
/tmp/
|
20
|
+
|
21
|
+
## Specific to RubyMotion:
|
22
|
+
.dat*
|
23
|
+
.repl_history
|
24
|
+
build/
|
25
|
+
|
26
|
+
## Documentation cache and generated files:
|
27
|
+
/.yardoc/
|
28
|
+
/_yardoc/
|
29
|
+
/doc/
|
30
|
+
/rdoc/
|
31
|
+
|
32
|
+
## Environment normalisation:
|
33
|
+
/.bundle/
|
34
|
+
/vendor/bundle
|
35
|
+
/lib/bundler/man/
|
36
|
+
|
37
|
+
# for a library or gem, you might want to ignore these files since the code is
|
38
|
+
# intended to run in multiple environments; otherwise, check them in:
|
39
|
+
Gemfile.lock
|
40
|
+
.ruby-version
|
41
|
+
.ruby-gemset
|
42
|
+
|
43
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
44
|
+
.rvmrc
|
45
|
+
|
46
|
+
### OSX ###
|
47
|
+
.DS_Store
|
48
|
+
.AppleDouble
|
49
|
+
.LSOverride
|
50
|
+
|
51
|
+
# Icon must end with two \r
|
52
|
+
Icon
|
53
|
+
|
54
|
+
# Thumbnails
|
55
|
+
._*
|
56
|
+
|
57
|
+
# Files that might appear in the root of a volume
|
58
|
+
.DocumentRevisions-V100
|
59
|
+
.fseventsd
|
60
|
+
.Spotlight-V100
|
61
|
+
.TemporaryItems
|
62
|
+
.Trashes
|
63
|
+
.VolumeIcon.icns
|
64
|
+
|
65
|
+
# Directories potentially created on remote AFP share
|
66
|
+
.AppleDB
|
67
|
+
.AppleDesktop
|
68
|
+
Network Trash Folder
|
69
|
+
Temporary Items
|
70
|
+
.apdisk
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1
|
6
|
+
- 2.2
|
7
|
+
- 2.2.4
|
8
|
+
- 2.3.0
|
9
|
+
|
10
|
+
install:
|
11
|
+
- gem install bundler
|
12
|
+
- bundle install --retry=3
|
13
|
+
|
14
|
+
script:
|
15
|
+
- bundle exec rspec
|
16
|
+
- bundle exec rubocop -R --format simple
|
17
|
+
|
18
|
+
addons:
|
19
|
+
code_climate:
|
20
|
+
repo_token: 18ae4433a073ee0e00127ab95c826ac5552d3b14d712aa70a231e9e3903f84d5
|
21
|
+
|
22
|
+
os:
|
23
|
+
- linux
|
24
|
+
- osx
|
25
|
+
|
26
|
+
matrix:
|
27
|
+
exclude:
|
28
|
+
- rvm: 2.2
|
29
|
+
os: osx
|
30
|
+
- rvm: 2.2.4
|
31
|
+
os: osx
|
32
|
+
- rvm: 2.3.0
|
33
|
+
os: osx
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Alejandro Bezdjian, aka alebian
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
# Dictum - Document your Rails APIs
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/dictum.svg)](https://badge.fury.io/rb/dictum)
|
3
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/alebian/dictum.svg)](https://gemnasium.com/github.com/alebian/dictum)
|
4
|
+
[![Build Status](https://travis-ci.org/alebian/dictum.svg)](https://travis-ci.org/alebian/dictum)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/alebian/dictum/badges/gpa.svg)](https://codeclimate.com/github/alebian/dictum)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/alebian/dictum/badges/coverage.svg)](https://codeclimate.com/github/alebian/dictum/coverage)
|
7
|
+
[![Issue Count](https://codeclimate.com/github/alebian/dictum/badges/issue_count.svg)](https://codeclimate.com/github/alebian/dictum)
|
8
|
+
[![Inline docs](http://inch-ci.org/github/alebian/dictum.svg)](http://inch-ci.org/github/alebian/dictum)
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'dictum'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle install
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install dictum
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
First you need to set a configuration file inside /config/initializers/dictum.rb
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
Dictum.configure do |config|
|
32
|
+
config.output_path = Rails.root.join('docs')
|
33
|
+
config.root_path = Rails.root
|
34
|
+
config.output_filename = 'Documentation'
|
35
|
+
# config.output_format = :markdown
|
36
|
+
# test_suite = :rspec
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
Then you can use Dictum in the most verbose and fully customizable way like this in your tests:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require 'rails_helper'
|
44
|
+
|
45
|
+
describe V1::MyResourceController do
|
46
|
+
Dictum.resource(
|
47
|
+
name: 'MyResource',
|
48
|
+
description: 'This is MyResource description.'
|
49
|
+
)
|
50
|
+
|
51
|
+
describe '#some_method' do
|
52
|
+
context 'some context for my resource' do
|
53
|
+
it 'returns status ok' do
|
54
|
+
get :index
|
55
|
+
Dictum.endpoint(
|
56
|
+
resource: 'MyResource',
|
57
|
+
endpoint: '/api/v1/my_resource/:id',
|
58
|
+
http_verb: 'POST',
|
59
|
+
description: 'Some description of the endpoint.',
|
60
|
+
request_headers: { 'AUTHORIZATION' => 'user_token',
|
61
|
+
'Content-Type' => 'application/json',
|
62
|
+
'Accept' => 'application/json' },
|
63
|
+
request_path_parameters: { id: 1, page: 1 },
|
64
|
+
request_body_parameters: { some: 'parameter' },
|
65
|
+
response_headers: { 'some_header' => 'some_header_value' },
|
66
|
+
response_status: response.status,
|
67
|
+
response_body: response_body
|
68
|
+
)
|
69
|
+
expect(response_status).to eq(200)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
75
|
+
Most parameters are not mandatory, and as you can see, writing all of these for each endpoint can add a lot of unnecessary boilerplate. But since you know everything the method receives you can customize the usage anyway you like, for example:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
require 'rails_helper'
|
79
|
+
|
80
|
+
describe V1::MyResourceController do
|
81
|
+
Dictum.resource(
|
82
|
+
name: 'MyResource',
|
83
|
+
description: 'This is MyResource description.'
|
84
|
+
)
|
85
|
+
|
86
|
+
after(:each) do |test|
|
87
|
+
if test.metadata[:dictum]
|
88
|
+
Dictum.endpoint(
|
89
|
+
resource: test.metadata[:described_class].to_s.gsub('V1::', '').gsub('Controller', ''),
|
90
|
+
endpoint: request.fullpath,
|
91
|
+
http_verb: request.env['REQUEST_METHOD'],
|
92
|
+
description: test.metadata[:dictum_description],
|
93
|
+
request_headers: { 'AUTHORIZATION' => 'user_token',
|
94
|
+
'Content-Type' => 'application/json',
|
95
|
+
'Accept' => 'application/json' },
|
96
|
+
request_path_parameters: request.env['action_dispatch.request.path_parameters'].except(:controller, :action),
|
97
|
+
request_body_parameters: request.env['action_dispatch.request.parameters'].except('controller', 'action'),
|
98
|
+
response_headers: response.headers,
|
99
|
+
response_status: response.status,
|
100
|
+
response_body: response_body
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#some_method' do
|
105
|
+
context 'some context for my resource' do
|
106
|
+
it 'returns status ok', dictum: true, dictum_description: 'Some description of the endpoint.' do
|
107
|
+
get :index
|
108
|
+
expect(response_status).to eq(200)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
115
|
+
Then execute:
|
116
|
+
|
117
|
+
$ bundle exec dictum
|
118
|
+
|
119
|
+
Both ways Dictum will create a document like this:
|
120
|
+
|
121
|
+
# Index
|
122
|
+
- MyResource
|
123
|
+
|
124
|
+
# MyResource
|
125
|
+
This is MyResource description.
|
126
|
+
|
127
|
+
## GET /api/v1/my_resource
|
128
|
+
|
129
|
+
### Description:
|
130
|
+
Some description of the endpoint.
|
131
|
+
|
132
|
+
### Request headers:
|
133
|
+
```json
|
134
|
+
{
|
135
|
+
"AUTHORIZATION" : "user_token",
|
136
|
+
"Content-Type" : "application/json",
|
137
|
+
"Accept" : "application/json"
|
138
|
+
}
|
139
|
+
```
|
140
|
+
|
141
|
+
### Response status:
|
142
|
+
200
|
143
|
+
|
144
|
+
### Response body:
|
145
|
+
```json
|
146
|
+
"no_content"
|
147
|
+
```
|
148
|
+
|
149
|
+
## Contributing
|
150
|
+
|
151
|
+
1. Fork it
|
152
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
153
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
154
|
+
4. Run rubocop lint (`rubocop -R --format simple`)
|
155
|
+
5. Run rspec tests (`bundle exec rspec`)
|
156
|
+
6. Push your branch (`git push origin my-new-feature`)
|
157
|
+
7. Create a new Pull Request
|
158
|
+
|
159
|
+
## License
|
160
|
+
|
161
|
+
**Dictum** is available under the MIT [license](https://raw.githubusercontent.com/alebian/dictum/master/LICENSE.md).
|
162
|
+
|
163
|
+
Copyright (c) 2016 Alejandro Bezdjian, aka alebian
|
164
|
+
|
165
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
166
|
+
of this software and associated documentation files (the "Software"), to deal
|
167
|
+
in the Software without restriction, including without limitation the rights
|
168
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
169
|
+
copies of the Software, and to permit persons to whom the Software is
|
170
|
+
furnished to do so, subject to the following conditions:
|
171
|
+
|
172
|
+
The above copyright notice and this permission notice shall be included in
|
173
|
+
all copies or substantial portions of the Software.
|
174
|
+
|
175
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
176
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
177
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
178
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
179
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
180
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
181
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/TODO.md
ADDED
data/dictum.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dictum/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'dictum'
|
8
|
+
spec.version = Dictum::VERSION
|
9
|
+
spec.authors = ['Alejandro Bezdjian']
|
10
|
+
spec.email = 'alebezdjian@gmail.com'
|
11
|
+
spec.date = Date.today
|
12
|
+
spec.summary = 'Document your APIs.'
|
13
|
+
spec.description = 'Create automatic documentation of your API endpoints through your tests.'
|
14
|
+
spec.platform = Gem::Platform::RUBY
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec)/}) }
|
16
|
+
spec.require_paths = ['lib']
|
17
|
+
spec.homepage = 'https://github.com/alebian/dictum'
|
18
|
+
spec.license = 'MIT'
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '>= 1.3.0', '< 2.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
|
24
|
+
spec.add_development_dependency 'byebug', '~> 8.0', '>= 8.0.0' if RUBY_VERSION >= '2.0.0'
|
25
|
+
spec.add_development_dependency 'rubocop', '~> 0.38', '>= 0.38.2'
|
26
|
+
end
|
data/lib/dictum.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'dictum/version'
|
2
|
+
require 'dictum/documenter'
|
3
|
+
require 'dictum/markdown_writer'
|
4
|
+
|
5
|
+
module Dictum
|
6
|
+
load 'tasks/dictum.rake' if defined?(Rails)
|
7
|
+
|
8
|
+
@config = {
|
9
|
+
output_format: :markdown,
|
10
|
+
output_path: '/tmp/docs',
|
11
|
+
root_path: '/tmp',
|
12
|
+
test_suite: :rspec,
|
13
|
+
output_filename: 'Documentation'
|
14
|
+
}
|
15
|
+
|
16
|
+
def self.configure
|
17
|
+
yield self
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.output_format=(style)
|
21
|
+
@config[:output_format] = style
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.output_path=(folder)
|
25
|
+
@config[:output_path] = folder
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.root_path=(folder)
|
29
|
+
@config[:root_path] = folder
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.test_suite=(suite)
|
33
|
+
@config[:test_suite] = suite
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.output_filename=(file)
|
37
|
+
@config[:output_filename] = file
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Method used to create a new resource
|
42
|
+
#
|
43
|
+
def self.resource(arguments)
|
44
|
+
Documenter.instance.resource(arguments)
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Method used to create a new endpoint of a resource
|
49
|
+
#
|
50
|
+
def self.endpoint(arguments)
|
51
|
+
Documenter.instance.endpoint(arguments)
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# Method that will execute tests and then save the results in the selected format
|
56
|
+
#
|
57
|
+
def self.document
|
58
|
+
Dir.mkdir(@config[:output_path]) unless Dir.exist?(@config[:output_path])
|
59
|
+
Documenter.instance.reset_resources
|
60
|
+
system "bundle exec rspec #{@config[:root_path]}" if @config[:test_suite] == :rspec
|
61
|
+
save_to_file
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.save_to_file
|
65
|
+
writer = nil
|
66
|
+
case @config[:output_format]
|
67
|
+
when :markdown
|
68
|
+
writer = MarkdownWriter.new("#{@config[:output_path]}/#{@config[:output_filename]}.md",
|
69
|
+
Documenter.instance.tempfile_path)
|
70
|
+
end
|
71
|
+
writer.write
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Dictum
|
4
|
+
##
|
5
|
+
# Singleton class that gathers the documentation and stores it as a hash/json
|
6
|
+
#
|
7
|
+
class Documenter
|
8
|
+
include Singleton
|
9
|
+
attr_reader :resources, :tempfile_path
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@resources = {}
|
13
|
+
@tempfile_path = '/tmp/dictum_temp.json'
|
14
|
+
end
|
15
|
+
|
16
|
+
def resource(arguments = {})
|
17
|
+
name = arguments[:name]
|
18
|
+
return if name.nil?
|
19
|
+
@resources[name] ||= {}
|
20
|
+
@resources[name][:description] = arguments[:description] if arguments[:description]
|
21
|
+
@resources[name][:endpoints] ||= []
|
22
|
+
update_temp
|
23
|
+
end
|
24
|
+
|
25
|
+
def endpoint(arguments = {})
|
26
|
+
resource = arguments[:resource]
|
27
|
+
endpoint = arguments[:endpoint]
|
28
|
+
return if resource.nil? || endpoint.nil?
|
29
|
+
resource(name: arguments[:resource]) unless @resources.key? arguments[:resource]
|
30
|
+
@resources[resource][:endpoints] << arguments_hash(arguments)
|
31
|
+
update_temp
|
32
|
+
end
|
33
|
+
|
34
|
+
def reset_resources
|
35
|
+
@resources = {}
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def update_temp
|
41
|
+
File.delete(tempfile_path) if File.exist?(tempfile_path)
|
42
|
+
file = File.open(tempfile_path, 'w+')
|
43
|
+
file.write(JSON.generate(@resources))
|
44
|
+
file.close
|
45
|
+
end
|
46
|
+
|
47
|
+
def arguments_hash(arguments)
|
48
|
+
{ endpoint: arguments[:endpoint],
|
49
|
+
description: arguments[:description],
|
50
|
+
http_verb: arguments[:http_verb] || '',
|
51
|
+
request_headers: arguments[:request_headers],
|
52
|
+
request_path_parameters: arguments[:request_path_parameters],
|
53
|
+
request_body_parameters: arguments[:request_body_parameters],
|
54
|
+
response_status: arguments[:response_status],
|
55
|
+
response_headers: arguments[:response_headers],
|
56
|
+
response_body: arguments[:response_body] }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Dictum
|
4
|
+
class MarkdownWriter
|
5
|
+
attr_reader :temp_path, :temp_json, :output_path, :output_file
|
6
|
+
|
7
|
+
def initialize(output_path, temp_path)
|
8
|
+
@output_path = output_path
|
9
|
+
File.delete(output_path) if File.exist?(output_path)
|
10
|
+
@temp_path = temp_path
|
11
|
+
@temp_json = JSON.parse(File.read(temp_path))
|
12
|
+
end
|
13
|
+
|
14
|
+
def write
|
15
|
+
@output_file = File.open(output_path, 'a+')
|
16
|
+
write_index
|
17
|
+
write_temp_path
|
18
|
+
output_file.close
|
19
|
+
File.delete(temp_path) if File.exist?(temp_path)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def write_index
|
25
|
+
output_file.puts '# Index'
|
26
|
+
@temp_json.each do |resource_name, _information|
|
27
|
+
output_file.puts "- #{resource_name}"
|
28
|
+
end
|
29
|
+
output_file.puts "\n"
|
30
|
+
end
|
31
|
+
|
32
|
+
def write_temp_path
|
33
|
+
@temp_json.each do |resource_name, information|
|
34
|
+
output_file.puts "# #{resource_name}"
|
35
|
+
output_file.puts "#{information['description']}\n\n"
|
36
|
+
write_endpoints(information['endpoints'])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def write_endpoints(endpoints)
|
41
|
+
endpoints.each do |endpoint|
|
42
|
+
output_file.puts "## #{endpoint['http_verb']} #{endpoint['endpoint']}\n\n"
|
43
|
+
write_endpoint_description(endpoint)
|
44
|
+
write_endpoint_response(endpoint)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def write_endpoint_description(endpoint)
|
49
|
+
print_subsubtitle('Description', endpoint['description'])
|
50
|
+
print_subsubtitle_json('Request headers', endpoint['request_headers'])
|
51
|
+
print_subsubtitle_json('Path parameters', endpoint['request_path_parameters'])
|
52
|
+
print_subsubtitle_json('Body Parameters', endpoint['request_body_parameters'])
|
53
|
+
end
|
54
|
+
|
55
|
+
def write_endpoint_response(endpoint)
|
56
|
+
print_subsubtitle('Response status', endpoint['response_status'])
|
57
|
+
print_subsubtitle_json('Response headers', endpoint['response_headers'])
|
58
|
+
print_subsubtitle_json('Response body', endpoint['response_body'])
|
59
|
+
end
|
60
|
+
|
61
|
+
def print_subsubtitle(subtitle, contents)
|
62
|
+
return if !subtitle.present? || !contents.present?
|
63
|
+
output_file.puts "\#\#\# #{subtitle}:"
|
64
|
+
output_file.puts "#{contents}\n\n"
|
65
|
+
end
|
66
|
+
|
67
|
+
def print_subsubtitle_json(subtitle, contents)
|
68
|
+
return if !subtitle.present? || !contents.present?
|
69
|
+
output_file.puts "\#\#\# #{subtitle}:"
|
70
|
+
output_file.puts "```json\n#{JSON.pretty_generate(contents)}\n```\n\n"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dictum
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alejandro Bezdjian
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.3.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '3.4'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 3.4.0
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '3.4'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 3.4.0
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: byebug
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '8.0'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 8.0.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '8.0'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 8.0.0
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: rubocop
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0.38'
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.38.2
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.38'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 0.38.2
|
93
|
+
description: Create automatic documentation of your API endpoints through your tests.
|
94
|
+
email: alebezdjian@gmail.com
|
95
|
+
executables: []
|
96
|
+
extensions: []
|
97
|
+
extra_rdoc_files: []
|
98
|
+
files:
|
99
|
+
- ".gitignore"
|
100
|
+
- ".rspec"
|
101
|
+
- ".rubocop.yml"
|
102
|
+
- ".travis.yml"
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.md
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- TODO.md
|
108
|
+
- dictum.gemspec
|
109
|
+
- lib/dictum.rb
|
110
|
+
- lib/dictum/documenter.rb
|
111
|
+
- lib/dictum/markdown_writer.rb
|
112
|
+
- lib/dictum/version.rb
|
113
|
+
- lib/tasks/dictum.rake
|
114
|
+
homepage: https://github.com/alebian/dictum
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.5.1
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Document your APIs.
|
138
|
+
test_files: []
|
139
|
+
has_rdoc:
|