prmd 0.1.0 → 0.2.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 +8 -8
- data/CONTRIBUTING.md +18 -0
- data/CONTRIBUTORS.md +3 -0
- data/Gemfile.lock +6 -6
- data/README.md +61 -37
- data/bin/prmd +2 -2
- data/lib/prmd/commands/combine.rb +15 -4
- data/lib/prmd/commands/init.rb +6 -6
- data/lib/prmd/schema.rb +9 -1
- data/lib/prmd/version.rb +1 -1
- data/lib/prmd/views/endpoint.erb +1 -0
- data/lib/prmd.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
ZGFhZTI3Yjc0OTA3ZWI5Mzc4NzBlNWQzMWY4YmQ5ZmRmNjAzZGIwMg==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
MTZlMzFjMDhjMWYyYmRlM2YxZjIyNjNkZjRjOWI0NmZkNDk4ZmU1MQ==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
MDM1ZTE1MTI1YWNiMDMzZmQ4YmRhYzQ0MDI4Nzc4ZmI1ODM3NTUyODEzYjZm
|
|
10
|
+
YTY5NGU3Mjk1ZmVhZDQ3Mjg2OTMwZjA2NmRlYzc3OTNkNWEyOWZjYTM4NzI2
|
|
11
|
+
OWU5OTZjMTU4ZmNiYzUyMTg5NmE4NGM0MTgyN2QxMzFiNzEyMDY=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
NjI0ZWJjOTRjNTA5YTM4MzI4NzI0ZDc2ZTYyZDQyNzRlYmM2MzIwOWQ2MDMy
|
|
14
|
+
NWVlYmExZDNhNTJiMDkxYmU5ZmRiNzRiZGNhYjA1NDUwZjcwOGQ0NDhhZmY0
|
|
15
|
+
Yjg4MDMwYmFlOWJkMDY0ZDljOTdiMWRhY2Q0NzA4ZmQ3YWFkMDU=
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
## Getting Involved
|
|
2
|
+
|
|
3
|
+
New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another.
|
|
4
|
+
|
|
5
|
+
### Coding
|
|
6
|
+
|
|
7
|
+
* Pick a task:
|
|
8
|
+
* Offer feedback on open [pull requests](https://github.com/heroku/prmd/pulls).
|
|
9
|
+
* Review open [issues](https://github.com/heroku/prmd/issues) for things to help on.
|
|
10
|
+
* [Create an issue](https://github.com/heroku/prmd/issues/new) to start a discussion on additions or features.
|
|
11
|
+
* Fork the project, add your changes and tests to cover them in a topic branch.
|
|
12
|
+
* Commit your changes and rebase against `heroku/prmd` to ensure everything is up to date.
|
|
13
|
+
* [Submit a pull request](https://github.com/heroku/prmd/compare/).
|
|
14
|
+
|
|
15
|
+
### Non-Coding
|
|
16
|
+
|
|
17
|
+
* Offer feedback on open [issues](https://github.com/heroku/prmd/issues).
|
|
18
|
+
* Organize or volunteer at events.
|
data/CONTRIBUTORS.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
* Brandur <brandur@mutelight.org>
|
|
2
2
|
* Chris Continanza <christopher.continanza@gmail.com>
|
|
3
|
+
* Dane Harrigan <dane.harrigan@gmail.com>
|
|
4
|
+
* Kousuke Ebihara <kousuke@co3k.org>
|
|
3
5
|
* Mark McGranaghan <mmcgrana@gmail.com>
|
|
6
|
+
* Olivier Lance <olance@users.noreply.github.com>
|
|
4
7
|
* Timothée Peignier <timothee.peignier@tryphon.org>
|
|
5
8
|
* Wesley Beary <geemus+github@gmail.com>
|
|
6
9
|
* geemus <geemus@gmail.com>
|
data/Gemfile.lock
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
prmd (0.0
|
|
5
|
-
erubis
|
|
4
|
+
prmd (0.2.0)
|
|
5
|
+
erubis (~> 2.7)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
10
|
erubis (2.7.0)
|
|
11
|
-
minitest (
|
|
12
|
-
rake (10.
|
|
11
|
+
minitest (5.3.2)
|
|
12
|
+
rake (10.2.2)
|
|
13
13
|
|
|
14
14
|
PLATFORMS
|
|
15
15
|
ruby
|
|
16
16
|
|
|
17
17
|
DEPENDENCIES
|
|
18
18
|
bundler (~> 1.3)
|
|
19
|
-
minitest
|
|
19
|
+
minitest (~> 5.3)
|
|
20
20
|
prmd!
|
|
21
|
-
rake
|
|
21
|
+
rake (~> 10.2)
|
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Prmd
|
|
2
2
|
|
|
3
3
|
JSON Schema tooling: scaffold, verify, and generate documentation
|
|
4
|
-
|
|
4
|
+
from JSON Schema documents.
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
## Introduction
|
|
@@ -11,76 +11,100 @@ an API. prmd provides tools for bootstrapping a description like this,
|
|
|
11
11
|
verifying its completeness, and generating documentation from the
|
|
12
12
|
specification.
|
|
13
13
|
|
|
14
|
-
The JSON Schema usage conventions expected by prmd are described in
|
|
15
|
-
[/docs/schemata.md](/docs/schemata.md).
|
|
16
|
-
|
|
17
14
|
To learn more about JSON Schema in general, start with
|
|
18
15
|
[this excellent guide](http://spacetelescope.github.io/understanding-json-schema/)
|
|
19
16
|
and supplement with the [specification](http://json-schema.org/documentation.html).
|
|
17
|
+
The JSON Schema usage conventions expected by prmd specifically are
|
|
18
|
+
described in [/docs/schemata.md](/docs/schemata.md).
|
|
20
19
|
|
|
21
20
|
## Installation
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
Install the command-line tool with:
|
|
24
23
|
|
|
25
|
-
```
|
|
26
|
-
gem
|
|
24
|
+
```console
|
|
25
|
+
$ gem install prmd
|
|
27
26
|
```
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
If you're using prmd within a Ruby project, you may want to add it
|
|
29
|
+
to the application's Gemfile:
|
|
30
30
|
|
|
31
|
-
```
|
|
32
|
-
|
|
31
|
+
```ruby
|
|
32
|
+
gem 'prmd'
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
Or install it yourself as:
|
|
36
|
-
|
|
37
35
|
```console
|
|
38
|
-
$
|
|
36
|
+
$ bundle install
|
|
39
37
|
```
|
|
40
38
|
|
|
41
39
|
## Usage
|
|
42
40
|
|
|
43
|
-
|
|
44
|
-
combines them on to stdout. If -m or --meta is supplied, it will override
|
|
45
|
-
defaults/metadata:
|
|
41
|
+
Prmd provides four main commands:
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
* `init`: Scaffold resource schemata
|
|
44
|
+
* `combine`: Combine schemata and metadata into single schema
|
|
45
|
+
* `verify`: Verify a schema
|
|
46
|
+
* `doc`: Generate documentation from a schema
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
If -m or --meta is supplied, it will override defaults/metadata:
|
|
48
|
+
Here's an example of using these commands in a typical workflow:
|
|
53
49
|
|
|
54
50
|
```console
|
|
55
|
-
|
|
51
|
+
# Fill out the resource schemata
|
|
52
|
+
$ mkdir -p schemata
|
|
53
|
+
$ prmd init app > schemata/app.json
|
|
54
|
+
$ prmd init user > schemata/user.json
|
|
55
|
+
$ vim schemata/{app,user}.json # edit scaffolded files
|
|
56
|
+
|
|
57
|
+
# Provide top-level metadata
|
|
58
|
+
$ cat <<EOF > meta.json
|
|
59
|
+
{
|
|
60
|
+
"description": "Hello world prmd API",
|
|
61
|
+
"id": "hello-prmd",
|
|
62
|
+
"links": [{
|
|
63
|
+
"href": "https://api.hello.com",
|
|
64
|
+
"rel": "self"
|
|
65
|
+
}],
|
|
66
|
+
"title": "Hello Prmd"
|
|
67
|
+
}
|
|
68
|
+
EOF
|
|
69
|
+
|
|
70
|
+
# Combine into a single schema
|
|
71
|
+
$ prmd combine --meta meta.json schemata/ > schema.json
|
|
72
|
+
|
|
73
|
+
# Check it’s all good
|
|
74
|
+
$ prmd verify schema.json
|
|
75
|
+
|
|
76
|
+
# Build docs
|
|
77
|
+
$ prmd doc schema.json > schema.md
|
|
56
78
|
```
|
|
57
79
|
|
|
58
|
-
|
|
80
|
+
Typically you'll want to prepend header and overview information to
|
|
81
|
+
your API documentation. You can do this with the `--prepend` flag:
|
|
59
82
|
|
|
60
83
|
```console
|
|
61
|
-
$ prmd doc
|
|
84
|
+
$ prmd doc schema.json --prepend overview.md > schema.md
|
|
62
85
|
```
|
|
63
86
|
|
|
64
|
-
|
|
65
|
-
new schema file to stdout (generically or using the resource name
|
|
66
|
-
provided). If -m or --meta is supplied, it will override
|
|
67
|
-
defaults/metadata:
|
|
87
|
+
You can also chain commands together as needed, e.g.:
|
|
68
88
|
|
|
69
89
|
```console
|
|
70
|
-
$ prmd
|
|
71
|
-
$ prmd init <resource name>
|
|
90
|
+
$ prmd combine --meta meta.json schemata/ | prmd verify | prmd doc --prepend overview.md > schema.md
|
|
72
91
|
```
|
|
73
92
|
|
|
74
|
-
|
|
93
|
+
See `prmd <command> --help` for additional usage details.
|
|
75
94
|
|
|
76
|
-
|
|
77
|
-
$ prmd verify <combined schema>
|
|
78
|
-
```
|
|
95
|
+
## File Layout
|
|
79
96
|
|
|
80
|
-
|
|
97
|
+
We suggest the following file layout for JSON schema related files:
|
|
81
98
|
|
|
82
|
-
```
|
|
83
|
-
|
|
99
|
+
```
|
|
100
|
+
/docs (top-level directory for project documentation)
|
|
101
|
+
/schema (API schema documentation)
|
|
102
|
+
/schemata
|
|
103
|
+
/{resource.json} (individual resource schema)
|
|
104
|
+
/meta.json (overall API metadata)
|
|
105
|
+
/overview.md (preamble for generated API docs)
|
|
106
|
+
/schema.json (complete generated JSON schema file)
|
|
107
|
+
/schema.md (complete generated API documentation file)
|
|
84
108
|
```
|
|
85
109
|
|
|
86
110
|
## Contributing
|
data/bin/prmd
CHANGED
|
@@ -19,8 +19,8 @@ commands = {
|
|
|
19
19
|
end,
|
|
20
20
|
init: OptionParser.new do |opts|
|
|
21
21
|
opts.banner = "prmd init [options] <resource name>"
|
|
22
|
-
opts.on("-
|
|
23
|
-
options[:
|
|
22
|
+
opts.on("-y", "--yaml", "Generate YAML") do |y|
|
|
23
|
+
options[:yaml] = y
|
|
24
24
|
end
|
|
25
25
|
end,
|
|
26
26
|
verify: OptionParser.new do |opts|
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
module Prmd
|
|
2
2
|
def self.combine(path, options={})
|
|
3
3
|
files = if File.directory?(path)
|
|
4
|
-
Dir.glob(File.join(path, '**', '*.json'))
|
|
4
|
+
Dir.glob(File.join(path, '**', '*.json')) +
|
|
5
|
+
Dir.glob(File.join(path, '**', '*.yaml')) -
|
|
6
|
+
[options[:meta]]
|
|
5
7
|
else
|
|
6
8
|
[path]
|
|
7
9
|
end
|
|
8
|
-
|
|
10
|
+
# sort for stable loading on any platform
|
|
11
|
+
schemas = files.sort.map { |file| [file, YAML.load(File.read(file))] }
|
|
9
12
|
|
|
10
13
|
data = {
|
|
11
14
|
'$schema' => 'http://json-schema.org/draft-04/hyper-schema',
|
|
@@ -14,16 +17,24 @@ module Prmd
|
|
|
14
17
|
'type' => ['object']
|
|
15
18
|
}
|
|
16
19
|
|
|
20
|
+
# tracks which entities where defined in which file
|
|
21
|
+
definitions_map = {}
|
|
22
|
+
|
|
17
23
|
if options[:meta] && File.exists?(options[:meta])
|
|
18
|
-
data.merge!(
|
|
24
|
+
data.merge!(YAML.load(File.read(options[:meta])))
|
|
19
25
|
end
|
|
20
26
|
|
|
21
|
-
schemas.each do |schema_data|
|
|
27
|
+
schemas.each do |schema_file, schema_data|
|
|
22
28
|
id = if schema_data['id']
|
|
23
29
|
schema_data['id'].split('/').last
|
|
24
30
|
end
|
|
25
31
|
next if id.nil? || id[0..0] == '_' # FIXME: remove this exception?
|
|
26
32
|
|
|
33
|
+
if file = definitions_map[id]
|
|
34
|
+
$stderr.puts "`#{id}` (from #{schema_file}) was already defined in `#{file}` and will overwrite the first definition"
|
|
35
|
+
end
|
|
36
|
+
definitions_map[id] = schema_file
|
|
37
|
+
|
|
27
38
|
data['definitions'][id] = schema_data
|
|
28
39
|
reference_localizer = lambda do |datum|
|
|
29
40
|
case datum
|
data/lib/prmd/commands/init.rb
CHANGED
|
@@ -10,10 +10,6 @@ module Prmd
|
|
|
10
10
|
'type' => ['object']
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
if options[:meta] && File.exists?(options[:meta])
|
|
14
|
-
data.merge!(JSON.parse(File.read(options[:meta])))
|
|
15
|
-
end
|
|
16
|
-
|
|
17
13
|
schema = Prmd::Schema.new(data)
|
|
18
14
|
|
|
19
15
|
if resource
|
|
@@ -21,7 +17,7 @@ module Prmd
|
|
|
21
17
|
parent, resource = resource.split('/')
|
|
22
18
|
end
|
|
23
19
|
schema['id'] = "schemata/#{resource}"
|
|
24
|
-
schema['title'] = "
|
|
20
|
+
schema['title'] = "FIXME - #{resource[0...1].upcase}#{resource[1..-1]}"
|
|
25
21
|
schema['definitions'] = {
|
|
26
22
|
"created_at" => {
|
|
27
23
|
"description" => "when #{resource} was created",
|
|
@@ -106,6 +102,10 @@ module Prmd
|
|
|
106
102
|
}
|
|
107
103
|
end
|
|
108
104
|
|
|
109
|
-
|
|
105
|
+
if options[:yaml]
|
|
106
|
+
schema.to_yaml
|
|
107
|
+
else
|
|
108
|
+
schema.to_json
|
|
109
|
+
end
|
|
110
110
|
end
|
|
111
111
|
end
|
data/lib/prmd/schema.rb
CHANGED
|
@@ -55,12 +55,20 @@ module Prmd
|
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
def
|
|
58
|
+
def to_json
|
|
59
59
|
new_json = JSON.pretty_generate(@data)
|
|
60
60
|
# nuke empty lines
|
|
61
61
|
new_json = new_json.split("\n").delete_if {|line| line.empty?}.join("\n") + "\n"
|
|
62
62
|
new_json
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
+
def to_yaml
|
|
66
|
+
YAML.dump(@data)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def to_s
|
|
70
|
+
to_json
|
|
71
|
+
end
|
|
72
|
+
|
|
65
73
|
end
|
|
66
74
|
end
|
data/lib/prmd/version.rb
CHANGED
data/lib/prmd/views/endpoint.erb
CHANGED
|
@@ -64,6 +64,7 @@ end -%>
|
|
|
64
64
|
data = {}
|
|
65
65
|
if link['schema']['properties']
|
|
66
66
|
link['schema']['properties'].each do |key, value|
|
|
67
|
+
_, value = schema.dereference(value)
|
|
67
68
|
if value.has_key?('anyOf')
|
|
68
69
|
id_ref = value['anyOf'].detect {|ref| ref['$ref'].split('/').last == 'id'}
|
|
69
70
|
data[key] = schema.dereference(id_ref).last['example']
|
data/lib/prmd.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: prmd
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- geemus
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-04-
|
|
11
|
+
date: 2014-04-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: erubis
|
|
@@ -76,6 +76,7 @@ extra_rdoc_files: []
|
|
|
76
76
|
files:
|
|
77
77
|
- .gitignore
|
|
78
78
|
- .travis.yml
|
|
79
|
+
- CONTRIBUTING.md
|
|
79
80
|
- CONTRIBUTORS.md
|
|
80
81
|
- Gemfile
|
|
81
82
|
- Gemfile.lock
|