haveapi 0.29.8 → 0.29.9
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 +4 -4
- data/.gitignore +1 -0
- data/Rakefile +19 -0
- data/doc/create-client.md +113 -0
- data/doc/json-schema.html +1182 -0
- data/doc/protocol.md +570 -0
- data/doc/protocol.png +0 -0
- data/doc/typed-input-validation.md +113 -0
- data/haveapi.gemspec +1 -1
- data/lib/haveapi/server.rb +6 -1
- data/lib/haveapi/version.rb +1 -1
- data/spec/documentation_spec.rb +14 -0
- data/spec/extensions/exception_mailer_spec.rb +33 -0
- data/spec/packaging_spec.rb +124 -0
- metadata +9 -3
data/lib/haveapi/server.rb
CHANGED
|
@@ -533,7 +533,12 @@ module HaveAPI
|
|
|
533
533
|
@sinatra.get "#{@root}doc/json-schema" do
|
|
534
534
|
content_type 'text/html'
|
|
535
535
|
erb :doc_layout, layout: :main_layout do
|
|
536
|
-
|
|
536
|
+
begin
|
|
537
|
+
@content = File.read(File.join(settings.root, '../../doc/json-schema.html'))
|
|
538
|
+
rescue Errno::ENOENT
|
|
539
|
+
halt 404
|
|
540
|
+
end
|
|
541
|
+
|
|
537
542
|
@sidebar = erb :'doc_sidebars/json-schema'
|
|
538
543
|
end
|
|
539
544
|
end
|
data/lib/haveapi/version.rb
CHANGED
data/spec/documentation_spec.rb
CHANGED
|
@@ -195,4 +195,18 @@ describe 'Documentation' do
|
|
|
195
195
|
expect(last_response.status).to eq(200)
|
|
196
196
|
expect(last_response.headers['Content-Type']).to include('text/html')
|
|
197
197
|
end
|
|
198
|
+
|
|
199
|
+
{
|
|
200
|
+
'/doc/json-schema' => 'Envelope',
|
|
201
|
+
'/doc/protocol.md' => 'Protocol definition',
|
|
202
|
+
'/doc/create-client.md' => 'Client definition'
|
|
203
|
+
}.each do |path, heading|
|
|
204
|
+
it "serves shared documentation at #{path}" do
|
|
205
|
+
get path
|
|
206
|
+
|
|
207
|
+
expect(last_response.status).to eq(200)
|
|
208
|
+
expect(last_response.headers['Content-Type']).to include('text/html')
|
|
209
|
+
expect(last_response.body).to include(heading)
|
|
210
|
+
end
|
|
211
|
+
end
|
|
198
212
|
end
|
|
@@ -122,6 +122,39 @@ describe HaveAPI::Extensions::ExceptionMailer do
|
|
|
122
122
|
expect(body).to include('request boom')
|
|
123
123
|
end
|
|
124
124
|
|
|
125
|
+
it 'does not mail a missing JSON schema documentation file' do
|
|
126
|
+
mailer = new_mailer
|
|
127
|
+
calls = collect_mail_calls(mailer)
|
|
128
|
+
doc_path = File.join(app.settings.root, '../../doc/json-schema.html')
|
|
129
|
+
allow(File).to receive(:read).and_call_original
|
|
130
|
+
allow(File).to receive(:read).with(doc_path).and_raise(Errno::ENOENT, doc_path)
|
|
131
|
+
|
|
132
|
+
with_exception_mailer(mailer) do
|
|
133
|
+
get '/doc/json-schema'
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
expect(last_response.status).to eq(404)
|
|
137
|
+
expect(calls).to be_empty
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it 'still mails other JSON schema file errors' do
|
|
141
|
+
mailer = new_mailer
|
|
142
|
+
calls = collect_mail_calls(mailer)
|
|
143
|
+
app.set :raise_errors, false
|
|
144
|
+
app.set :show_exceptions, false
|
|
145
|
+
doc_path = File.join(app.settings.root, '../../doc/json-schema.html')
|
|
146
|
+
allow(File).to receive(:read).and_call_original
|
|
147
|
+
allow(File).to receive(:read).with(doc_path).and_raise(Errno::EACCES, doc_path)
|
|
148
|
+
|
|
149
|
+
with_exception_mailer(mailer) do
|
|
150
|
+
get '/doc/json-schema'
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
expect(last_response.status).to eq(500)
|
|
154
|
+
expect(calls.size).to eq(1)
|
|
155
|
+
expect(calls.first[1]).to be_a(Errno::EACCES)
|
|
156
|
+
end
|
|
157
|
+
|
|
125
158
|
it 'redacts secrets from request-level exception emails' do
|
|
126
159
|
mailer = new_mailer
|
|
127
160
|
calls = collect_mail_calls(mailer)
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'open3'
|
|
5
|
+
require 'rake'
|
|
6
|
+
require 'rbconfig'
|
|
7
|
+
require 'rubygems/package'
|
|
8
|
+
require 'tmpdir'
|
|
9
|
+
|
|
10
|
+
describe HaveAPI::Server do
|
|
11
|
+
def required_docs
|
|
12
|
+
%w[json-schema.html protocol.md create-client.md typed-input-validation.md protocol.png]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
before(:context) do
|
|
16
|
+
load File.expand_path('../Rakefile', __dir__)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def invoke_build
|
|
20
|
+
Rake::Task[:check_doc].reenable
|
|
21
|
+
Rake::Task[:build].reenable
|
|
22
|
+
Rake::Task[:build].invoke
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
%i[missing empty].each do |condition|
|
|
26
|
+
it "rejects a direct build with #{condition} shared documentation" do
|
|
27
|
+
Dir.mktmpdir('haveapi-doc-check') do |dir|
|
|
28
|
+
FileUtils.mkdir_p(File.join(dir, 'doc'))
|
|
29
|
+
required_docs.each do |name|
|
|
30
|
+
next if name == 'json-schema.html' && condition == :missing
|
|
31
|
+
|
|
32
|
+
content = name == 'json-schema.html' && condition == :empty ? '' : 'document'
|
|
33
|
+
File.write(File.join(dir, 'doc', name), content)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
Dir.chdir(dir) do
|
|
37
|
+
expect do
|
|
38
|
+
expect { invoke_build }.to raise_error(SystemExit) do |error|
|
|
39
|
+
expect(error.status).to eq(1)
|
|
40
|
+
end
|
|
41
|
+
end.to output(/json-schema.html.*Run `make doc`/).to_stderr
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'ships and serves shared documentation from the built gem' do
|
|
48
|
+
invoke_build
|
|
49
|
+
gem_path = File.expand_path("../pkg/haveapi-#{HaveAPI::VERSION}.gem", __dir__)
|
|
50
|
+
|
|
51
|
+
Dir.mktmpdir('haveapi-package') do |dir|
|
|
52
|
+
Gem::Package.new(gem_path).extract_files(dir)
|
|
53
|
+
required_docs.each do |name|
|
|
54
|
+
expect(File.read(File.join(dir, 'doc', name))).not_to be_empty
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
script = <<~RUBY
|
|
58
|
+
require 'haveapi'
|
|
59
|
+
require 'rack/mock'
|
|
60
|
+
|
|
61
|
+
module PackagedAPI
|
|
62
|
+
class Test < HaveAPI::Resource
|
|
63
|
+
version 1
|
|
64
|
+
auth false
|
|
65
|
+
|
|
66
|
+
class Index < HaveAPI::Actions::Default::Index
|
|
67
|
+
authorize { allow }
|
|
68
|
+
def exec
|
|
69
|
+
[]
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
server = HaveAPI::Server.new(PackagedAPI)
|
|
76
|
+
server.use_version(1)
|
|
77
|
+
server.mount('/')
|
|
78
|
+
request = Rack::MockRequest.new(server.app)
|
|
79
|
+
responses = %w[/doc/json-schema /doc/protocol.md /doc/create-client.md].to_h do |path|
|
|
80
|
+
response = request.get(path, 'HTTP_HOST' => 'localhost')
|
|
81
|
+
[path, { status: response.status, type: response.content_type, body: response.body }]
|
|
82
|
+
end
|
|
83
|
+
puts JSON.generate({
|
|
84
|
+
framework: HaveAPI::Server.instance_method(:mount).source_location.first,
|
|
85
|
+
responses: responses
|
|
86
|
+
})
|
|
87
|
+
RUBY
|
|
88
|
+
|
|
89
|
+
empty_gem_home = File.join(dir, 'empty-gems')
|
|
90
|
+
original_env = Bundler.original_env.merge('GEM_HOME' => empty_gem_home, 'GEM_PATH' => empty_gem_home)
|
|
91
|
+
allow(Bundler).to receive(:original_env).and_return(original_env)
|
|
92
|
+
|
|
93
|
+
# Retain Bundler's resolved gem paths for installations such as vendor/bundle.
|
|
94
|
+
child_env = {
|
|
95
|
+
'GEM_HOME' => Gem.dir,
|
|
96
|
+
'GEM_PATH' => Gem.path.join(File::PATH_SEPARATOR),
|
|
97
|
+
'RUBYLIB' => nil,
|
|
98
|
+
'RUBYOPT' => nil
|
|
99
|
+
}
|
|
100
|
+
stdout, stderr, status = Bundler.with_unbundled_env do
|
|
101
|
+
Open3.capture3(
|
|
102
|
+
child_env,
|
|
103
|
+
RbConfig.ruby, '-I', File.join(dir, 'lib'), '-e', script,
|
|
104
|
+
'-I', File.join(Gem.loaded_specs.fetch('haveapi-client').full_gem_path, 'lib'),
|
|
105
|
+
chdir: dir
|
|
106
|
+
)
|
|
107
|
+
end
|
|
108
|
+
expect(status.success?).to be(true), "Packaged server failed: #{stderr}"
|
|
109
|
+
result = JSON.parse(stdout)
|
|
110
|
+
expect(File.realpath(result.fetch('framework'))).to eq(File.join(dir, 'lib/haveapi/server.rb'))
|
|
111
|
+
|
|
112
|
+
{
|
|
113
|
+
'/doc/json-schema' => 'Envelope',
|
|
114
|
+
'/doc/protocol.md' => 'Protocol definition',
|
|
115
|
+
'/doc/create-client.md' => 'Client definition'
|
|
116
|
+
}.each do |path, heading|
|
|
117
|
+
response = result.fetch('responses').fetch(path)
|
|
118
|
+
expect(response.fetch('status')).to eq(200), "Packaged route failed: #{path}"
|
|
119
|
+
expect(response.fetch('type')).to include('text/html')
|
|
120
|
+
expect(response.fetch('body')).to include(heading)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: haveapi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.29.
|
|
4
|
+
version: 0.29.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jakub Skokan
|
|
@@ -29,14 +29,14 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - "~>"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: 0.29.
|
|
32
|
+
version: 0.29.9
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: 0.29.
|
|
39
|
+
version: 0.29.9
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: i18n
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -210,8 +210,13 @@ files:
|
|
|
210
210
|
- LICENSE.txt
|
|
211
211
|
- README.md
|
|
212
212
|
- Rakefile
|
|
213
|
+
- doc/create-client.md
|
|
213
214
|
- doc/hooks.erb
|
|
214
215
|
- doc/index.md
|
|
216
|
+
- doc/json-schema.html
|
|
217
|
+
- doc/protocol.md
|
|
218
|
+
- doc/protocol.png
|
|
219
|
+
- doc/typed-input-validation.md
|
|
215
220
|
- haveapi.gemspec
|
|
216
221
|
- lib/haveapi.rb
|
|
217
222
|
- lib/haveapi/action.rb
|
|
@@ -338,6 +343,7 @@ files:
|
|
|
338
343
|
- spec/hooks_spec.rb
|
|
339
344
|
- spec/i18n_spec.rb
|
|
340
345
|
- spec/model_adapters/active_record_spec.rb
|
|
346
|
+
- spec/packaging_spec.rb
|
|
341
347
|
- spec/parameters/typed_spec.rb
|
|
342
348
|
- spec/params_spec.rb
|
|
343
349
|
- spec/resource_spec.rb
|