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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3eb51612948dcffe393a0fee74c1f79dcfb64ae9
4
- data.tar.gz: ccaa3a9f4e00a1b022b1c71eb9431fba6675efee
3
+ metadata.gz: 67c64b2ae7bcb8d0a653d598dc5f6de70d223d8e
4
+ data.tar.gz: 95555f61513a11238944a1e9a4bd361f00e70159
5
5
  SHA512:
6
- metadata.gz: 191427fd69bff4114b6a55a844430e373f7505eab2d0a63781c027fd468691b6f19fe36fb2fea1107a585b1e6acfc6152e2934a4ff96e5f022a0e944c7b822a8
7
- data.tar.gz: 1fe19613a6cc7d7a7cf70cb1c1b2ee85d92bb9fc9a9aecb34d6b8c33b6d49180a9aceea273ff021b5f1d23f36cd1705d5d0b7d132bdc9081146ca10454b3dd9f
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 @jdar, @fotinakis, @stevschmid and all of our contributors for making swagger-docs better.
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
 
@@ -12,11 +12,22 @@ module Swagger
12
12
  end
13
13
 
14
14
  def swagger_actions
15
- @swagger_dsl
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
- @swagger_model_dsls ||= {}
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
- dsl = SwaggerDSL.call(action, self, &block)
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
- model_dsl = SwaggerModelDSL.call(model_name, self, &block)
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
@@ -1,5 +1,5 @@
1
1
  module Swagger
2
2
  module Docs
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
4
4
  end
5
5
  end
@@ -1,3 +1,4 @@
1
1
  class ApplicationController
2
-
2
+ cattr_accessor :context
3
+ self.context = "original"
3
4
  end
@@ -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
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-07 00:00:00.000000000 Z
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.0.6
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
- c2��a�{�p ���@nr4� ���v�gX0$�����F��.~��|2E��U}HQ���;�3/�i D��=J�c����$T�D���B#�s�0QBd��������u�S3�/hXaE�?3���F)#P]��s�Dv��@ߊ�l��>�;�P��̻�����B��u$���i��RK�� �����@3�"��l�.�S��'�.�'��-� �?�|�����1�[�G^��K�GҶ�)
1
+ aS9!fI}ª �@
data/pec DELETED
@@ -1,120 +0,0 @@
1
- diff --git a/lib/swagger/docs/generator.rb b/lib/swagger/docs/generator.rb
2
- index ed18606..6455c92 100644
3
- --- a/lib/swagger/docs/generator.rb
4
- +++ b/lib/swagger/docs/generator.rb
5
- @@ -17,34 +17,56 @@ module Swagger
6
- end
7
- 
8
- def write_docs(apis = nil)
9
- - apis ||= Config.registered_apis
10
- - results = {}
11
- - set_real_methods
12
- - unless apis.empty?
13
- - apis.each do |api_version,config|
14
- - config.reverse_merge!(DEFAULT_CONFIG)
15
- - results[api_version] = write_doc(api_version, config)
16
- - end
17
- - else
18
- - results[DEFAULT_VER] = write_doc(DEFAULT_VER, DEFAULT_CONFIG)
19
- + results = generate_docs(apis)
20
- + results.each do |api_version, result|
21
- + write_doc(result)
22
- end
23
- results
24
- end
25
- 
26
- - def write_doc(api_version, config)
27
- - settings = get_settings(api_version, config)
28
- -
29
- + def write_doc(result)
30
- + settings = result[:settings]
31
- + config = result[:config]
32
- create_output_paths(settings[:api_file_path])
33
- clean_output_paths(settings[:api_file_path]) if config[:clean_directory] || false
34
- + root = result[:root]
35
- + resources = root.delete 'resources'
36
- + write_to_file("#{settings[:api_file_path]}/api-docs.json", root, config)
37
- + resources.each do |resource|
38
- + resource_file_path = resource.delete 'resourceFilePath'
39
- + write_to_file(File.join(settings[:api_file_path], "#{resource_file_path}.json"), resource, config)
40
- + end
41
- + result
42
- + end
43
- 
44
- + def generate_docs(apis=nil)
45
- + apis ||= Config.registered_apis
46
- + results = {}
47
- + set_real_methods
48
- +
49
- + apis[DEFAULT_VER] = DEFAULT_CONFIG if apis.empty?
50
- +
51
- + apis.each do |api_version, config|
52
- + settings = get_settings(api_version, config)
53
- + config.reverse_merge!(DEFAULT_CONFIG)
54
- + results[api_version] = generate_doc(api_version, settings, config)
55
- + results[api_version][:settings] = settings
56
- + results[api_version][:config] = config
57
- + end
58
- + results
59
- + end
60
- +
61
- + def generate_doc(api_version, settings, config)
62
- root = { :api_version => api_version, :swagger_version => "1.2", :base_path => settings[:base_path] + "/", :apis => []}
63
- results = {:processed => [], :skipped => []}
64
- + resources = []
65
- 
66
- get_route_paths(settings[:controller_base_path]).each do |path|
67
- ret = process_path(path, root, config, settings)
68
- results[ret[:action]] << ret
69
- if ret[:action] == :processed
70
- - create_resource_file(ret[:path], ret[:apis], ret[:models], settings, root, config)
71
- + resource = generate_resource(ret[:path], ret[:apis], ret[:models], settings, root, config)
72
- + resources << resource
73
- debased_path = get_debased_path(ret[:path], settings[:controller_base_path])
74
- resource_api = {
75
- path: "#{Config.transform_path(trim_leading_slash(debased_path))}.{format}",
76
- @@ -53,9 +75,9 @@ module Swagger
77
- root[:apis] << resource_api
78
- end
79
- end
80
- -
81
- + root[:resources] = resources
82
- camelize_keys_deep!(root)
83
- - write_to_file("#{settings[:api_file_path]}/api-docs.json", root, config)
84
- + results[:root] = root
85
- results
86
- end
87
- 
88
- @@ -115,7 +137,7 @@ module Swagger
89
- {action: :processed, path: path, apis: apis, models: models, klass: klass}
90
- end
91
- 
92
- - def create_resource_file(path, apis, models, settings, root, config)
93
- + def generate_resource(path, apis, models, settings, root, config)
94
- debased_path = get_debased_path(path, settings[:controller_base_path])
95
- demod = "#{debased_path.to_s.camelize}".demodulize.camelize.underscore
96
- resource_path = trim_leading_slash(debased_path.to_s.underscore)
97
- @@ -123,8 +145,8 @@ module Swagger
98
- camelize_keys_deep!(resource)
99
- # Add the already-normalized models to the resource.
100
- resource = resource.merge({:models => models}) if models.present?
101
- - # write controller resource file
102
- - write_to_file(File.join(settings[:api_file_path], "#{resource_path}.json"), resource, config)
103
- + resource[:resource_file_path] = resource_path
104
- + resource
105
- end
106
- 
107
- def get_route_path_apis(path, route, klass, settings, config)
108
- diff --git a/spec/lib/swagger/docs/generator_spec.rb b/spec/lib/swagger/docs/generator_spec.rb
109
- index d319ac3..ba57ccd 100644
110
- --- a/spec/lib/swagger/docs/generator_spec.rb
111
- +++ b/spec/lib/swagger/docs/generator_spec.rb
112
- @@ -298,7 +298,7 @@ describe Swagger::Docs::Generator do
113
- }
114
- }
115
- }
116
- - expect(models['Tag']).to eq expected_model
117
- + expect(models['tag']).to eq expected_model
118
- end
119
- end
120
- end