prmd 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ module Prmd
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,107 @@
1
+ ## <%= title %>
2
+ <%= definition['description'] %>
3
+
4
+ <%- if definition['properties'] %>
5
+ ### Attributes
6
+ <table>
7
+ <tr>
8
+ <th>Name</th>
9
+ <th>Type</th>
10
+ <th>Description</th>
11
+ <th>Example</th>
12
+ </tr>
13
+ <%- extract_attributes(schema, definition['properties']).each do |(key, type, description, example)| %>
14
+ <tr>
15
+ <td><strong><%= key %></strong></td>
16
+ <td><em><%= type %></em></td>
17
+ <td><%= description %></td>
18
+ <td><%= example %></td>
19
+ </tr>
20
+ <%- end %>
21
+ </table>
22
+
23
+ <%- end %>
24
+ <%- definition['links'].each do |link, datum| %>
25
+ <%- path = link['href'].gsub(%r|(\{\([^\)]+\)\})|) do |ref|
26
+ ref = ref.gsub('%2F', '/').gsub('%23', '#').gsub(%r|[\{\(\)\}]|, '')
27
+ resource = ref.split('#/definitions/').last.split('/definitions/identity').first
28
+ '{' + resource + '_' + schema.dereference(ref)['anyOf'].map {|r| r['$ref'].split('/').last}.join('_or_') + '}'
29
+ end -%>
30
+ ### <%= title %> <%= link['title'] %>
31
+ <%= link['description'] %>
32
+
33
+ ```
34
+ <%= link['method'] %> <%= path %>
35
+ ```
36
+
37
+ <%- if link.has_key?('schema') && link['schema'].has_key?('properties') %>
38
+ <%-
39
+ required, optional = link['schema']['properties'].partition do |k, v|
40
+ (link['schema']['required'] || []).include?(k)
41
+ end.map { |partition| Hash[partition] }
42
+ %>
43
+ <%- unless required.empty? %>
44
+ #### Required Parameters
45
+ <%= Erubis::Eruby.new(params_template).result(params: required, schema: schema) %>
46
+
47
+ <%- end %>
48
+ <%- unless optional.empty? %>
49
+ #### Optional Parameters
50
+ <%= Erubis::Eruby.new(params_template).result(params: optional, schema: schema) %>
51
+ <%- end %>
52
+ <%- end %>
53
+
54
+ #### Curl Example
55
+ ```term
56
+ $ curl -n -X <%= link['method'] %> <%= root_url %><%= path.gsub(/{([^}]*)}/) {|match| '$' + match.gsub(/[{}]/, '').gsub('-', '_').upcase} %><%- if link.has_key?('schema') && (link['schema'].has_key?('properties') || link['schema'].has_key?('example')) %> \
57
+ -H "Content-Type: application/json" \
58
+ <%-
59
+ data = {}
60
+ if link['schema']['properties']
61
+ link['schema']['properties'].each do |key, value|
62
+ if value.has_key?('anyOf')
63
+ id_ref = value['anyOf'].detect {|ref| ref['$ref'].split('/').last == 'id'}
64
+ data[key] = schema.dereference(id_ref)['example']
65
+ elsif value.has_key?('properties')
66
+ data[key] = {}
67
+ value['properties'].each do |k,v|
68
+ data[key][k] = v['example']
69
+ end
70
+ else
71
+ data[key] = value['example']
72
+ end
73
+ end
74
+ else
75
+ data.merge!(link['schema']['example'])
76
+ end
77
+ %>
78
+ -d '<%= data.to_json %>'
79
+ <%- else %>
80
+
81
+ <%- end %>
82
+ ```
83
+
84
+ #### Response Example
85
+ ```
86
+ HTTP/1.1 <%= case link['rel']
87
+ when 'create'
88
+ '201 Created'
89
+ else
90
+ '200 OK'
91
+ end %>
92
+ <%- if link['rel'] == 'instances' && identifiers %>
93
+ Accept-Range: <%= identifiers.join(', ') %>
94
+ Content-Range: id 01234567-89ab-cdef-0123-456789abcdef..01234567-89ab-cdef-0123-456789abcdef; max=200
95
+ <%- end %>
96
+ ETag: "0123456789abcdef0123456789abcdef"
97
+ RateLimit-Remaining: 1200
98
+ ```
99
+ ```javascript```
100
+ <%- if link['rel'] == 'instances' %>
101
+ <%= JSON.pretty_generate([serialization]) %>
102
+ <%- else %>
103
+ <%= JSON.pretty_generate(serialization) %>
104
+ <%- end %>
105
+ ```
106
+
107
+ <%- end -%>
@@ -0,0 +1,16 @@
1
+ <table>
2
+ <tr>
3
+ <th>Name</th>
4
+ <th>Type</th>
5
+ <th>Description</th>
6
+ <th>Example</th>
7
+ </tr>
8
+ <%- extract_attributes(schema, params).each do |(key, type, description, example)| %>
9
+ <tr>
10
+ <td><strong><%= key %></strong></td>
11
+ <td><em><%= type %></em></td>
12
+ <td><%= description %></td>
13
+ <td><%= example %></td>
14
+ </tr>
15
+ <%- end %>
16
+ </table>
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'prmd/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "prmd"
8
+ spec.version = Prmd::VERSION
9
+ spec.authors = ["geemus"]
10
+ spec.email = ["geemus@gmail.com"]
11
+ spec.description = %q{schema to rule them all}
12
+ spec.summary = %q{schema to rule them all}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "diff-lcs"
22
+ spec.add_dependency "erubis"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "minitest"
27
+ end
@@ -0,0 +1,10 @@
1
+ require "minitest/autorun"
2
+ require "prmd"
3
+
4
+ def input_schemas_path
5
+ @data_path ||= File.join(File.dirname(__FILE__), 'schemas', 'input')
6
+ end
7
+
8
+ def user_input_schema
9
+ @user_input_schema ||= Prmd::Schema.load(File.join(input_schemas_path, 'user.json'))
10
+ end
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), 'helpers')
2
+
3
+ class SchemaTest < Minitest::Unit::TestCase
4
+ def test_dereference_with_ref
5
+ ref = user_input_schema.dereference({ "$ref" => "/schema/user#/definitions/id" })
6
+ assert_equal ref, user_input_schema["definitions"]["id"]
7
+ end
8
+
9
+ def test_dereference_without_ref
10
+ ref = user_input_schema.dereference("/schema/user#/definitions/id")
11
+ assert_equal ref, user_input_schema["definitions"]["id"]
12
+ end
13
+ end
@@ -0,0 +1,102 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/hyper-schema",
3
+ "title": "API - User",
4
+ "type": [
5
+ "object"
6
+ ],
7
+ "definitions": {
8
+ "created_at": {
9
+ "description": "when user was created",
10
+ "example": "2012-01-01T12:00:00Z",
11
+ "format": "date-time",
12
+ "readOnly": true,
13
+ "type": [
14
+ "string"
15
+ ]
16
+ },
17
+ "id": {
18
+ "description": "unique identifier of user",
19
+ "example": "01234567-89ab-cdef-0123-456789abcdef",
20
+ "format": "uuid",
21
+ "readOnly": true,
22
+ "type": [
23
+ "string"
24
+ ]
25
+ },
26
+ "identity": {
27
+ "$ref": "/schema/user#/definitions/id"
28
+ },
29
+ "updated_at": {
30
+ "description": "when user was updated",
31
+ "example": "2012-01-01T12:00:00Z",
32
+ "format": "date-time",
33
+ "readOnly": true,
34
+ "type": [
35
+ "string"
36
+ ]
37
+ }
38
+ },
39
+ "links": [
40
+ {
41
+ "description": "Create a new user.",
42
+ "href": "/users",
43
+ "method": "POST",
44
+ "rel": "create",
45
+ "schema": {
46
+ "properties": {
47
+ },
48
+ "type": [
49
+ "object"
50
+ ]
51
+ },
52
+ "title": "Create"
53
+ },
54
+ {
55
+ "description": "Delete an existing user.",
56
+ "href": "/users/{(%2Fschema%2Fuser%23%2Fdefinitions%2Fidentity)}",
57
+ "method": "DELETE",
58
+ "rel": "destroy",
59
+ "title": "Delete"
60
+ },
61
+ {
62
+ "description": "Info for existing user.",
63
+ "href": "/users/{(%2Fschema%2Fuser%23%2Fdefinitions%2Fidentity)}",
64
+ "method": "GET",
65
+ "rel": "self",
66
+ "title": "Info"
67
+ },
68
+ {
69
+ "description": "List existing user.",
70
+ "href": "/users",
71
+ "method": "GET",
72
+ "rel": "instances",
73
+ "title": "List"
74
+ },
75
+ {
76
+ "description": "Update an existing user.",
77
+ "href": "/users/{(%2Fschema%2Fuser%23%2Fdefinitions%2Fidentity)}",
78
+ "method": "PATCH",
79
+ "rel": "update",
80
+ "schema": {
81
+ "properties": {
82
+ },
83
+ "type": [
84
+ "object"
85
+ ]
86
+ },
87
+ "title": "Update"
88
+ }
89
+ ],
90
+ "properties": {
91
+ "created_at": {
92
+ "$ref": "/schema/user#/definitions/created_at"
93
+ },
94
+ "id": {
95
+ "$ref": "/schema/user#/definitions/id"
96
+ },
97
+ "updated_at": {
98
+ "$ref": "/schema/user#/definitions/updated_at"
99
+ }
100
+ },
101
+ "id": "schema/user"
102
+ }
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prmd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - geemus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: diff-lcs
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: erubis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: schema to rule them all
84
+ email:
85
+ - geemus@gmail.com
86
+ executables:
87
+ - prmd
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .travis.yml
93
+ - CONTRIBUTORS.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.md
97
+ - README.md
98
+ - Rakefile
99
+ - bin/prmd
100
+ - docs/schemata.md
101
+ - lib/prmd.rb
102
+ - lib/prmd/commands/combine.rb
103
+ - lib/prmd/commands/doc.rb
104
+ - lib/prmd/commands/expand.rb
105
+ - lib/prmd/commands/init.rb
106
+ - lib/prmd/commands/verify.rb
107
+ - lib/prmd/schema.rb
108
+ - lib/prmd/version.rb
109
+ - lib/prmd/views/endpoint.erb
110
+ - lib/prmd/views/parameters.erb
111
+ - prmd.gemspec
112
+ - test/helpers.rb
113
+ - test/schema_test.rb
114
+ - test/schemas/input/user.json
115
+ homepage: ''
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.2.2
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: schema to rule them all
139
+ test_files:
140
+ - test/helpers.rb
141
+ - test/schema_test.rb
142
+ - test/schemas/input/user.json
143
+ has_rdoc: