apiaryio 0.10.2 → 0.11.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 +4 -4
- data/.rubocop_todo.yml +2 -2
- data/README.md +1 -0
- data/lib/apiary/cli.rb +1 -0
- data/lib/apiary/command/preview.rb +6 -6
- data/lib/apiary/command/styleguide.rb +34 -5
- data/lib/apiary/file_templates/preview.erb +6 -6
- data/lib/apiary/version.rb +1 -1
- data/spec/apiary/command/styleguide_spec.rb +44 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5756528c3736e0906c6b0548508705fb4b43c601
|
4
|
+
data.tar.gz: 9910234e8ac83f76eca23712bccc01be7c9e28c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edfda0ff24e9ee17001f1ebf3365908e95b76e5308d6af714db4b80de06e97f2dd8b29377a4bdb147882be82f4e46106b5c76143d489ff071cd32ff98d8deee6
|
7
|
+
data.tar.gz: 8460c8eea49d4ef58681e7c1c5d4d52a3265b8353c43eeca82200f6afca7e4000d7fbb636e57c4fa103edf31d54d6e6a282c5e050b82780119c53f889cab1b11
|
data/.rubocop_todo.yml
CHANGED
@@ -10,10 +10,10 @@ Metrics/AbcSize:
|
|
10
10
|
Max: 33
|
11
11
|
|
12
12
|
Metrics/BlockLength:
|
13
|
-
Max:
|
13
|
+
Max: 200
|
14
14
|
|
15
15
|
Metrics/ClassLength:
|
16
|
-
Max:
|
16
|
+
Max: 250 # or whatever ends up being appropriate
|
17
17
|
|
18
18
|
Metrics/PerceivedComplexity:
|
19
19
|
Max: 12
|
data/README.md
CHANGED
@@ -132,6 +132,7 @@ Usage:
|
|
132
132
|
|
133
133
|
Options:
|
134
134
|
[--fetch], [--no-fetch] # Fetch styleguide rules and functions from apiary.io
|
135
|
+
[--push], [--no-push] # Push styleguide rules and functions to apiary.io
|
135
136
|
[--add=ADD] # Path to API Description Document. When given a directory, it will look for `apiary.apib` and `swagger.yaml` file
|
136
137
|
[--functions=FUNCTIONS] # Path to to the file with functions definitions
|
137
138
|
[--rules=RULES] # Path to to the file with rules definitions - `functions.js` and `rules.json` are loaded if not specified
|
data/lib/apiary/cli.rb
CHANGED
@@ -49,6 +49,7 @@ module Apiary
|
|
49
49
|
|
50
50
|
desc 'styleguide', 'Check API Description Document against styleguide rules (Apiary.io pro plan is required - https://apiary.io/plans )'
|
51
51
|
method_option :fetch, type: :boolean, desc: 'Fetch styleguide rules and functions from apiary.io'
|
52
|
+
method_option :push, type: :boolean, desc: 'Push styleguide rules and functions to apiary.io'
|
52
53
|
method_option :add, type: :string, desc: 'Path to API Description Document. When given a directory, it will look for `apiary.apib` and `swagger.yaml` file'
|
53
54
|
method_option :functions, type: :string, desc: 'Path to to the file with functions definitions'
|
54
55
|
method_option :rules, type: :string, desc: 'Path to to the file with rules definitions - `functions.js` and `rules.json` are loaded if not specified'
|
@@ -49,7 +49,7 @@ module Apiary::Command
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def execute
|
52
|
-
if @options.server
|
52
|
+
if @options.server || @options.watch
|
53
53
|
watch
|
54
54
|
server
|
55
55
|
else
|
@@ -70,15 +70,15 @@ module Apiary::Command
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def server
|
73
|
-
generate_app = get_app('/') do
|
73
|
+
generate_app = get_app(path: '/') do
|
74
74
|
generate
|
75
75
|
end
|
76
76
|
|
77
|
-
change_app = get_app('/changed') do
|
77
|
+
change_app = get_app(path: '/changed', options: { 'Content-Type' => 'text/plain' }) do
|
78
78
|
@changed
|
79
79
|
end
|
80
80
|
|
81
|
-
source_app = get_app('/source') do
|
81
|
+
source_app = get_app(path: '/source', options: { 'Content-Type' => 'text/plain' }) do
|
82
82
|
api_description_source(@source_path)
|
83
83
|
end
|
84
84
|
|
@@ -99,10 +99,10 @@ module Apiary::Command
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
-
def get_app(path)
|
102
|
+
def get_app(path: '/', options: {})
|
103
103
|
Rack::Builder.new do
|
104
104
|
map path do
|
105
|
-
run ->(env) { [200,
|
105
|
+
run ->(env) { [200, options, [yield]] }
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
@@ -36,11 +36,37 @@ module Apiary::Command
|
|
36
36
|
check_api_key
|
37
37
|
if @options.fetch
|
38
38
|
fetch
|
39
|
+
elsif @options.push
|
40
|
+
push
|
39
41
|
else
|
40
42
|
validate
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
46
|
+
def push
|
47
|
+
begin
|
48
|
+
load(add: false)
|
49
|
+
rescue StandardError => e
|
50
|
+
abort "Error: #{e.message}"
|
51
|
+
end
|
52
|
+
|
53
|
+
path = 'styleguide-cli/set-assertions/'
|
54
|
+
headers = @options.headers.clone
|
55
|
+
headers[:authentication] = "Token #{@options.api_key}"
|
56
|
+
|
57
|
+
data = {
|
58
|
+
functions: @functions,
|
59
|
+
rules: @rules
|
60
|
+
}.to_json
|
61
|
+
|
62
|
+
begin
|
63
|
+
call_apiary(path, data, headers, :post)
|
64
|
+
rescue => e
|
65
|
+
puts e
|
66
|
+
abort "Error: Can not write into the rules/functions file: #{e}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
44
70
|
def fetch
|
45
71
|
begin
|
46
72
|
assertions = fetch_from_apiary
|
@@ -82,6 +108,7 @@ module Apiary::Command
|
|
82
108
|
|
83
109
|
headers = @options.headers.clone
|
84
110
|
headers[:Authorization] = "Bearer #{token}"
|
111
|
+
headers['Accept-Encoding'] = 'identity'
|
85
112
|
|
86
113
|
output call_resource(@options.vk_url, data, headers, :post)
|
87
114
|
end
|
@@ -195,11 +222,13 @@ module Apiary::Command
|
|
195
222
|
abort 'Error: API key must be provided through environment variable APIARY_API_KEY. \Please go to https://login.apiary.io/tokens to obtain it.'
|
196
223
|
end
|
197
224
|
|
198
|
-
def load
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
225
|
+
def load(add: true, functions: true, rules: true)
|
226
|
+
if add
|
227
|
+
@add_path = api_description_source_path(@options.add)
|
228
|
+
@add = api_description_source(@add_path)
|
229
|
+
end
|
230
|
+
@functions = get_functions(@options.functions) if functions
|
231
|
+
@rules = get_rules(@options.rules) if rules
|
203
232
|
end
|
204
233
|
|
205
234
|
def fetch_from_apiary
|
@@ -12,7 +12,7 @@
|
|
12
12
|
});
|
13
13
|
|
14
14
|
if (<%= data[:watch] %>) {
|
15
|
-
var changed = null
|
15
|
+
var changed = null;
|
16
16
|
var xhrChanged = new XMLHttpRequest();
|
17
17
|
var xhrData = new XMLHttpRequest();
|
18
18
|
setInterval(function() {
|
@@ -20,18 +20,18 @@
|
|
20
20
|
xhrChanged.send();
|
21
21
|
|
22
22
|
xhrChanged.onreadystatechange = function() {
|
23
|
-
if (xhrChanged.readyState
|
23
|
+
if (xhrChanged.readyState === 4 && xhrChanged.status === 200) {
|
24
24
|
if (!changed) {
|
25
|
-
changed = xhrChanged.responseText
|
25
|
+
changed = xhrChanged.responseText;
|
26
26
|
}
|
27
27
|
if (changed != xhrChanged.responseText) {
|
28
|
-
changed = xhrChanged.responseText
|
28
|
+
changed = xhrChanged.responseText;
|
29
29
|
xhrData.open('GET', window.location.href + "/source", true);
|
30
30
|
xhrData.send();
|
31
31
|
|
32
32
|
xhrData.onreadystatechange = function() {
|
33
|
-
if (xhrData.readyState
|
34
|
-
embed.
|
33
|
+
if (xhrData.readyState === 4 && xhrData.status === 200) {
|
34
|
+
window[embed.adaptee.id].contentWindow.postMessage({"origin": "Apiary.Embed", "eventType": "anonymousPreview", "data": {"code": xhrData.responseText}}, '*');
|
35
35
|
}
|
36
36
|
}
|
37
37
|
}
|
data/lib/apiary/version.rb
CHANGED
@@ -172,4 +172,48 @@ describe Apiary::Command::Styleguide do
|
|
172
172
|
end.to output("[\n\n]\n").to_stdout
|
173
173
|
end
|
174
174
|
end
|
175
|
+
|
176
|
+
describe 'push' do
|
177
|
+
it 'call command without APIARY_API_KEY set' do
|
178
|
+
opts = {
|
179
|
+
push: true,
|
180
|
+
api_key: '',
|
181
|
+
functions: 'features/support',
|
182
|
+
rules: 'features/support'
|
183
|
+
}
|
184
|
+
command = Apiary::Command::Styleguide.new(opts)
|
185
|
+
test_abort(command, 'Error: API key must be provided through environment variable APIARY_API_KEY.')
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'call command with incorrect APIARY_API_KEY' do
|
189
|
+
opts = {
|
190
|
+
push: true,
|
191
|
+
api_key: 'xxx'
|
192
|
+
}
|
193
|
+
|
194
|
+
command = Apiary::Command::Styleguide.new(opts)
|
195
|
+
stub_request(:post, "https://#{command.options.api_host}/styleguide-cli/set-assertions/").to_return(status: [403, 'This resource requires authenticated API call.'])
|
196
|
+
|
197
|
+
test_abort(command, 'Error: Apiary service responded with: 403')
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'call command with correct APIARY_API_KEY' do
|
201
|
+
opts = {
|
202
|
+
push: true,
|
203
|
+
api_key: 'xxx',
|
204
|
+
functions: 'function testFunction(data) { return "failed"; }',
|
205
|
+
rules: '[{"ruleName": "testName","functionName": "testFunction","target": "Request_Body","intent": "testIntent"}]'
|
206
|
+
}
|
207
|
+
|
208
|
+
command = Apiary::Command::Styleguide.new(opts)
|
209
|
+
stub_request(:post, "https://#{command.options.api_host}/styleguide-cli/set-assertions/").to_return(status: 200, body: '')
|
210
|
+
|
211
|
+
expect do
|
212
|
+
begin
|
213
|
+
command.execute
|
214
|
+
rescue SystemExit
|
215
|
+
end
|
216
|
+
end.to output('').to_stdout
|
217
|
+
end
|
218
|
+
end
|
175
219
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apiaryio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Apiary Ltd.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|