swagger-docs 0.2.1 → 0.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9fdc3f4f644a149fff976af8f32e4a084749d95
4
- data.tar.gz: ec345458634e9e25fee45ace966b271d1d8bd273
3
+ metadata.gz: 850e7d77a965af9ee323f25bc7ab3e3a91d370c8
4
+ data.tar.gz: 6b724ad6dd87abc8cab15e2b4a30055c6910e198
5
5
  SHA512:
6
- metadata.gz: 45bb296a5aa61b7b7ecae8eb1706da6483bb7febe4b189f36490203e39732ffc2e0f54271298aec7d1a0d0615eeedc808fa599ce5ff7bab1ba8ed2afb92911c6
7
- data.tar.gz: 566577465f61ef479399c9ef270f5762905e4b9f173ce2d11d1111a3162ace73621b78b6b39fc489dca7793e7bbb47e301bafb65cf823a3b346d4302f8fe8ded
6
+ metadata.gz: e155052e677d44500ce278b910766d6c0e9eae07cacd5bc9514b79af5f61a98d510dd073ce1bc86ad0be3d4bdcc5eb4e8fd8e3f2cd51b66523e40ce2c7344cac
7
+ data.tar.gz: 66cf934624dbf944215ddc98401dc3a6a8c3608014fb62b4de88b9500394d2deabcdd89bd668240fe9cd7f379392d6565b29de3ab2c8f3f8ee0d13547bce2c4a
@@ -1,3 +1,23 @@
1
+ ## 0.2.6
2
+
3
+ - swagger_controller DSL can accept a resource_path which will be used over a generated path #126 @sb8244
4
+
5
+ ## 0.2.5
6
+
7
+ - Enabled option to set 'items' inside swagger_api method #99 @krakatoa
8
+
9
+ ## 0.2.4
10
+
11
+ - Parent controller option for register_apis config. #123 @mskubenich
12
+
13
+ ## 0.2.3
14
+
15
+ - Added property_list to SwaggerModelDSL #108 @dr-impossible
16
+
17
+ ## 0.2.2
18
+
19
+ - Support multiple route methods #128 @frodrigo
20
+
1
21
  ## 0.2.1
2
22
 
3
23
  - Add support for Authorizations (OAuth 2.0) - Thanks to @RKushnir #97
