apipie-rails 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -1
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -1
- data/README.rst +105 -0
- data/apipie-rails.gemspec +1 -0
- data/app/controllers/apipie/apipies_controller.rb +18 -2
- data/lib/apipie-rails.rb +1 -0
- data/lib/apipie/apipie_module.rb +5 -0
- data/lib/apipie/application.rb +23 -3
- data/lib/apipie/configuration.rb +13 -2
- data/lib/apipie/extractor.rb +2 -4
- data/lib/apipie/swagger_generator.rb +545 -0
- data/lib/apipie/validator.rb +4 -0
- data/lib/apipie/version.rb +1 -1
- data/lib/tasks/apipie.rake +95 -1
- data/spec/controllers/apipies_controller_spec.rb +38 -0
- data/spec/dummy/app/controllers/users_controller.rb +5 -0
- data/spec/dummy/config/routes.rb +5 -0
- data/spec/lib/swagger/openapi_2_0_schema.json +1607 -0
- data/spec/lib/swagger/rake_swagger_spec.rb +127 -0
- metadata +22 -3
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "json-schema"
|
3
|
+
|
4
|
+
describe 'rake tasks' do
|
5
|
+
include_context "rake"
|
6
|
+
|
7
|
+
let(:doc_path) { "user_specified_doc_path" }
|
8
|
+
|
9
|
+
before do
|
10
|
+
Apipie.configuration.doc_path = doc_path
|
11
|
+
Apipie.configuration.swagger_suppress_warnings = true
|
12
|
+
allow(Apipie).to receive(:reload_documentation)
|
13
|
+
subject.invoke(*task_args)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'static swagger specification files' do
|
17
|
+
|
18
|
+
after do
|
19
|
+
Dir["#{doc_output}*"].each { |static_file| FileUtils.rm_rf(static_file) }
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:swagger_schema) do
|
23
|
+
File.read(File.join(File.dirname(__FILE__),"openapi_2_0_schema.json"))
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:apidoc_swagger_json) do
|
27
|
+
# note: the filename ends with '_tmp' because this suffix is passed as a parameter to the rake task
|
28
|
+
File.read("#{doc_output}/schema_swagger_tmp.json")
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:apidoc_swagger) do
|
32
|
+
JSON.parse(apidoc_swagger_json)
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:doc_output) do
|
36
|
+
File.join(::Rails.root, doc_path, 'apidoc')
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:ref_output) do
|
40
|
+
File.join(::Rails.root, doc_path, 'apidoc_ref')
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def expect_param_def(http_method, path, param_name, field, value)
|
45
|
+
params = apidoc_swagger["paths"][path][http_method]["parameters"]
|
46
|
+
param = params.select {|p| p if p["name"]==param_name}[0]
|
47
|
+
expect(param[field]).to eq(value)
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def body_param_def(http_method, path, param_name)
|
52
|
+
params = apidoc_swagger["paths"][path][http_method]["parameters"]
|
53
|
+
body = params.select {|p| p if p["name"]=="body"}[0]
|
54
|
+
schema_properties = body["schema"]["properties"]
|
55
|
+
# print JSON.pretty_generate(schema_properties)
|
56
|
+
param = (schema_properties.select {|k,v| v if k == param_name })[param_name]
|
57
|
+
# print JSON.pretty_generate(param)
|
58
|
+
param
|
59
|
+
end
|
60
|
+
|
61
|
+
def expect_body_param_def(http_method, path, param_name, field, value)
|
62
|
+
param = body_param_def(http_method, path, param_name)
|
63
|
+
expect(param[field]).to eq(value)
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
describe 'apipie:static_swagger_json[development,json,_tmp]' do
|
68
|
+
it "generates static swagger files for the default version of apipie docs" do
|
69
|
+
# print apidoc_swagger_json
|
70
|
+
|
71
|
+
expect(apidoc_swagger["info"]["title"]).to eq("Test app (params in:body)")
|
72
|
+
expect(apidoc_swagger["info"]["version"]).to eq("#{Apipie.configuration.default_version}")
|
73
|
+
end
|
74
|
+
|
75
|
+
it "includes expected values in the generated swagger file" do
|
76
|
+
expect_param_def("get", "/twitter_example/{id}", "screen_name", "in", "query")
|
77
|
+
expect_param_def("put", "/users/{id}", "id", "in", "path")
|
78
|
+
expect_body_param_def("put", "/users/{id}", "oauth", "type", "string")
|
79
|
+
expect_body_param_def("put", "/users/{id}", "user", "type", "object")
|
80
|
+
|
81
|
+
user = body_param_def("put", "/users/{id}", "user")
|
82
|
+
expect(user["properties"]["name"]["type"]).to eq("string")
|
83
|
+
|
84
|
+
expect_param_def("get", "/users/by_department", "department", "in", "query")
|
85
|
+
expect_param_def("get", "/users/by_department", "department", "enum",
|
86
|
+
["finance", "operations", "sales", "marketing", "HR"])
|
87
|
+
end
|
88
|
+
|
89
|
+
it "generates a valid swagger file" do
|
90
|
+
# print apidoc_swagger_json
|
91
|
+
expect(JSON::Validator.validate(swagger_schema, apidoc_swagger_json)).to be_truthy
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'apipie:static_swagger_json[development,form_data,_tmp]' do
|
96
|
+
it "generates static swagger files for the default version of apipie docs" do
|
97
|
+
# print apidoc_swagger_json
|
98
|
+
|
99
|
+
expect(apidoc_swagger["info"]["title"]).to eq("Test app (params in:formData)")
|
100
|
+
expect(apidoc_swagger["info"]["version"]).to eq("#{Apipie.configuration.default_version}")
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
it "includes expected values in the generated swagger file" do
|
105
|
+
expect_param_def("get", "/twitter_example/{id}", "screen_name", "in", "query")
|
106
|
+
expect_param_def("put", "/users/{id}", "id", "in", "path")
|
107
|
+
expect_param_def("put", "/users/{id}", "oauth", "in", "formData")
|
108
|
+
expect_param_def("get", "/users/by_department", "department", "in", "query")
|
109
|
+
expect_param_def("get", "/users/by_department", "department", "enum",
|
110
|
+
["finance", "operations", "sales", "marketing", "HR"])
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
it "generates a valid swagger file" do
|
115
|
+
# print apidoc_swagger_json
|
116
|
+
expect(JSON::Validator.validate(swagger_schema, apidoc_swagger_json)).to be_truthy
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'apipie:did_swagger_change[development,form_data,_tmp]' do
|
121
|
+
it "keeps a reference file" do
|
122
|
+
expect(Pathname(ref_output).children.count).to eq(2) # one file for each language
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apipie-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Pokorny
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-03-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -123,6 +123,20 @@ dependencies:
|
|
123
123
|
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: json-schema
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '2.8'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '2.8'
|
126
140
|
description: Rails REST API documentation tool
|
127
141
|
email:
|
128
142
|
- pajkycz@gmail.com
|
@@ -210,6 +224,7 @@ files:
|
|
210
224
|
- lib/apipie/routing.rb
|
211
225
|
- lib/apipie/see_description.rb
|
212
226
|
- lib/apipie/static_dispatcher.rb
|
227
|
+
- lib/apipie/swagger_generator.rb
|
213
228
|
- lib/apipie/validator.rb
|
214
229
|
- lib/apipie/version.rb
|
215
230
|
- lib/generators/apipie/install/README
|
@@ -279,6 +294,8 @@ files:
|
|
279
294
|
- spec/lib/param_group_spec.rb
|
280
295
|
- spec/lib/rake_spec.rb
|
281
296
|
- spec/lib/resource_description_spec.rb
|
297
|
+
- spec/lib/swagger/openapi_2_0_schema.json
|
298
|
+
- spec/lib/swagger/rake_swagger_spec.rb
|
282
299
|
- spec/lib/validator_spec.rb
|
283
300
|
- spec/lib/validators/array_validator_spec.rb
|
284
301
|
- spec/spec_helper.rb
|
@@ -302,7 +319,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
302
319
|
version: '0'
|
303
320
|
requirements: []
|
304
321
|
rubyforge_project:
|
305
|
-
rubygems_version: 2.
|
322
|
+
rubygems_version: 2.5.1
|
306
323
|
signing_key:
|
307
324
|
specification_version: 4
|
308
325
|
summary: Rails REST API documentation tool
|
@@ -366,6 +383,8 @@ test_files:
|
|
366
383
|
- spec/lib/param_group_spec.rb
|
367
384
|
- spec/lib/rake_spec.rb
|
368
385
|
- spec/lib/resource_description_spec.rb
|
386
|
+
- spec/lib/swagger/openapi_2_0_schema.json
|
387
|
+
- spec/lib/swagger/rake_swagger_spec.rb
|
369
388
|
- spec/lib/validator_spec.rb
|
370
389
|
- spec/lib/validators/array_validator_spec.rb
|
371
390
|
- spec/spec_helper.rb
|