swagger-docs 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +8 -0
- data/README.md +30 -1
- data/lib/swagger/docs/methods.rb +17 -9
- data/lib/swagger/docs/version.rb +1 -1
- data/spec/fixtures/controllers/application_controller.rb +2 -1
- data/spec/fixtures/controllers/sample_controller.rb +7 -0
- data/spec/lib/swagger/docs/generator_spec.rb +19 -0
- data/swagger-docs.gemspec +4 -4
- metadata +16 -17
- metadata.gz.sig +1 -1
- data/pec +0 -120
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67c64b2ae7bcb8d0a653d598dc5f6de70d223d8e
|
4
|
+
data.tar.gz: 95555f61513a11238944a1e9a4bd361f00e70159
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c047b999407fc51017a1e6ded45582bff68c395446f643d3aaef3f2c3f0c5d397cc6f210c9021348337bce459b5f5e2d88a9eb6ac98814826fd86746b6046f14
|
7
|
+
data.tar.gz: 2a86f256d2298cb7ab8abadd4e350641bb37da943f77b1dad6f7cb2b1d7106b942b6d55c8efb39636c755464f7fec03a7d20effe3c655b37b96b9aaf2093e0c6
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 0.1.5
|
2
|
+
- Delay processing docs DSL to allow changing the context of the controllers #47 @ldnunes
|
3
|
+
|
4
|
+
## 0.1.4
|
5
|
+
- An undocumentated action in a documented controller should not raise errors #43 @ldnunes
|
6
|
+
- Allow reopening of docs definition for the swagger_api DSL command #44 @ldnunes
|
7
|
+
- Refactor write_docs to split the documentation generation from file writing #45 @ldnunes
|
8
|
+
|
1
9
|
## 0.1.3
|
2
10
|
- Fix issue where empty path throws error
|
3
11
|
|
data/README.md
CHANGED
@@ -216,6 +216,35 @@ https://github.com/richhollis/swagger-docs-sample
|
|
216
216
|
|
217
217
|
### Advanced Customization
|
218
218
|
|
219
|
+
#### Recurring parameters
|
220
|
+
|
221
|
+
If you have lots of recurring parameters then you can use this approach suggested by Lucas Dutra Nunes (@ldnunes):
|
222
|
+
|
223
|
+
```
|
224
|
+
class Api::BaseController < ActionController::Base
|
225
|
+
class << self
|
226
|
+
Swagger::Docs::Generator::set_real_methods
|
227
|
+
|
228
|
+
def inherited(subclass)
|
229
|
+
super
|
230
|
+
subclass.class_eval do
|
231
|
+
setup_basic_api_documentation
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
private
|
236
|
+
|
237
|
+
def setup_basic_api_documentation
|
238
|
+
[:index, :show, :create, :update, :delete].each do |api_action|
|
239
|
+
swagger_api api_action do
|
240
|
+
param :header, 'Authentication-Token', :string, :required, 'Authentication token'
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
```
|
247
|
+
|
219
248
|
#### Inheriting from a custom Api controller
|
220
249
|
|
221
250
|
By default swagger-docs is applied to controllers inheriting from ApplicationController.
|
@@ -565,7 +594,7 @@ users.json output:
|
|
565
594
|
|
566
595
|
## Thanks to our contributors
|
567
596
|
|
568
|
-
Thanks to
|
597
|
+
Thanks to jdar, fotinakis, stevschmid, ldnunes and all of our contributors for making swagger-docs even better.
|
569
598
|
|
570
599
|
## Contributing
|
571
600
|
|
data/lib/swagger/docs/methods.rb
CHANGED
@@ -12,11 +12,22 @@ module Swagger
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def swagger_actions
|
15
|
-
|
15
|
+
swagger_dsl = {}
|
16
|
+
Array(@swagger_dsl).each do |action, controller, block|
|
17
|
+
dsl = SwaggerDSL.call(action, controller, &block)
|
18
|
+
swagger_dsl[action] ||= {}
|
19
|
+
swagger_dsl[action].deep_merge!(dsl) { |key, old, new| Array(old) + Array(new) }
|
20
|
+
end
|
21
|
+
swagger_dsl
|
16
22
|
end
|
17
23
|
|
18
24
|
def swagger_models
|
19
|
-
|
25
|
+
swagger_model_dsls ||= {}
|
26
|
+
Array(@swagger_model_dsls).each do |model_name, controller, block|
|
27
|
+
model_dsl = SwaggerModelDSL.call(model_name, controller, &block)
|
28
|
+
swagger_model_dsls[model_name] = model_dsl
|
29
|
+
end
|
30
|
+
swagger_model_dsls
|
20
31
|
end
|
21
32
|
|
22
33
|
def swagger_config
|
@@ -26,16 +37,13 @@ module Swagger
|
|
26
37
|
private
|
27
38
|
|
28
39
|
def swagger_api(action, &block)
|
29
|
-
@swagger_dsl ||=
|
30
|
-
|
31
|
-
@swagger_dsl[action] ||= {}
|
32
|
-
@swagger_dsl[action].deep_merge!(dsl) { |key, old, new| Array(old) + Array(new) }
|
40
|
+
@swagger_dsl ||= []
|
41
|
+
@swagger_dsl << [action, self, block]
|
33
42
|
end
|
34
43
|
|
35
44
|
def swagger_model(model_name, &block)
|
36
|
-
@swagger_model_dsls ||=
|
37
|
-
|
38
|
-
@swagger_model_dsls[model_name] = model_dsl
|
45
|
+
@swagger_model_dsls ||= []
|
46
|
+
@swagger_model_dsls << [model_name, self, block]
|
39
47
|
end
|
40
48
|
end
|
41
49
|
end
|
data/lib/swagger/docs/version.rb
CHANGED
@@ -62,6 +62,13 @@ module Api
|
|
62
62
|
summary "Builds a new User item"
|
63
63
|
end
|
64
64
|
|
65
|
+
swagger_api :context_dependent do
|
66
|
+
summary "An action dependent on the context of the controller " +
|
67
|
+
"class. Right now it is: " + ApplicationController.context
|
68
|
+
response :success
|
69
|
+
response :unauthorized
|
70
|
+
end
|
71
|
+
|
65
72
|
# Support for Swagger complex types:
|
66
73
|
# https://github.com/wordnik/swagger-core/wiki/Datatypes#wiki-complex-types
|
67
74
|
swagger_model :Tag do
|
@@ -184,6 +184,25 @@ describe Swagger::Docs::Generator do
|
|
184
184
|
it "writes out expected api count" do
|
185
185
|
expect(response["apis"].count).to eq 7
|
186
186
|
end
|
187
|
+
describe "context dependent documentation" do
|
188
|
+
after(:each) do
|
189
|
+
ApplicationController.context = "original"
|
190
|
+
end
|
191
|
+
let(:routes) {[stub_route("^GET$", "context_dependent", "api/v1/sample", "/api/v1/sample(.:format)")]}
|
192
|
+
let(:operations) { apis[0]["operations"] }
|
193
|
+
it "should be the original" do
|
194
|
+
ApplicationController.context = "original"
|
195
|
+
generate(config)
|
196
|
+
expect(operations.first["summary"]).to eq "An action dependent on the context of the controller class. Right now it is: original"
|
197
|
+
end
|
198
|
+
context "when modified" do
|
199
|
+
it "should be modified" do
|
200
|
+
ApplicationController.context = "modified"
|
201
|
+
generate(config)
|
202
|
+
expect(operations.first["summary"]).to eq "An action dependent on the context of the controller class. Right now it is: modified"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
187
206
|
context "apis" do
|
188
207
|
context "index" do
|
189
208
|
let(:api) { get_api_operation(apis, "sample", :get) }
|
data/swagger-docs.gemspec
CHANGED
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
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
|
-
spec.add_development_dependency "rake"
|
27
|
-
spec.add_development_dependency "rspec"
|
28
|
-
spec.add_development_dependency "rails"
|
29
|
-
spec.add_development_dependency "appraisal"
|
26
|
+
spec.add_development_dependency "rake", "~> 0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 0"
|
28
|
+
spec.add_development_dependency "rails", "~> 0"
|
29
|
+
spec.add_development_dependency "appraisal", "~> 0"
|
30
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagger-docs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rich Hollis
|
@@ -30,76 +30,76 @@ cert_chain:
|
|
30
30
|
RYcsqDfanYBx7QcftOnbeQq7/Ep7Zx+W9+Ph3TiJLMLdAr7bLkgN1SjvrjTL5mQR
|
31
31
|
FuQtYvE4LKiUQpG7vLTRB78dQBlSj9fnv2OM9w==
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2014-04-
|
33
|
+
date: 2014-04-28 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: bundler
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - ~>
|
39
|
+
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '1.3'
|
42
42
|
type: :development
|
43
43
|
prerelease: false
|
44
44
|
version_requirements: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - ~>
|
46
|
+
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '1.3'
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: rake
|
51
51
|
requirement: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
58
|
version_requirements: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
64
|
name: rspec
|
65
65
|
requirement: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
type: :development
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
- !ruby/object:Gem::Dependency
|
78
78
|
name: rails
|
79
79
|
requirement: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
type: :development
|
85
85
|
prerelease: false
|
86
86
|
version_requirements: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- -
|
88
|
+
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: appraisal
|
93
93
|
requirement: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- -
|
95
|
+
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
type: :development
|
99
99
|
prerelease: false
|
100
100
|
version_requirements: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - "~>"
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
description: Generates json files for rails apps to use with swagger-ui
|
@@ -109,7 +109,7 @@ executables: []
|
|
109
109
|
extensions: []
|
110
110
|
extra_rdoc_files: []
|
111
111
|
files:
|
112
|
-
- .gitignore
|
112
|
+
- ".gitignore"
|
113
113
|
- Appraisals
|
114
114
|
- CHANGELOG.md
|
115
115
|
- Gemfile
|
@@ -126,7 +126,6 @@ files:
|
|
126
126
|
- lib/swagger/docs/task.rb
|
127
127
|
- lib/swagger/docs/version.rb
|
128
128
|
- lib/tasks/swagger.rake
|
129
|
-
- pec
|
130
129
|
- spec/fixtures/controllers/application_controller.rb
|
131
130
|
- spec/fixtures/controllers/ignored_controller.rb
|
132
131
|
- spec/fixtures/controllers/sample_controller.rb
|
@@ -143,17 +142,17 @@ require_paths:
|
|
143
142
|
- lib
|
144
143
|
required_ruby_version: !ruby/object:Gem::Requirement
|
145
144
|
requirements:
|
146
|
-
- -
|
145
|
+
- - ">="
|
147
146
|
- !ruby/object:Gem::Version
|
148
147
|
version: '0'
|
149
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
149
|
requirements:
|
151
|
-
- -
|
150
|
+
- - ">="
|
152
151
|
- !ruby/object:Gem::Version
|
153
152
|
version: '0'
|
154
153
|
requirements: []
|
155
154
|
rubyforge_project:
|
156
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.2.2
|
157
156
|
signing_key:
|
158
157
|
specification_version: 4
|
159
158
|
summary: Generates swagger-ui json files for rails apps with APIs. You add the swagger
|
metadata.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
�
|
1
|
+
�aS9!fI}ª �@
|
data/pec
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
[1mdiff --git a/lib/swagger/docs/generator.rb b/lib/swagger/docs/generator.rb[m
|
2
|
-
[1mindex ed18606..6455c92 100644[m
|
3
|
-
[1m--- a/lib/swagger/docs/generator.rb[m
|
4
|
-
[1m+++ b/lib/swagger/docs/generator.rb[m
|
5
|
-
[36m@@ -17,34 +17,56 @@[m [mmodule Swagger[m
|
6
|
-
end[m
|
7
|
-
[m
|
8
|
-
def write_docs(apis = nil)[m
|
9
|
-
[31m- apis ||= Config.registered_apis[m
|
10
|
-
[31m- results = {}[m
|
11
|
-
[31m- set_real_methods[m
|
12
|
-
[31m- unless apis.empty?[m
|
13
|
-
[31m- apis.each do |api_version,config|[m
|
14
|
-
[31m- config.reverse_merge!(DEFAULT_CONFIG)[m
|
15
|
-
[31m- results[api_version] = write_doc(api_version, config)[m
|
16
|
-
[31m- end[m
|
17
|
-
[31m- else[m
|
18
|
-
[31m- results[DEFAULT_VER] = write_doc(DEFAULT_VER, DEFAULT_CONFIG)[m
|
19
|
-
[32m+[m[32m results = generate_docs(apis)[m
|
20
|
-
[32m+[m[32m results.each do |api_version, result|[m
|
21
|
-
[32m+[m[32m write_doc(result)[m
|
22
|
-
end[m
|
23
|
-
results[m
|
24
|
-
end[m
|
25
|
-
[m
|
26
|
-
[31m- def write_doc(api_version, config)[m
|
27
|
-
[31m- settings = get_settings(api_version, config)[m
|
28
|
-
[31m-[m
|
29
|
-
[32m+[m[32m def write_doc(result)[m
|
30
|
-
[32m+[m[32m settings = result[:settings][m
|
31
|
-
[32m+[m[32m config = result[:config][m
|
32
|
-
create_output_paths(settings[:api_file_path])[m
|
33
|
-
clean_output_paths(settings[:api_file_path]) if config[:clean_directory] || false[m
|
34
|
-
[32m+[m[32m root = result[:root][m
|
35
|
-
[32m+[m[32m resources = root.delete 'resources'[m
|
36
|
-
[32m+[m[32m write_to_file("#{settings[:api_file_path]}/api-docs.json", root, config)[m
|
37
|
-
[32m+[m[32m resources.each do |resource|[m
|
38
|
-
[32m+[m[32m resource_file_path = resource.delete 'resourceFilePath'[m
|
39
|
-
[32m+[m[32m write_to_file(File.join(settings[:api_file_path], "#{resource_file_path}.json"), resource, config)[m
|
40
|
-
[32m+[m[32m end[m
|
41
|
-
[32m+[m[32m result[m
|
42
|
-
[32m+[m[32m end[m
|
43
|
-
[m
|
44
|
-
[32m+[m[32m def generate_docs(apis=nil)[m
|
45
|
-
[32m+[m[32m apis ||= Config.registered_apis[m
|
46
|
-
[32m+[m[32m results = {}[m
|
47
|
-
[32m+[m[32m set_real_methods[m
|
48
|
-
[32m+[m
|
49
|
-
[32m+[m[32m apis[DEFAULT_VER] = DEFAULT_CONFIG if apis.empty?[m
|
50
|
-
[32m+[m
|
51
|
-
[32m+[m[32m apis.each do |api_version, config|[m
|
52
|
-
[32m+[m[32m settings = get_settings(api_version, config)[m
|
53
|
-
[32m+[m[32m config.reverse_merge!(DEFAULT_CONFIG)[m
|
54
|
-
[32m+[m[32m results[api_version] = generate_doc(api_version, settings, config)[m
|
55
|
-
[32m+[m[32m results[api_version][:settings] = settings[m
|
56
|
-
[32m+[m[32m results[api_version][:config] = config[m
|
57
|
-
[32m+[m[32m end[m
|
58
|
-
[32m+[m[32m results[m
|
59
|
-
[32m+[m[32m end[m
|
60
|
-
[32m+[m
|
61
|
-
[32m+[m[32m def generate_doc(api_version, settings, config)[m
|
62
|
-
root = { :api_version => api_version, :swagger_version => "1.2", :base_path => settings[:base_path] + "/", :apis => []}[m
|
63
|
-
results = {:processed => [], :skipped => []}[m
|
64
|
-
[32m+[m[32m resources = [][m
|
65
|
-
[m
|
66
|
-
get_route_paths(settings[:controller_base_path]).each do |path|[m
|
67
|
-
ret = process_path(path, root, config, settings)[m
|
68
|
-
results[ret[:action]] << ret[m
|
69
|
-
if ret[:action] == :processed[m
|
70
|
-
[31m- create_resource_file(ret[:path], ret[:apis], ret[:models], settings, root, config)[m
|
71
|
-
[32m+[m[32m resource = generate_resource(ret[:path], ret[:apis], ret[:models], settings, root, config)[m
|
72
|
-
[32m+[m[32m resources << resource[m
|
73
|
-
debased_path = get_debased_path(ret[:path], settings[:controller_base_path])[m
|
74
|
-
resource_api = {[m
|
75
|
-
path: "#{Config.transform_path(trim_leading_slash(debased_path))}.{format}",[m
|
76
|
-
[36m@@ -53,9 +75,9 @@[m [mmodule Swagger[m
|
77
|
-
root[:apis] << resource_api[m
|
78
|
-
end[m
|
79
|
-
end[m
|
80
|
-
[31m-[m
|
81
|
-
[32m+[m[32m root[:resources] = resources[m
|
82
|
-
camelize_keys_deep!(root)[m
|
83
|
-
[31m- write_to_file("#{settings[:api_file_path]}/api-docs.json", root, config)[m
|
84
|
-
[32m+[m[32m results[:root] = root[m
|
85
|
-
results[m
|
86
|
-
end[m
|
87
|
-
[m
|
88
|
-
[36m@@ -115,7 +137,7 @@[m [mmodule Swagger[m
|
89
|
-
{action: :processed, path: path, apis: apis, models: models, klass: klass}[m
|
90
|
-
end[m
|
91
|
-
[m
|
92
|
-
[31m- def create_resource_file(path, apis, models, settings, root, config)[m
|
93
|
-
[32m+[m[32m def generate_resource(path, apis, models, settings, root, config)[m
|
94
|
-
debased_path = get_debased_path(path, settings[:controller_base_path])[m
|
95
|
-
demod = "#{debased_path.to_s.camelize}".demodulize.camelize.underscore[m
|
96
|
-
resource_path = trim_leading_slash(debased_path.to_s.underscore)[m
|
97
|
-
[36m@@ -123,8 +145,8 @@[m [mmodule Swagger[m
|
98
|
-
camelize_keys_deep!(resource)[m
|
99
|
-
# Add the already-normalized models to the resource.[m
|
100
|
-
resource = resource.merge({:models => models}) if models.present?[m
|
101
|
-
[31m- # write controller resource file[m
|
102
|
-
[31m- write_to_file(File.join(settings[:api_file_path], "#{resource_path}.json"), resource, config)[m
|
103
|
-
[32m+[m[32m resource[:resource_file_path] = resource_path[m
|
104
|
-
[32m+[m[32m resource[m
|
105
|
-
end[m
|
106
|
-
[m
|
107
|
-
def get_route_path_apis(path, route, klass, settings, config)[m
|
108
|
-
[1mdiff --git a/spec/lib/swagger/docs/generator_spec.rb b/spec/lib/swagger/docs/generator_spec.rb[m
|
109
|
-
[1mindex d319ac3..ba57ccd 100644[m
|
110
|
-
[1m--- a/spec/lib/swagger/docs/generator_spec.rb[m
|
111
|
-
[1m+++ b/spec/lib/swagger/docs/generator_spec.rb[m
|
112
|
-
[36m@@ -298,7 +298,7 @@[m [mdescribe Swagger::Docs::Generator do[m
|
113
|
-
}[m
|
114
|
-
}[m
|
115
|
-
}[m
|
116
|
-
[31m- expect(models['Tag']).to eq expected_model[m
|
117
|
-
[32m+[m[32m expect(models['tag']).to eq expected_model[m
|
118
|
-
end[m
|
119
|
-
end[m
|
120
|
-
end[m
|