service_contract 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/service_contract/avro/documentation.rb +45 -4
- data/lib/service_contract/version.rb +1 -1
- data/service_contract.gemspec +6 -0
- data/test/documentation_json_test.rb +53 -0
- data/test/documentation_test.rb +40 -0
- data/test/test_helper.rb +9 -1
- metadata +90 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e726ee71c2b94a1710d218844ed0638db29e5730
|
4
|
+
data.tar.gz: e7dd9b8d5b897d2456c4712aa00774befd9205e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d09426d12f7a2734d749f57c23fc61bea471c19aed47a6d0167486a4e25a5157a2dd51007fc5f80713e78cb07140d993bf0f4a64723f5963030350e22ae8a959
|
7
|
+
data.tar.gz: f0f48cad6bdeb955b26528e85f58a2c91f5ac03f0f5de0c23f7ed489d53cd644a25ee8bc9b5653c15d02fa558a6a51153523d4fc3feb8cfa5450673fafc9565a
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'sinatra/base'
|
2
|
+
require 'sinatra/json'
|
2
3
|
require 'slim'
|
3
4
|
|
4
5
|
module ServiceContract
|
@@ -7,28 +8,68 @@ module ServiceContract
|
|
7
8
|
get '/:version/:protocol' do
|
8
9
|
version = service.find(params[:version])
|
9
10
|
protocol = version.protocol(params[:protocol])
|
10
|
-
|
11
|
+
if request_json?
|
12
|
+
content_type "application/json"
|
13
|
+
send_file File.join(service.data_dir, version.version, "compiled", "#{protocol.name}.avpr")
|
14
|
+
else
|
15
|
+
slim :protocol, locals: { version: version, protocol: protocol }
|
16
|
+
end
|
11
17
|
end
|
12
18
|
|
13
19
|
get '/:version' do
|
14
20
|
version = service.find(params[:version])
|
15
21
|
|
16
22
|
if version
|
17
|
-
|
23
|
+
if request_json?
|
24
|
+
json version: {
|
25
|
+
version: version.version,
|
26
|
+
protocols: version.protocols.map { |protocol|
|
27
|
+
{
|
28
|
+
name: protocol.name,
|
29
|
+
link: "/#{version.version}/#{protocol.name}"
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
else
|
34
|
+
slim :version, locals: { version: version }
|
35
|
+
end
|
18
36
|
else
|
19
37
|
status 404
|
20
38
|
end
|
21
39
|
end
|
22
40
|
|
23
41
|
get '/' do
|
24
|
-
|
42
|
+
if request_json?
|
43
|
+
json contract: {
|
44
|
+
name: service.name,
|
45
|
+
title: service.title,
|
46
|
+
description: service.description,
|
47
|
+
release_version: release_version,
|
48
|
+
versions: service.all.map { |version|
|
49
|
+
{
|
50
|
+
version: version.version,
|
51
|
+
link: "/#{version.version}"
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
else
|
56
|
+
slim :homepage
|
57
|
+
end
|
25
58
|
end
|
26
59
|
|
27
60
|
helpers do
|
28
61
|
def service
|
29
62
|
raise :not_implemented
|
30
63
|
end
|
64
|
+
|
65
|
+
def request_json?
|
66
|
+
request.accept.map(&:entry).include?("application/json")
|
67
|
+
end
|
68
|
+
|
69
|
+
def release_version
|
70
|
+
service.const_defined?("VERSION") ? service.const_get("VERSION") : ""
|
71
|
+
end
|
31
72
|
end
|
32
73
|
end
|
33
74
|
end
|
34
|
-
end
|
75
|
+
end
|
data/service_contract.gemspec
CHANGED
@@ -23,4 +23,10 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
spec.add_development_dependency "minitest", "~> 5"
|
25
25
|
spec.add_development_dependency "faker"
|
26
|
+
spec.add_development_dependency "sinatra"
|
27
|
+
spec.add_development_dependency "slim"
|
28
|
+
spec.add_development_dependency "rack-test"
|
29
|
+
spec.add_development_dependency "capybara"
|
30
|
+
spec.add_development_dependency "sinatra-contrib"
|
31
|
+
spec.add_development_dependency "pry"
|
26
32
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
ENV['RACK_ENV'] = 'test'
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'rack/test'
|
5
|
+
require 'service_contract/avro/documentation'
|
6
|
+
|
7
|
+
class DocumentationJsonTest < Minitest::Test
|
8
|
+
include Rack::Test::Methods
|
9
|
+
|
10
|
+
def app
|
11
|
+
SampleDocumentation
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup
|
15
|
+
super
|
16
|
+
header "Accept", "application/json"
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_homepage_json
|
20
|
+
get '/'
|
21
|
+
assert_equal "application/json", last_response.headers["Content-Type"]
|
22
|
+
assert_equal({"contract" => {
|
23
|
+
"name" => "SampleService",
|
24
|
+
"title" => "Avro Service",
|
25
|
+
"description" => "",
|
26
|
+
"release_version" => "0.1.2",
|
27
|
+
"versions" => [
|
28
|
+
{"version" => "1", "link" => "/1"},
|
29
|
+
{"version" => "2", "link" => "/2"},
|
30
|
+
]
|
31
|
+
}}, JSON.parse(last_response.body))
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_version_index_json
|
35
|
+
get '/1'
|
36
|
+
assert_equal "application/json", last_response.headers["Content-Type"]
|
37
|
+
assert_equal({"version" => {
|
38
|
+
"version" => "1",
|
39
|
+
"protocols" => [
|
40
|
+
{"name" => "city_state", "link" => "/1/city_state"},
|
41
|
+
{"name" => "location", "link" => "/1/location"},
|
42
|
+
{"name" => "sales_region", "link" => "/1/sales_region"},
|
43
|
+
]
|
44
|
+
}}, JSON.parse(last_response.body))
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_protocol_json
|
48
|
+
get '/1/city_state'
|
49
|
+
assert_equal "application/json", last_response.headers["Content-Type"]
|
50
|
+
assert_equal File.read(File.expand_path("../sample/1/compiled/city_state.avpr", __FILE__)),
|
51
|
+
last_response.body
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
ENV['RACK_ENV'] = 'test'
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'rack/test'
|
5
|
+
require 'capybara'
|
6
|
+
require 'capybara/dsl'
|
7
|
+
require 'service_contract/avro/documentation'
|
8
|
+
|
9
|
+
class DocumentationTest < Minitest::Test
|
10
|
+
include Capybara::DSL
|
11
|
+
|
12
|
+
class SampleDocumentation < ServiceContract::Avro::Documentation
|
13
|
+
def service
|
14
|
+
SampleService
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup
|
19
|
+
super
|
20
|
+
Capybara.app = SampleDocumentation
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_homepage_html
|
24
|
+
visit '/'
|
25
|
+
assert page.find("a[href='http://www.example.com/1']", text: "Version 1")
|
26
|
+
assert page.find("a[href='http://www.example.com/2']", text: "Version 2")
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_version_index_html
|
30
|
+
visit '/1'
|
31
|
+
assert page.find("a[href='http://www.example.com/1/city_state']", text: "city_state")
|
32
|
+
assert page.find("a[href='http://www.example.com/1/location']", text: "location")
|
33
|
+
assert page.find("a[href='http://www.example.com/1/sales_region']", text: "sales_region")
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_version_protocol_html
|
37
|
+
visit '/1/city_state'
|
38
|
+
assert page.has_content?("CityState params")
|
39
|
+
end
|
40
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -4,7 +4,15 @@ require 'minitest/autorun'
|
|
4
4
|
require 'service_contract'
|
5
5
|
|
6
6
|
class SampleService < ServiceContract::Avro::Service
|
7
|
+
VERSION = "0.1.2"
|
8
|
+
|
7
9
|
def self.data_dir
|
8
10
|
File.expand_path("../sample", __FILE__)
|
9
11
|
end
|
10
|
-
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class SampleDocumentation < ServiceContract::Avro::Documentation
|
15
|
+
def service
|
16
|
+
SampleService
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: service_contract
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Ching
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro
|
@@ -80,6 +80,90 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sinatra
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: slim
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rack-test
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: capybara
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: sinatra-contrib
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: pry
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
83
167
|
description: Abstract the definition of a service's interface contract. Supports Avro
|
84
168
|
email:
|
85
169
|
- jching@avvo.com
|
@@ -119,6 +203,8 @@ files:
|
|
119
203
|
- service_contract.gemspec
|
120
204
|
- src/avro-tools-1.7.7.jar
|
121
205
|
- test/assertions_test.rb
|
206
|
+
- test/documentation_json_test.rb
|
207
|
+
- test/documentation_test.rb
|
122
208
|
- test/mock_test.rb
|
123
209
|
- test/sample/1/compiled/city_state.avpr
|
124
210
|
- test/sample/1/compiled/location.avpr
|
@@ -160,6 +246,8 @@ specification_version: 4
|
|
160
246
|
summary: Abstract the definition of a service's interface contract
|
161
247
|
test_files:
|
162
248
|
- test/assertions_test.rb
|
249
|
+
- test/documentation_json_test.rb
|
250
|
+
- test/documentation_test.rb
|
163
251
|
- test/mock_test.rb
|
164
252
|
- test/sample/1/compiled/city_state.avpr
|
165
253
|
- test/sample/1/compiled/location.avpr
|
@@ -175,4 +263,3 @@ test_files:
|
|
175
263
|
- test/sample/2/source/social_login.avdl
|
176
264
|
- test/service_test.rb
|
177
265
|
- test/test_helper.rb
|
178
|
-
has_rdoc:
|