data/README.md CHANGED
@@ -62,6 +62,8 @@ Swagger::Docs::Config.register_apis({
62
62
  :base_path => "http://api.somedomain.com",
63
63
  # if you want to delete all .json files at each generation
64
64
  :clean_directory => false,
65
+ # Ability to setup base controller for each api version. Api::V1::SomeController for example.
66
+ :parent_controller => Api::V1::SomeController
65
67
  # add custom attributes to api-docs
66
68
  :attributes => {
67
69
  :info => {
@@ -133,6 +135,12 @@ The following table shows all the current configuration options and their defaul
133
135
  <td>true</td>
134
136
  </tr>
135
137
 
138
+ <tr>
139
+ <td><b>parent_controller</b></td>
140
+ <td>Assign a different controller to use for the configuration</td>
141
+ <td>ClassName</td>
142
+ </tr>
143
+
136
144
  </tbody>
137
145
  </table>
138
146
 
@@ -198,11 +206,25 @@ class Api::V1::UsersController < ApplicationController
198
206
  description "A Tag object."
199
207
  property :id, :integer, :required, "User Id"
200
208
  property :name, :string, :optional, "Name"
209
+ property_list :type, :string, :optional, "Tag Type", ["info", "warning", "error"]
201
210
  end
202
-
203
211
  end
204
212
  ```
205
213
 
214
+ #### Support for Enums (PR #108)
215
+
216
+ ```
217
+ property_list :type, :string, :optional, "Type", ["info", "warning", "error"]
218
+ ```
219
+
220
+ #### Custom resource paths`(PR #126)
221
+
222
+ ```ruby
223
+ class Api::V1::UsersController < ApplicationController
224
+
225
+ swagger_controller :users, "User Management", resource_path: "/some/where"
226
+ ```
227
+
206
228
  ### DRYing up common documentation
207
229
 
208
230
  Suppose you have a header or a parameter that must be present on several controllers and methods. Instead of duplicating it on all the controllers you can do this on your API base controller:
@@ -41,7 +41,7 @@ module Swagger
41
41
  end
42
42
 
43
43
  def resource_path
44
- demod
44
+ metadata.overridden_resource_path || demod
45
45
  end
46
46
 
47
47
  def resource_file_path
@@ -2,8 +2,10 @@ module Swagger
2
2
  module Docs
3
3
  class ApiDeclarationFileMetadata
4
4
  DEFAULT_SWAGGER_VERSION = "1.2"
5
+ DEFAULT_RESOURCE_PATH = nil
5
6
 
6
- attr_reader :api_version, :path, :base_path, :controller_base_path, :swagger_version, :camelize_model_properties, :authorizations
7
+ attr_reader :api_version, :path, :base_path, :controller_base_path, :swagger_version, :camelize_model_properties
8
+ attr_reader :authorizations, :overridden_resource_path
7
9
 
8
10
  def initialize(api_version, path, base_path, controller_base_path, options={})
9
11
  @api_version = api_version
@@ -13,6 +15,7 @@ module Swagger
13
15
  @swagger_version = options.fetch(:swagger_version, DEFAULT_SWAGGER_VERSION)
14
16
  @camelize_model_properties = options.fetch(:camelize_model_properties, true)
15
17
  @authorizations = options.fetch(:authorizations, {})
18
+ @overridden_resource_path = options.fetch(:resource_path, DEFAULT_RESOURCE_PATH)
16
19
  end
17
20
  end
18
21
  end
@@ -29,6 +29,10 @@ module Swagger
29
29
  @type = type
30
30
  end
31
31
 
32
+ def items(items)
33
+ @items = items
34
+ end
35
+
32
36
  def consumes(mime_types)
33
37
  @consumes = mime_types
34
38
  end
@@ -104,6 +108,12 @@ module Swagger
104
108
  }.merge!(hash)
105
109
  self.required << name if required == :required
106
110
  end
111
+
112
+ # helper method to generate enums
113
+ def property_list(name, type, required, description = nil, allowed_values = [], hash = {})
114
+ hash.merge!({allowable_values: {value_type: "LIST", values: allowed_values}})
115
+ property(name, type, required, description, hash)
116
+ end
107
117
  end
108
118
  end
109
119
  end
@@ -75,7 +75,7 @@ module Swagger
75
75
  ret = process_path(path, root, config, settings)
76
76
  results[ret[:action]] << ret
77
77
  if ret[:action] == :processed
78
- resources << generate_resource(ret[:path], ret[:apis], ret[:models], settings, root, config)
78
+ resources << generate_resource(ret[:path], ret[:apis], ret[:models], settings, root, config, ret[:klass].swagger_config)
79
79
  debased_path = get_debased_path(ret[:path], settings[:controller_base_path])
80
80
  resource_api = {
81
81
  path: "/#{Config.transform_path(trim_leading_slash(debased_path), api_version)}.{format}",
@@ -136,6 +136,7 @@ module Swagger
136
136
  klass = Config.log_exception { "#{path.to_s.camelize}Controller".constantize } rescue nil
137
137
  return {action: :skipped, path: path, reason: :klass_not_present} if !klass
138
138
  return {action: :skipped, path: path, reason: :not_swagger_resource} if !klass.methods.include?(:swagger_config) or !klass.swagger_config[:controller]
139
+ return {action: :skipped, path: path, reason: :not_kind_of_parent_controller} if config[:parent_controller] && !klass < config[:parent_controller]
139
140
  apis, models, defined_nicknames = [], {}, []
140
141
  routes.select{|i| i.defaults[:controller] == path}.each do |route|
141
142
  unless nickname_defined?(defined_nicknames, path, route) # only add once for each route once e.g. PATCH, PUT
@@ -148,8 +149,8 @@ module Swagger
148
149
  {action: :processed, path: path, apis: apis, models: models, klass: klass}
149
150
  end
150
151
 
151
- def route_verb(route)
152
- if defined?(route.verb.source) then route.verb.source.to_s.delete('$'+'^') else route.verb end.downcase.to_sym
152
+ def route_verbs(route)
153
+ if defined?(route.verb.source) then route.verb.source.to_s.delete('$'+'^').split('|') else [route.verb] end.collect{|verb| verb.downcase.to_sym}
153
154
  end
154
155
 
155
156
  def path_route_nickname(path, route)
@@ -158,19 +159,19 @@ module Swagger
158
159
  end
159
160
 
160
161
  def nickname_defined?(defined_nicknames, path, route)
161
- verb = route_verb(route)
162
162
  target_nickname = path_route_nickname(path, route)
163
163
  defined_nicknames.each{|nickname| return true if nickname == target_nickname }
164
164
  false
165
165
  end
166
166
 
167
- def generate_resource(path, apis, models, settings, root, config)
167
+ def generate_resource(path, apis, models, settings, root, config, swagger_config)
168
168
  metadata = ApiDeclarationFileMetadata.new(
169
169
  root["apiVersion"], path, root["basePath"],
170
170
  settings[:controller_base_path],
171
171
  camelize_model_properties: config.fetch(:camelize_model_properties, true),
172
172
  swagger_version: root["swaggerVersion"],
173
- authorizations: root[:authorizations]
173
+ authorizations: root[:authorizations],
174
+ resource_path: swagger_config[:resource_path]
174
175
  )
175
176
  declaration = ApiDeclarationFile.new(metadata, apis, models)
176
177
  declaration.generate_resource
@@ -183,17 +184,20 @@ module Swagger
183
184
  def get_route_path_apis(path, route, klass, settings, config)
184
185
  models, apis = {}, []
185
186
  action = route.defaults[:action]
186
- verb = route_verb(route)
187
- return {apis: apis, models: models, nickname: nil} if !operations = klass.swagger_actions[action.to_sym]
188
- operations = Hash[operations.map {|k, v| [k.to_s.gsub("@","").to_sym, v.respond_to?(:deep_dup) ? v.deep_dup : v.dup] }] # rename :@instance hash keys
189
- operations[:method] = verb
190
- nickname = operations[:nickname] = path_route_nickname(path, route)
187
+ verbs = route_verbs(route)
188
+ return {apis: apis, models: models, nickname: nil} if !operation = klass.swagger_actions[action.to_sym]
189
+ operation = Hash[operation.map {|k, v| [k.to_s.gsub("@","").to_sym, v.respond_to?(:deep_dup) ? v.deep_dup : v.dup] }] # rename :@instance hash keys
190
+ nickname = operation[:nickname] = path_route_nickname(path, route)
191
191
 
192
192
  route_path = if defined?(route.path.spec) then route.path.spec else route.path end
193
193
  api_path = transform_spec_to_api_path(route_path, settings[:controller_base_path], config[:api_extension_type])
194
- operations[:parameters] = filter_path_params(api_path, operations[:parameters]) if operations[:parameters]
195
-
196
- apis << {:path => api_path, :operations => [operations]}
194
+ operation[:parameters] = filter_path_params(api_path, operation[:parameters]) if operation[:parameters]
195
+ operations = verbs.collect{|verb|
196
+ op = operation.dup
197
+ op[:method] = verb
198
+ op
199
+ }
200
+ apis << {:path => api_path, :operations => operations}
197
201
  models = get_klass_models(klass)
198
202
 
199
203
  {apis: apis, models: models, nickname: nickname}
@@ -15,7 +15,7 @@ module Swagger
15
15
  def swagger_model(model_name, &block)
16
16
  end
17
17
 
18
- def swagger_controller(controller, description)
18
+ def swagger_controller(controller, description, params={})
19
19
  end
20
20
  end
21
21
 
@@ -10,6 +10,7 @@ module Swagger
10
10
  def swagger_controller(controller, description, params = {})
11
11
  swagger_config[:controller] = controller
12
12
  swagger_config[:description] = description
13
+ swagger_config[:resource_path] = params[:resource_path]
13
14
  end
14
15
 
15
16
  def swagger_actions
@@ -1,5 +1,5 @@
1
1
  module Swagger
2
2
  module Docs
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.6"
4
4
  end
5
5
  end
@@ -0,0 +1,18 @@
1
+ module Api
2
+ module V1
3
+ class SuperclassController < ApplicationController
4
+ end
5
+ class CustomResourcePathController < SuperclassController
6
+ swagger_controller :custom_resource_path, "User Management", resource_path: "resource/testing"
7
+
8
+ swagger_api :index do
9
+ summary "Fetches all User items"
10
+ param :query, :page, :integer, :optional, "Page number"
11
+ param :path, :nested_id, :integer, :optional, "Team Id"
12
+ response :unauthorized
13
+ response :not_acceptable, "The request you made is not acceptable"
14
+ response :requested_range_not_satisfiable
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module Api
2
+ module V1
3
+ class MultipleRoutesController < ApplicationController
4
+ swagger_controller :multiple_routes, "Multiple Routes"
5
+
6
+ swagger_api :index do
7
+ summary "Creates a new User"
8
+ param :form, :first_name, :string, :required, "First name"
9
+ response :unauthorized
10
+ end
11
+ end
12
+ end
13
+ end
@@ -31,6 +31,7 @@ module Api
31
31
  param :form, :email, :string, :required, "Email address"
32
32
  param_list :form, :role, :string, :required, "Role", [ "admin", "superadmin", "user" ]
33
33
  param :body, :body, :json, :required, 'JSON formatted body'
34
+ items '{$ref" => "setup"}'
34
35
  response :unauthorized
35
36
  response :not_acceptable
36
37
  end
@@ -73,6 +74,7 @@ module Api
73
74
  description "A Tag object."
74
75
  property :id, :integer, :required, "User Id"
75
76
  property :name, :string, :optional, "Name", foo: "test"
77
+ property_list :type, :string, :optional, "Type", ["info", "warning", "error"]
76
78
  end
77
79
  end
78
80
  end
@@ -29,7 +29,6 @@ describe Swagger::Docs::ApiDeclarationFile do
29
29
  }
30
30
  ]
31
31
  end
32
-
33
32
  let(:models) do
34
33
  {
35
34
  :Tag=>
@@ -46,13 +45,11 @@ describe Swagger::Docs::ApiDeclarationFile do
46
45
  }
47
46
  }
48
47
  end
49
-
50
48
  let(:metadata) do
51
49
  Swagger::Docs::ApiDeclarationFileMetadata.new("1.0", "api/v1/sample", "http://api.no.where/", "")
52
50
  end
53
51
 
54
52
  describe "#generate_resource" do
55
-
56
53
  it "generates the appropriate response" do
57
54
  declaration = described_class.new(metadata, apis, models)
58
55
 
@@ -69,7 +66,6 @@ describe Swagger::Docs::ApiDeclarationFile do
69
66
  expect(declaration.generate_resource).to eq(expected_response)
70
67
  end
71
68
  end
72
-
73
69
  describe "#base_path" do
74
70
  it "returns metadata.base_path" do
75
71
  metadata = double("metadata", base_path: "/hello")
@@ -77,7 +73,6 @@ describe Swagger::Docs::ApiDeclarationFile do
77
73
  expect(declaration.base_path).to eq(metadata.base_path)
78
74
  end
79
75
  end
80
-
81
76
  describe "#path" do
82
77
  it "returns metadata.path" do
83
78
  metadata = double("metadata", path: "/hello")
@@ -85,7 +80,6 @@ describe Swagger::Docs::ApiDeclarationFile do
85
80
  expect(declaration.path).to eq(metadata.path)
86
81
  end
87
82
  end
88
-
89
83
  describe "#controller_base_path" do
90
84
  it "returns metadata.controller_base_path" do
91
85
  metadata = double("metadata", controller_base_path: "/hello")
@@ -93,7 +87,20 @@ describe Swagger::Docs::ApiDeclarationFile do
93
87
  expect(declaration.controller_base_path).to eq(metadata.controller_base_path)
94
88
  end
95
89
  end
96
-
90
+ describe "#resource_path" do
91
+ it "returns the debased controller path" do
92
+ metadata = double("metadata", overridden_resource_path: nil, controller_base_path: "/hello", path: "/hello/test-endpoint")
93
+ declaration = described_class.new(metadata, apis, models)
94
+ expect(declaration.resource_path).to eq("test_endpoint")
95
+ end
96
+ context "with an overridden_resource_path" do
97
+ it "returns the overriden resource path directly" do
98
+ metadata = double("metadata", overridden_resource_path: "testing-path", controller_base_path: "/hello", path: "/hello/test-endpoint")
99
+ declaration = described_class.new(metadata, apis, models)
100
+ expect(declaration.resource_path).to eq("testing-path")
101
+ end
102
+ end
103
+ end
97
104
  describe "#swagger_version" do
98
105
  it "returns metadata.swagger_version" do
99
106
  metadata = double("metadata", swagger_version: "1.2")
@@ -101,7 +108,6 @@ describe Swagger::Docs::ApiDeclarationFile do
101
108
  expect(declaration.swagger_version).to eq(metadata.swagger_version)
102
109
  end
103
110
  end
104
-
105
111
  describe "#api_version" do
106
112
  it "returns metadata.api_version" do
107
113
  metadata = double("metadata", api_version: "1.0")
@@ -109,7 +115,6 @@ describe Swagger::Docs::ApiDeclarationFile do
109
115
  expect(declaration.api_version).to eq(metadata.api_version)
110
116
  end
111
117
  end
112
-
113
118
  describe "#camelize_model_properties" do
114
119
  it "returns metadata.camelize_model_properties" do
115
120
  metadata = double("metadata", camelize_model_properties: false)
@@ -117,7 +122,6 @@ describe Swagger::Docs::ApiDeclarationFile do
117
122
  expect(declaration.camelize_model_properties).to eq(metadata.camelize_model_properties)
118
123
  end
119
124
  end
120
-
121
125
  describe "#models" do
122
126
  context "with camelize_model_properties set to true" do
123
127
  it "returns a models hash that's ready for output" do
@@ -141,7 +145,6 @@ describe Swagger::Docs::ApiDeclarationFile do
141
145
  expect(declaration.models).to eq(expected_models_hash)
142
146
  end
143
147
  end
144
-
145
148
  context "with camelize_model_properties set to false" do
146
149
  it "returns a models hash that's ready for output" do
147
150
  declaration = described_class.new(metadata, apis, models)
@@ -165,7 +168,6 @@ describe Swagger::Docs::ApiDeclarationFile do
165
168
  end
166
169
  end
167
170
  end
168
-
169
171
  describe "#apis" do
170
172
  it "returns a api hash that's ready for output" do
171
173
  declaration = described_class.new(metadata, apis, models)
@@ -14,6 +14,7 @@ describe Swagger::Docs::Generator do
14
14
  stub_route( "^GET$", "index", "api/v1/ignored", "/api/v1/ignored(.:format)"),
15
15
  stub_route( "^GET$", "index", "api/v1/sample", "/api/v1/sample(.:format)"),
16
16
  stub_string_verb_route("GET", "index", "api/v1/nested", "/api/v1/nested/:nested_id/nested_sample(.:format)"),
17
+ stub_string_verb_route("GET", "index", "api/v1/custom_resource_path", "/api/v1/custom_resource_path/:custom_resource_path/custom_resource_path_sample(.:format)"),
17
18
  stub_route( "^PATCH$", "create", "api/v1/sample", "/api/v1/sample(.:format)"),
18
19
  stub_route( "^PUT$", "create", "api/v1/sample", "/api/v1/sample(.:format)"), # intentional duplicate of above route to ensure PATCH is used
19
20
  stub_route( "^GET$", "show", "api/v1/sample", "/api/v1/sample/:id(.:format)"),
@@ -21,13 +22,22 @@ describe Swagger::Docs::Generator do
21
22
  stub_route( "^DELETE$", "destroy", "api/v1/sample", "/api/v1/sample/:id(.:format)"),
22
23
  stub_route( "^GET$", "new", "api/v1/sample", "/api/v1/sample/new(.:format)"), # no parameters for this method
23
24
  stub_route( "^GET$", "index", "", "/api/v1/empty_path"), # intentional empty path should not cause any errors
24
- stub_route( "^GET$", "ignored", "api/v1/sample", "/api/v1/ignored(.:format)") # an action without documentation should not cause any errors
25
+ stub_route( "^GET$", "ignored", "api/v1/sample", "/api/v1/ignored(.:format)"), # an action without documentation should not cause any errors
26
+ stub_route( "^GET|POST$","index", "api/v1/multiple_routes", "/api/v1/multiple_routes(.:format)") # multiple route methods
25
27
  ]}
