swagger-docs 0.1.9 → 0.2.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 +6 -2
- data/README.md +53 -3
- data/lib/swagger/docs/config.rb +25 -1
- data/lib/swagger/docs/dsl.rb +1 -0
- data/lib/swagger/docs/generator.rb +10 -6
- data/lib/swagger/docs/version.rb +1 -1
- data/spec/fixtures/controllers/sample_controller.rb +2 -2
- data/spec/lib/swagger/docs/config_spec.rb +12 -3
- data/spec/lib/swagger/docs/dsl_spec.rb +2 -2
- data/spec/lib/swagger/docs/generator_spec.rb +35 -21
- data/swagger-docs.gemspec +2 -2
- metadata +4 -26
- checksums.yaml.gz.sig +0 -2
- data.tar.gz.sig +0 -3
- metadata.gz.sig +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 979bda39f8d785e5d599ae56058247e02b9c8335
|
4
|
+
data.tar.gz: d2e4e3cc8356e686e72376012249ca2ee1c00375
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f409fe0f7a4b448fbfe63c276c1ecb8faf5d9242e3f06d4864950c1df97a497542dc153c8a1b4b8c630d7d499e4040dae7ae58a45f89e6f0a7febea327a0062b
|
7
|
+
data.tar.gz: 7b6ec4109fea5d965160218f77a89b3630bc89987660556c703bb9cb2419c82263c87d076d2cb1d57a424515ae4f7d334cf88d59ebe7c68e5efd72e9ff1122d1
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
## 0.
|
1
|
+
## 0.2.0
|
2
2
|
|
3
|
-
|
3
|
+
- Additional logging for generation failures (suggested in #81)
|
4
|
+
- Added api_file_name to config #88
|
5
|
+
- Add support for multiple base api controllers. #93
|
6
|
+
- Change success status to ok #89
|
7
|
+
- Address issue with missing slashes - remove trailing slash from base paths and add slash before api paths #117
|
4
8
|
|
5
9
|
## 0.1.9
|
6
10
|
|
data/README.md
CHANGED
@@ -105,8 +105,8 @@ The following table shows all the current configuration options and their defaul
|
|
105
105
|
</tr>
|
106
106
|
|
107
107
|
<tr>
|
108
|
-
<td><b>base_api_controller</b></td>
|
109
|
-
<td>The base controller class your project uses; it or its subclasses will be where you call swagger_controller and swagger_api.</td>
|
108
|
+
<td><b>base_api_controller / base_api_controllers</b></td>
|
109
|
+
<td>The base controller class your project uses; it or its subclasses will be where you call swagger_controller and swagger_api. An array of base controller classes may be provided.</td>
|
110
110
|
<td>ActionController::Base</td>
|
111
111
|
</tr>
|
112
112
|
|
@@ -152,7 +152,7 @@ class Api::V1::UsersController < ApplicationController
|
|
152
152
|
swagger_api :show do
|
153
153
|
summary "Fetches a single User item"
|
154
154
|
param :path, :id, :integer, :optional, "User Id"
|
155
|
-
response :
|
155
|
+
response :ok, "Success", :User
|
156
156
|
response :unauthorized
|
157
157
|
response :not_acceptable
|
158
158
|
response :not_found
|
@@ -228,6 +228,39 @@ end
|
|
228
228
|
|
229
229
|
And then use it as a superclass to all you API controllers. All the subclassed controllers will have the same documentation applied to them.
|
230
230
|
|
231
|
+
#### Alternate method
|
232
|
+
|
233
|
+
Using a block for the swagger_api definition:
|
234
|
+
|
235
|
+
```ruby
|
236
|
+
class Api::V1::UserController < Api::V1::BaseController
|
237
|
+
|
238
|
+
swagger_controller :user, "Users"
|
239
|
+
|
240
|
+
def self.add_common_params(api)
|
241
|
+
api.param :form, "user[first_name]", :string, :optional, "Notes"
|
242
|
+
api.param :form, "user[last_name]", :string, :optional, "Name"
|
243
|
+
api.param :form, "user[email]", :string, :optional, "Email"
|
244
|
+
end
|
245
|
+
|
246
|
+
swagger_api :create do |api|
|
247
|
+
summary "Create a new User item"
|
248
|
+
Api::V1::UserController::add_common_params(api)
|
249
|
+
response :unauthorized
|
250
|
+
response :not_acceptable
|
251
|
+
response :unprocessable_entity
|
252
|
+
end
|
253
|
+
|
254
|
+
swagger_api :update do |api|
|
255
|
+
summary "Update an existing User item"
|
256
|
+
Api::V1::UserController::add_common_params(api)
|
257
|
+
response :unauthorized
|
258
|
+
response :not_acceptable
|
259
|
+
response :unprocessable_entity
|
260
|
+
end
|
261
|
+
end
|
262
|
+
```
|
263
|
+
|
231
264
|
### DSL Methods
|
232
265
|
|
233
266
|
<table>
|
@@ -275,6 +308,20 @@ rake swagger:docs
|
|
275
308
|
|
276
309
|
Swagger-ui JSON files should now be present in your api_file_path (e.g. ./public/api/v1)
|
277
310
|
|
311
|
+
#### Additional logging for generation failures
|
312
|
+
|
313
|
+
Errors aren't displayed by default. To see all error messages use the ```SD_LOG_LEVEL``` environment variable when running the rake task:
|
314
|
+
|
315
|
+
```
|
316
|
+
SD_LOG_LEVEL=1 rake swagger:docs
|
317
|
+
```
|
318
|
+
|
319
|
+
Currently only constantize errors are shown.
|
320
|
+
|
321
|
+
Errors are written to ```$stderr```. Error logging methods can be found in ```Config``` and can be overridden for custom behaviour.
|
322
|
+
|
323
|
+
Thanks to **[@tomtt](https://github.com/tomtt/)** who originally suggested this idea in #81
|
324
|
+
|
278
325
|
### Sample
|
279
326
|
|
280
327
|
A sample Rails application where you can run the above rake command and view the output in swagger-ui can be found here:
|
@@ -660,6 +707,9 @@ Thanks to jdar, fotinakis, stevschmid, ldnunes, aaronrenner and all of our contr
|
|
660
707
|
|
661
708
|
**[@fotinakis](https://github.com/fotinakis/)** has created Swagger::Blocks - a DSL for pure Ruby code blocks: [swagger-blocks](https://github.com/fotinakis/swagger-blocks/)
|
662
709
|
|
710
|
+
A [cors rack middleware for testing swagger apis](https://gist.github.com/richhollis/b98a8b0599860145ad86) designed to be used in Rails development environments.
|
711
|
+
|
712
|
+
|
663
713
|
## More About Me
|
664
714
|
|
665
715
|
[Rich Hollis](http://richhollis.co.uk)
|
data/lib/swagger/docs/config.rb
CHANGED
@@ -8,10 +8,16 @@ module Swagger
|
|
8
8
|
@@base_api_controller || ActionController::Base
|
9
9
|
end
|
10
10
|
|
11
|
+
def base_api_controllers
|
12
|
+
Array(base_api_controller)
|
13
|
+
end
|
14
|
+
|
11
15
|
def base_api_controller=(controller)
|
12
16
|
@@base_api_controller = controller
|
13
17
|
end
|
14
18
|
|
19
|
+
alias_method :base_api_controllers=, :base_api_controller=
|
20
|
+
|
15
21
|
def base_applications
|
16
22
|
Array(base_application)
|
17
23
|
end
|
@@ -21,7 +27,9 @@ module Swagger
|
|
21
27
|
end
|
22
28
|
|
23
29
|
def register_apis(versions)
|
24
|
-
|
30
|
+
base_api_controllers.each do |controller|
|
31
|
+
controller.send(:include, ImpotentMethods)
|
32
|
+
end
|
25
33
|
@versions = versions
|
26
34
|
end
|
27
35
|
|
@@ -33,6 +41,22 @@ module Swagger
|
|
33
41
|
# This is only for overriding, so don't perform any path transformations by default.
|
34
42
|
path
|
35
43
|
end
|
44
|
+
|
45
|
+
def log_exception
|
46
|
+
yield
|
47
|
+
rescue => e
|
48
|
+
write_log(:error, e)
|
49
|
+
raise
|
50
|
+
end
|
51
|
+
|
52
|
+
def log_env_name
|
53
|
+
'SD_LOG_LEVEL'
|
54
|
+
end
|
55
|
+
|
56
|
+
def write_log(type, output)
|
57
|
+
$stderr.puts output if type == :error and ENV[log_env_name]=="1"
|
58
|
+
end
|
59
|
+
|
36
60
|
end
|
37
61
|
end
|
38
62
|
end
|
data/lib/swagger/docs/dsl.rb
CHANGED
@@ -58,6 +58,7 @@ module Swagger
|
|
58
58
|
|
59
59
|
def response(status, text = nil, model = nil)
|
60
60
|
if status.is_a? Symbol
|
61
|
+
status == :ok if status == :success
|
61
62
|
status_code = Rack::Utils.status_code(status)
|
62
63
|
response_messages << {:code => status_code, :responseModel => model, :message => text || status.to_s.titleize}
|
63
64
|
else
|
@@ -5,6 +5,7 @@ module Swagger
|
|
5
5
|
DEFAULT_VER = "1.0"
|
6
6
|
DEFAULT_CONFIG = {
|
7
7
|
:api_file_path => "public/",
|
8
|
+
:api_file_name => "api-docs.json",
|
8
9
|
:base_path => "/",
|
9
10
|
:clean_directory => false,
|
10
11
|
:formatting => :pretty
|
@@ -13,7 +14,10 @@ module Swagger
|
|
13
14
|
class << self
|
14
15
|
|
15
16
|
def set_real_methods
|
16
|
-
|
17
|
+
# replace impotent methods with live ones
|
18
|
+
Config.base_api_controllers.each do |controller|
|
19
|
+
controller.send(:include, Methods)
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
def write_docs(apis = nil)
|
@@ -30,7 +34,7 @@ module Swagger
|
|
30
34
|
resources = root.delete 'resources'
|
31
35
|
root.merge!(config[:attributes] || {}) # merge custom user attributes like info
|
32
36
|
# write the api-docs file
|
33
|
-
write_to_file("#{settings[:api_file_path]}
|
37
|
+
write_to_file("#{settings[:api_file_path]}/#{config[:api_file_name]}", root, config)
|
34
38
|
# write the individual resource files
|
35
39
|
resources.each do |resource|
|
36
40
|
resource_file_path = resource.delete 'resourceFilePath'
|
@@ -57,7 +61,7 @@ module Swagger
|
|
57
61
|
end
|
58
62
|
|
59
63
|
def generate_doc(api_version, settings, config)
|
60
|
-
root = { "apiVersion" => api_version, "swaggerVersion" => "1.2", "basePath" => settings[:base_path]
|
64
|
+
root = { "apiVersion" => api_version, "swaggerVersion" => "1.2", "basePath" => settings[:base_path], :apis => [] }
|
61
65
|
results = {:processed => [], :skipped => []}
|
62
66
|
resources = []
|
63
67
|
|
@@ -68,7 +72,7 @@ module Swagger
|
|
68
72
|
resources << generate_resource(ret[:path], ret[:apis], ret[:models], settings, root, config)
|
69
73
|
debased_path = get_debased_path(ret[:path], settings[:controller_base_path])
|
70
74
|
resource_api = {
|
71
|
-
path: "
|
75
|
+
path: "/#{Config.transform_path(trim_leading_slash(debased_path), api_version)}.{format}",
|
72
76
|
description: ret[:klass].swagger_config[:description]
|
73
77
|
}
|
74
78
|
root[:apis] << resource_api
|
@@ -86,7 +90,7 @@ module Swagger
|
|
86
90
|
api_path.gsub!('(.:format)', extension ? ".#{extension}" : '')
|
87
91
|
api_path.gsub!(/:(\w+)/, '{\1}')
|
88
92
|
api_path.gsub!(controller_base_path, '')
|
89
|
-
trim_slashes(api_path)
|
93
|
+
"/" + trim_slashes(api_path)
|
90
94
|
end
|
91
95
|
|
92
96
|
def camelize_keys_deep!(h)
|
@@ -123,7 +127,7 @@ module Swagger
|
|
123
127
|
|
124
128
|
def process_path(path, root, config, settings)
|
125
129
|
return {action: :skipped, reason: :empty_path} if path.empty?
|
126
|
-
klass = "#{path.to_s.camelize}Controller".constantize rescue nil
|
130
|
+
klass = Config.log_exception { "#{path.to_s.camelize}Controller".constantize } rescue nil
|
127
131
|
return {action: :skipped, path: path, reason: :klass_not_present} if !klass
|
128
132
|
return {action: :skipped, path: path, reason: :not_swagger_resource} if !klass.methods.include?(:swagger_config) or !klass.swagger_config[:controller]
|
129
133
|
apis, models, defined_nicknames = [], {}, []
|
data/lib/swagger/docs/version.rb
CHANGED
@@ -9,7 +9,7 @@ module Api
|
|
9
9
|
summary "Fetches all User items"
|
10
10
|
param :query, :page, :integer, :optional, "Page number"
|
11
11
|
param :path, :nested_id, :integer, :optional, "Team Id"
|
12
|
-
response :
|
12
|
+
response :ok, "Some text", :Tag
|
13
13
|
response :unauthorized
|
14
14
|
response :not_acceptable, "The request you made is not acceptable"
|
15
15
|
response :requested_range_not_satisfiable
|
@@ -63,7 +63,7 @@ module Api
|
|
63
63
|
swagger_api :context_dependent do
|
64
64
|
summary "An action dependent on the context of the controller " +
|
65
65
|
"class. Right now it is: " + ApplicationController.context
|
66
|
-
response :
|
66
|
+
response :ok
|
67
67
|
response :unauthorized
|
68
68
|
end
|
69
69
|
|
@@ -6,7 +6,7 @@ describe Swagger::Docs::Config do
|
|
6
6
|
|
7
7
|
let(:test_controller) { Class.new }
|
8
8
|
|
9
|
-
before(:each) do
|
9
|
+
before(:each) do
|
10
10
|
stub_const('ActionController::Base', ApplicationController)
|
11
11
|
end
|
12
12
|
|
@@ -19,7 +19,17 @@ describe Swagger::Docs::Config do
|
|
19
19
|
it "allows assignment of another class" do
|
20
20
|
subject.base_api_controller = test_controller
|
21
21
|
expect(subject.base_api_controller).to eq(test_controller)
|
22
|
-
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "::base_api_controllers" do
|
26
|
+
it "returns an array with ActionController::Base by default" do
|
27
|
+
expect(subject.base_api_controllers).to eq([ActionController::Base])
|
28
|
+
end
|
29
|
+
it "allows assignment of multiple classes" do
|
30
|
+
subject.base_api_controllers = [test_controller, ActionController::Base]
|
31
|
+
expect(subject.base_api_controllers).to eq([test_controller, ActionController::Base])
|
32
|
+
end
|
23
33
|
end
|
24
34
|
|
25
35
|
describe "::base_application" do
|
@@ -35,5 +45,4 @@ describe Swagger::Docs::Config do
|
|
35
45
|
end
|
36
46
|
end
|
37
47
|
|
38
|
-
|
39
48
|
end
|
@@ -6,8 +6,8 @@ describe Swagger::Docs::SwaggerDSL do
|
|
6
6
|
|
7
7
|
describe "#response" do
|
8
8
|
it "adds code, responseModel and message to response_messages" do
|
9
|
-
subject.response(:
|
10
|
-
expect(subject.response_messages).to eq([{:code=>
|
9
|
+
subject.response(:ok, "Some sample text", "Tag")
|
10
|
+
expect(subject.response_messages).to eq([{:code=>200, :responseModel=>"Tag", :message=>"Some sample text"}])
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -32,7 +32,7 @@ describe Swagger::Docs::Generator do
|
|
32
32
|
context "without controller base path" do
|
33
33
|
let(:config) {
|
34
34
|
{
|
35
|
-
DEFAULT_VER => {:api_file_path => "#{tmp_dir}", :base_path => "http://api.no.where"}
|
35
|
+
DEFAULT_VER => {:api_file_path => "#{tmp_dir}", :base_path => "http://api.no.where/"}
|
36
36
|
}
|
37
37
|
}
|
38
38
|
before(:each) do
|
@@ -45,13 +45,24 @@ describe Swagger::Docs::Generator do
|
|
45
45
|
let(:resources) { file_resources.read }
|
46
46
|
let(:response) { JSON.parse(resources) }
|
47
47
|
it "writes basePath correctly" do
|
48
|
-
expect(response["basePath"]).to eq "http://api.no.where
|
48
|
+
expect(response["basePath"]).to eq "http://api.no.where"
|
49
49
|
end
|
50
50
|
it "writes apis correctly" do
|
51
51
|
expect(response["apis"].count).to eq 1
|
52
52
|
end
|
53
53
|
it "writes api path correctly" do
|
54
|
-
expect(response["apis"][0]["path"]).to eq "api/v1/sample.{format}"
|
54
|
+
expect(response["apis"][0]["path"]).to eq "/api/v1/sample.{format}"
|
55
|
+
end
|
56
|
+
|
57
|
+
context "api_file_name" do
|
58
|
+
let(:api_file_name) { 'swagger-docs.json' }
|
59
|
+
let(:config) {{
|
60
|
+
DEFAULT_VER => {
|
61
|
+
:api_file_path => tmp_dir,
|
62
|
+
:api_file_name => api_file_name }
|
63
|
+
}}
|
64
|
+
let(:file_resources) { tmp_dir + api_file_name }
|
65
|
+
specify { expect(File.exists? file_resources).to be true }
|
55
66
|
end
|
56
67
|
end
|
57
68
|
context "resource file" do
|
@@ -61,7 +72,7 @@ describe Swagger::Docs::Generator do
|
|
61
72
|
let(:operations) { first["operations"] }
|
62
73
|
# {"apiVersion":"1.0","swaggerVersion":"1.2","basePath":"/api/v1","resourcePath":"/sample"
|
63
74
|
it "writes basePath correctly" do
|
64
|
-
expect(response["basePath"]).to eq "http://api.no.where
|
75
|
+
expect(response["basePath"]).to eq "http://api.no.where"
|
65
76
|
end
|
66
77
|
it "writes resourcePath correctly" do
|
67
78
|
expect(response["resourcePath"]).to eq "sample"
|
@@ -73,7 +84,7 @@ describe Swagger::Docs::Generator do
|
|
73
84
|
#"apis":[{"path":" /sample","operations":[{"summary":"Fetches all User items"
|
74
85
|
#,"method":"get","nickname":"Api::V1::Sample#index"}]
|
75
86
|
it "writes path correctly" do
|
76
|
-
expect(first["path"]).to eq "api/v1/sample"
|
87
|
+
expect(first["path"]).to eq "/api/v1/sample"
|
77
88
|
end
|
78
89
|
end
|
79
90
|
end
|
@@ -81,7 +92,7 @@ describe Swagger::Docs::Generator do
|
|
81
92
|
|
82
93
|
context "with controller base path" do
|
83
94
|
let(:config) { Swagger::Docs::Config.register_apis({
|
84
|
-
DEFAULT_VER => {:controller_base_path => "api/v1", :api_file_path => "#{tmp_dir}", :base_path => "http://api.no.where",
|
95
|
+
DEFAULT_VER => {:controller_base_path => "api/v1", :api_file_path => "#{tmp_dir}", :base_path => "http://api.no.where/",
|
85
96
|
:attributes => {
|
86
97
|
:info => {
|
87
98
|
"title" => "Swagger Sample App",
|
@@ -182,13 +193,13 @@ describe Swagger::Docs::Generator do
|
|
182
193
|
expect(response["swaggerVersion"]).to eq "1.2"
|
183
194
|
end
|
184
195
|
it "writes basePath correctly" do
|
185
|
-
expect(response["basePath"]).to eq "http://api.no.where/api/v1
|
196
|
+
expect(response["basePath"]).to eq "http://api.no.where/api/v1"
|
186
197
|
end
|
187
198
|
it "writes apis correctly" do
|
188
199
|
expect(response["apis"].count).to eq 2
|
189
200
|
end
|
190
201
|
it "writes api path correctly" do
|
191
|
-
expect(response["apis"][0]["path"]).to eq "sample.{format}"
|
202
|
+
expect(response["apis"][0]["path"]).to eq "/sample.{format}"
|
192
203
|
end
|
193
204
|
it "writes api description correctly" do
|
194
205
|
expect(response["apis"][0]["description"]).to eq "User Management"
|
@@ -200,8 +211,8 @@ describe Swagger::Docs::Generator do
|
|
200
211
|
let(:apis) { response["apis"] }
|
201
212
|
context "apis" do
|
202
213
|
context "show" do
|
203
|
-
let(:api) { get_api_operation(apis, "nested/{nested_id}/nested_sample", :get) }
|
204
|
-
let(:operations) { get_api_operations(apis, "nested/{nested_id}/nested_sample") }
|
214
|
+
let(:api) { get_api_operation(apis, "/nested/{nested_id}/nested_sample", :get) }
|
215
|
+
let(:operations) { get_api_operations(apis, "/nested/{nested_id}/nested_sample") }
|
205
216
|
context "parameters" do
|
206
217
|
it "has correct count" do
|
207
218
|
expect(api["parameters"].count).to eq 2
|
@@ -222,7 +233,7 @@ describe Swagger::Docs::Generator do
|
|
222
233
|
expect(response["swaggerVersion"]).to eq "1.2"
|
223
234
|
end
|
224
235
|
it "writes basePath correctly" do
|
225
|
-
expect(response["basePath"]).to eq "http://api.no.where/api/v1
|
236
|
+
expect(response["basePath"]).to eq "http://api.no.where/api/v1"
|
226
237
|
end
|
227
238
|
it "writes resourcePath correctly" do
|
228
239
|
expect(response["resourcePath"]).to eq "sample"
|
@@ -251,17 +262,17 @@ describe Swagger::Docs::Generator do
|
|
251
262
|
end
|
252
263
|
context "apis" do
|
253
264
|
context "index" do
|
254
|
-
let(:api) { get_api_operation(apis, "sample", :get) }
|
255
|
-
let(:operations) { get_api_operations(apis, "sample") }
|
265
|
+
let(:api) { get_api_operation(apis, "/sample", :get) }
|
266
|
+
let(:operations) { get_api_operations(apis, "/sample") }
|
256
267
|
#"apis":[{"path":" /sample","operations":[{"summary":"Fetches all User items"
|
257
268
|
#,"method":"get","nickname":"Api::V1::Sample#index"}]
|
258
269
|
it "writes path correctly when api extension type is not set" do
|
259
|
-
expect(apis.first["path"]).to eq "sample"
|
270
|
+
expect(apis.first["path"]).to eq "/sample"
|
260
271
|
end
|
261
272
|
it "writes path correctly when api extension type is set" do
|
262
273
|
config[DEFAULT_VER][:api_extension_type] = :json
|
263
274
|
generate(config)
|
264
|
-
expect(apis.first["path"]).to eq "sample.json"
|
275
|
+
expect(apis.first["path"]).to eq "/sample.json"
|
265
276
|
end
|
266
277
|
it "writes summary correctly" do
|
267
278
|
expect(operations.first["summary"]).to eq "Fetches all User items"
|
@@ -275,6 +286,9 @@ describe Swagger::Docs::Generator do
|
|
275
286
|
it "writes responseModel attribute" do
|
276
287
|
expect(api["responseMessages"].find{|m| m["responseModel"] == "Tag"}).to_not be_nil
|
277
288
|
end
|
289
|
+
it "writes response code as 200" do
|
290
|
+
expect(api["responseMessages"].find{|m| m["responseModel"] == "Tag"}["code"]).to eq 200
|
291
|
+
end
|
278
292
|
#"parameters"=>[
|
279
293
|
# {"paramType"=>"query", "name"=>"page", "type"=>"integer", "description"=>"Page number", "required"=>false},
|
280
294
|
# {"paramType"=>"path", "name"=>"nested_id", "type"=>"integer", "description"=>"Team Id", "required"=>false}], "responseMessages"=>[{"code"=>401, "message"=>"Unauthorized"}, {"code"=>406, "message"=>"The request you made is not acceptable"}, {"code"=>416, "message"=>"Requested Range Not Satisfiable"}], "method"=>"get", "nickname"=>"Api::V1::Sample#index"}
|
@@ -301,7 +315,7 @@ describe Swagger::Docs::Generator do
|
|
301
315
|
end
|
302
316
|
end
|
303
317
|
context "list parameter" do
|
304
|
-
let(:api) { get_api_operation(apis, "sample", :patch) }
|
318
|
+
let(:api) { get_api_operation(apis, "/sample", :patch) }
|
305
319
|
let(:params) {api["parameters"] }
|
306
320
|
it "writes description correctly" do
|
307
321
|
expect(params[3]["description"]).to eq "Role"
|
@@ -314,18 +328,18 @@ describe Swagger::Docs::Generator do
|
|
314
328
|
expect(response_msgs.count).to eq 4
|
315
329
|
end
|
316
330
|
it "writes code correctly" do
|
317
|
-
expect(response_msgs.first["code"]).to eq
|
331
|
+
expect(response_msgs.first["code"]).to eq 200
|
318
332
|
end
|
319
333
|
it "writes message correctly" do
|
320
|
-
expect(response_msgs.first["message"]).to eq "
|
334
|
+
expect(response_msgs.first["message"]).to eq "Some text"
|
321
335
|
end
|
322
336
|
it "writes specified message correctly" do
|
323
|
-
expect(response_msgs[1]["message"]).to eq "
|
337
|
+
expect(response_msgs[1]["message"]).to eq "Unauthorized"
|
324
338
|
end
|
325
339
|
end
|
326
340
|
end
|
327
341
|
context "create" do
|
328
|
-
let(:api) { get_api_operation(apis, "sample", :patch) }
|
342
|
+
let(:api) { get_api_operation(apis, "/sample", :patch) }
|
329
343
|
it "writes list parameter values correctly" do
|
330
344
|
expected_param = {"valueType"=>"LIST", "values"=>["admin", "superadmin", "user"]}
|
331
345
|
expected_body = {"paramType"=>"body", "name"=>"body", "type"=>"json", "description"=>"JSON formatted body", "required"=>true}
|
@@ -339,7 +353,7 @@ describe Swagger::Docs::Generator do
|
|
339
353
|
end
|
340
354
|
end
|
341
355
|
context "update" do
|
342
|
-
let(:api) { get_api_operation(apis, "sample/{id}", :put) }
|
356
|
+
let(:api) { get_api_operation(apis, "/sample/{id}", :put) }
|
343
357
|
it "writes notes correctly" do
|
344
358
|
expect(api["notes"]).to eq "Only the given fields are updated."
|
345
359
|
end
|
data/swagger-docs.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.cert_chain = ['certs/gem-public_cert.pem']
|
23
|
-
spec.signing_key = File.expand_path("~/.gemcert/gem-private_key.pem") if $0 =~ /gem\z/
|
22
|
+
#spec.cert_chain = ['certs/gem-public_cert.pem']
|
23
|
+
#spec.signing_key = File.expand_path("~/.gemcert/gem-private_key.pem") if $0 =~ /gem\z/
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.3"
|
26
26
|
spec.add_development_dependency "rake", "~> 10"
|
metadata
CHANGED
@@ -1,36 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagger-docs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rich Hollis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
-
|
12
|
-
-----BEGIN CERTIFICATE-----
|
13
|
-
MIIDeDCCAmCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBBMRMwEQYDVQQDDApyaWNo
|
14
|
-
aG9sbGlzMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZFgNj
|
15
|
-
b20wHhcNMTMxMDIyMTMwMzI3WhcNMTQxMDIyMTMwMzI3WjBBMRMwEQYDVQQDDApy
|
16
|
-
aWNoaG9sbGlzMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
|
17
|
-
FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDppQTU++yinAuC
|
18
|
-
ydu87c/vDGTmE5Go9/zI48/T0kTco+JbUn4BPUaK0DWCEpZULvqwQAqVQm8JQnIU
|
19
|
-
6Z3k1tAQbhtgbG2oWNIxyC7SyXMQw/ag5qoAhw6k3DFE+jGKrREzADFb7vG+nPYp
|
20
|
-
4yinx27jCTIAv7/z2AVt6HoHOYh1s0HniJQWCebi7QgNXboMY8MpFxSwNkcFjl14
|
21
|
-
KMSf9SX7iOyiwqgcJmN0fN4be8pH5j/EdinUL1rWlwldcUo2+6LChBswRPmtdaZv
|
22
|
-
UyICuX5VfVJA0KrA/ihIMLaZVO5esFso+YrpP+QgbvhLwhn5e/sB5dr3a+y0+GJZ
|
23
|
-
zPGtm60bAgMBAAGjezB5MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
|
24
|
-
BBShIiKLL1E1JG++RUVAOSPO7rZV0TAfBgNVHREEGDAWgRRyaWNoaG9sbGlzQGdt
|
25
|
-
YWlsLmNvbTAfBgNVHRIEGDAWgRRyaWNoaG9sbGlzQGdtYWlsLmNvbTANBgkqhkiG
|
26
|
-
9w0BAQUFAAOCAQEAe4P1TzJlVhUn60Wx/431wNnuHZS9K4gSzmNr4zuZU6lP3rxx
|
27
|
-
rMsSY1nJY1nTBqX9W62hO+KS14ncbZvNU59ao5YVXHDflEB3Yz20DP9E2Uws64Bx
|
28
|
-
ify0Dwuq4VV2PiQbczuTGhGupzQpkMttWNZqVdjDbH5k8sGx3MumNX7YUJwUerhZ
|
29
|
-
bTBme5soNyJzAeWBqCBPT9p98rC6vqhcBfAVF6RbERYL6MPyoBZWqGeuMR4H2X/v
|
30
|
-
RYcsqDfanYBx7QcftOnbeQq7/Ep7Zx+W9+Ph3TiJLMLdAr7bLkgN1SjvrjTL5mQR
|
31
|
-
FuQtYvE4LKiUQpG7vLTRB78dQBlSj9fnv2OM9w==
|
32
|
-
-----END CERTIFICATE-----
|
33
|
-
date: 2014-09-10 00:00:00.000000000 Z
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-13 00:00:00.000000000 Z
|
34
12
|
dependencies:
|
35
13
|
- !ruby/object:Gem::Dependency
|
36
14
|
name: bundler
|
@@ -186,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
164
|
version: '0'
|
187
165
|
requirements: []
|
188
166
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.
|
167
|
+
rubygems_version: 2.4.8
|
190
168
|
signing_key:
|
191
169
|
specification_version: 4
|
192
170
|
summary: Generates swagger-ui json files for rails apps with APIs. You add the swagger
|
checksums.yaml.gz.sig
DELETED
data.tar.gz.sig
DELETED
metadata.gz.sig
DELETED