26
28
 
27
29
  let(:tmp_dir) { Pathname.new('/tmp/swagger-docs/') }
28
30
  let(:file_resources) { tmp_dir + 'api-docs.json' }
29
31
  let(:file_resource) { tmp_dir + 'api/v1/sample.json' }
30
32
  let(:file_resource_nested) { tmp_dir + 'nested.json' }
33
+ let(:file_resource_custom_resource_path) { tmp_dir + 'custom_resource_path.json' }
34
+
35
+ let(:controllers) { [
36
+ "fixtures/controllers/sample_controller",
37
+ "fixtures/controllers/nested_controller",
38
+ "fixtures/controllers/custom_resource_path_controller",
39
+ "fixtures/controllers/multiple_routes_controller"
40
+ ]}
31
41
 
32
42
  context "without controller base path" do
33
43
  let(:config) {
@@ -89,7 +99,6 @@ describe Swagger::Docs::Generator do
89
99
  end
90
100
  end
91
101
  end
92
-
93
102
  context "with controller base path" do
94
103
  let(:config) { Swagger::Docs::Config.register_apis({
95
104
  DEFAULT_VER => {:controller_base_path => "api/v1", :api_file_path => "#{tmp_dir}", :base_path => "http://api.no.where/",
@@ -106,13 +115,14 @@ describe Swagger::Docs::Generator do
106
115
  }
107
116
  })}
108
117
  let(:file_resource) { tmp_dir + 'sample.json' }
118
+ let(:resource) { file_resource.read }
119
+ let(:response) { JSON.parse(resource) }
120
+ let(:apis) { response["apis"] }
109
121
  before(:each) do
110
122
  allow(Rails).to receive_message_chain(:application, :routes, :routes).and_return(routes)
111
123
  Swagger::Docs::Generator.set_real_methods
112
- require "fixtures/controllers/sample_controller"
113
- require "fixtures/controllers/nested_controller"
124
+ controllers.each{ |path| require path }
114
125
  end
115
-
116
126
  context "test suite initialization" do
117
127
  it "the resources file does not exist" do
118
128
  expect(file_resource).to_not exist
@@ -121,7 +131,6 @@ describe Swagger::Docs::Generator do
121
131
  expect(file_resource).to_not exist
122
132
  end
123
133
  end
124
-
125
134
  describe "#write_docs" do
126
135
  context "no apis registered" do
127
136
  before(:each) do
@@ -129,7 +138,7 @@ describe Swagger::Docs::Generator do
129
138
  end
130
139
  it "generates using default config" do
131
140
  results = generate({})
132
- expect(results[DEFAULT_VER][:processed].count).to eq 2
141
+ expect(results[DEFAULT_VER][:processed].count).to eq(controllers.count)
133
142
  end
134
143
  end
135
144
  before(:each) do
@@ -174,7 +183,7 @@ describe Swagger::Docs::Generator do
174
183
  end
175
184
  it "returns results hash" do
176
185
  results = generate(config)
177
- expect(results[DEFAULT_VER][:processed].count).to eq 2
186
+ expect(results[DEFAULT_VER][:processed].count).to eq(controllers.count)
178
187
  expect(results[DEFAULT_VER][:skipped].count).to eq 1
179
188
  end
180
189
  it "writes pretty json files when set" do
@@ -196,7 +205,7 @@ describe Swagger::Docs::Generator do
196
205
  expect(response["basePath"]).to eq "http://api.no.where/api/v1"
197
206
  end
198
207
  it "writes apis correctly" do
199
- expect(response["apis"].count).to eq 2
208
+ expect(response["apis"].count).to eq(controllers.count)
200
209
  end
201
210
  it "writes api path correctly" do
202
211
  expect(response["apis"][0]["path"]).to eq "/sample.{format}"
@@ -221,10 +230,18 @@ describe Swagger::Docs::Generator do
221
230
  end
222
231
  end
223
232
  end
233
+ context "multiple routes resource file" do
234
+ let(:file_resource) { tmp_dir + 'multiple_routes.json' }
235
+ it "handles multiple GET path" do
236
+ resource = get_api_operation(apis, "/multiple_routes", :get)
237
+ expect(resource["method"]).to eq "get"
238
+ end
239
+ it "handles multiple POST path" do
240
+ resource = get_api_operation(apis, "/multiple_routes", :post)
241
+ expect(resource["method"]).to eq "post"
242
+ end
243
+ end
224
244
  context "sample resource file" do
225
- let(:resource) { file_resource.read }
226
- let(:response) { JSON.parse(resource) }
227
- let(:apis) { response["apis"] }
228
245
  # {"apiVersion":"1.0","swaggerVersion":"1.2","basePath":"/api/v1","resourcePath":"/sample"
229
246
  it "writes version correctly" do
230
247
  expect(response["apiVersion"]).to eq DEFAULT_VER
@@ -347,6 +364,7 @@ describe Swagger::Docs::Generator do
347
364
  expect(get_api_parameter(api, "role")["allowableValues"]).to eq expected_param
348
365
  expect(get_api_parameter(api, "body")).to eq expected_body
349
366
  expect(api["consumes"]).to eq ["application/json", "text/xml"]
367
+ expect(api["items"]).to eq("{$ref\" => \"setup\"}")
350
368
  end
351
369
  it "doesn't write out route put method" do
352
370
  expect(get_api_operation(apis, "sample", :put)).to be_nil
@@ -386,12 +404,33 @@ describe Swagger::Docs::Generator do
386
404
  "id" => {
387
405
  "type" => "integer",
388
406
  "description" => "User Id",
407
+ },
408
+ "type" => {
409
+ "type" => "string",
410
+ "description" => "Type",
411
+ "allowableValues" => {
412
+ "valueType" => "LIST",
413
+ "values" => [
414
+ "info",
415
+ "warning",
416
+ "error"
417
+ ]
418
+ }
389
419
  }
390
420
  }
391
421
  }
392
422
  expect(models['Tag']).to eq expected_model
393
423
  end
394
424
  end
425
+ context "custom resource_path resource file" do
426
+ let(:resource) { file_resource_custom_resource_path.read }
427
+ let(:response) { JSON.parse(resource) }
428
+ let(:apis) { response["apis"] }
429
+ # {"apiVersion":"1.0","swaggerVersion":"1.2","basePath":"/api/v1","resourcePath":"/sample"
430
+ it "writes resourcePath correctly" do
431
+ expect(response["resourcePath"]).to eq "resource/testing"
432
+ end
433
+ end
395
434
  end
396
435
  end
397
436
  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.2.1
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich Hollis
@@ -133,7 +133,9 @@ files:
133
133
  - lib/swagger/docs/version.rb
134
134
  - lib/tasks/swagger.rake
135
135
  - spec/fixtures/controllers/application_controller.rb
136
+ - spec/fixtures/controllers/custom_resource_path_controller.rb
136
137
  - spec/fixtures/controllers/ignored_controller.rb
138
+ - spec/fixtures/controllers/multiple_routes_controller.rb
137
139
  - spec/fixtures/controllers/nested_controller.rb
138
140
  - spec/fixtures/controllers/sample_controller.rb
139
141
  - spec/lib/swagger/docs/api_declaration_file_metadata_spec.rb
@@ -171,7 +173,9 @@ summary: Generates swagger-ui json files for rails apps with APIs. You add the s
171
173
  DSL to your controller classes and then run one rake task to generate the json files.
172
174
  test_files:
173
175
  - spec/fixtures/controllers/application_controller.rb
176
+ - spec/fixtures/controllers/custom_resource_path_controller.rb
174
177
  - spec/fixtures/controllers/ignored_controller.rb
178
+ - spec/fixtures/controllers/multiple_routes_controller.rb
175
179
  - spec/fixtures/controllers/nested_controller.rb
176
180
  - spec/fixtures/controllers/sample_controller.rb
177
181
  - spec/lib/swagger/docs/api_declaration_file_metadata_spec.rb