grape-swagger 0.25.0 → 0.25.1
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 +4 -4
- data/.rubocop_todo.yml +1 -1
- data/CHANGELOG.md +13 -0
- data/README.md +47 -13
- data/lib/grape-swagger.rb +7 -1
- data/lib/grape-swagger/doc_methods/data_type.rb +2 -1
- data/lib/grape-swagger/doc_methods/move_params.rb +10 -0
- data/lib/grape-swagger/doc_methods/parse_params.rb +2 -0
- data/lib/grape-swagger/doc_methods/status_codes.rb +2 -0
- data/lib/grape-swagger/endpoint.rb +13 -5
- data/lib/grape-swagger/version.rb +1 -1
- data/spec/issues/533_specify_status_code_spec.rb +76 -0
- data/spec/issues/539_array_post_body.rb +63 -0
- data/spec/support/namespace_tags.rb +17 -0
- data/spec/swagger_v2/api_swagger_v2_ignore_defaults_spec.rb +3 -3
- data/spec/swagger_v2/parent_less_namespace.rb +47 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05e6839d574113d1a31a0b1758bb9426174b2dd5
|
4
|
+
data.tar.gz: ad8936f7e557193a2502e95d64c8ef7c90a04684
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0ed0cbb32dbe1998964427703cee5e7399f67dad503ba1bd04569b913343bb67e5782da445340e4eda390a1f0c424edd08546a06189047de7d2f9ce3bc55463
|
7
|
+
data.tar.gz: f01ba1a06247a146fed67950c98257d5708965531558f18468391da001e848aea03c2a80e3e19431337b10a2d912783ba8e50ed0fcedca3285ac7c637364d7ed
|
data/.rubocop_todo.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,19 @@
|
|
8
8
|
|
9
9
|
* Your contribution here.
|
10
10
|
|
11
|
+
|
12
|
+
### 0.25.1 (November 29, 2016)
|
13
|
+
|
14
|
+
#### Features
|
15
|
+
|
16
|
+
* [#531](https://github.com/ruby-grape/grape-swagger/pull/531): UUID data_type format support - [@migmartri](https://github.com/migmartri).
|
17
|
+
* [#534](https://github.com/ruby-grape/grape-swagger/pull/534): Allows to overwrite defaults status codes - [@LeFnord](https://github.com/LeFnord).
|
18
|
+
|
19
|
+
#### Fixes
|
20
|
+
|
21
|
+
* [#540](https://github.com/ruby-grape/grape-swagger/pull/540): Corrects exposing of array in post body - [@LeFnord](https://github.com/LeFnord).
|
22
|
+
* [#509](https://github.com/ruby-grape/grape-swagger/pull/509), [#529](https://github.com/ruby-grape/grape-swagger/pull/529): Making parent-less routes working - [@mur-wtag](https://github.com/mur-wtag).
|
23
|
+
|
11
24
|
### 0.25.0 (October 31, 2016)
|
12
25
|
|
13
26
|
#### Features
|
data/README.md
CHANGED
@@ -52,6 +52,8 @@ grape-swagger | swagger spec | grape | grape-entity | represen
|
|
52
52
|
0.20.3 | 2.0 | >= 0.12.0 ... ~> 0.16.2 | ~> 0.5.1 | n/a |
|
53
53
|
0.21.0 | 2.0 | >= 0.12.0 ... <= 0.16.2 | <= 0.5.1 | >= 2.4.1 |
|
54
54
|
0.23.0 | 2.0 | >= 0.12.0 ... <= 0.17.0 | <= 0.5.1 | >= 2.4.1 |
|
55
|
+
0.24.0 | 2.0 | >= 0.12.0 ... <= 0.18.0 | <= 0.5.1 | >= 2.4.1 |
|
56
|
+
0.25.0 | 2.0 | >= 0.14.0 ... <= 0.18.0 | <= 0.5.2 | >= 2.4.1 |
|
55
57
|
|
56
58
|
<a name="swagger-spec" />
|
57
59
|
## Swagger-Spec
|
@@ -402,6 +404,7 @@ add_swagger_documentation \
|
|
402
404
|
* [Hiding parameters](#hiding-parameters)
|
403
405
|
* [Setting a Swagger default value](#default-value)
|
404
406
|
* [Response documentation](#response)
|
407
|
+
* [Changing default status codes](#change-status)
|
405
408
|
* [Extensions](#extensions)
|
406
409
|
|
407
410
|
|
@@ -750,7 +753,7 @@ You can also document the HTTP status codes with a description and a specified m
|
|
750
753
|
In the following cases, the schema ref would be taken from route.
|
751
754
|
|
752
755
|
```ruby
|
753
|
-
desc 'thing', failures: [ { code: 400, message:
|
756
|
+
desc 'thing', failures: [ { code: 400, message: 'Invalid parameter entry' } ]
|
754
757
|
get '/thing' do
|
755
758
|
...
|
756
759
|
end
|
@@ -759,7 +762,7 @@ end
|
|
759
762
|
```ruby
|
760
763
|
desc 'thing' do
|
761
764
|
params Entities::Something.documentation
|
762
|
-
failures [ { code: 400, message:
|
765
|
+
failures [ { code: 400, message: 'Invalid parameter entry' } ]
|
763
766
|
end
|
764
767
|
get '/thing' do
|
765
768
|
...
|
@@ -768,8 +771,8 @@ end
|
|
768
771
|
|
769
772
|
```ruby
|
770
773
|
get '/thing', failures: [
|
771
|
-
{ code:
|
772
|
-
{ code:
|
774
|
+
{ code: 400, message: 'Invalid parameter entry' },
|
775
|
+
{ code: 404, message: 'Not authorized' },
|
773
776
|
] do
|
774
777
|
...
|
775
778
|
end
|
@@ -778,13 +781,13 @@ end
|
|
778
781
|
By adding a `model` key, e.g. this would be taken.
|
779
782
|
```ruby
|
780
783
|
get '/thing', failures: [
|
781
|
-
{ code:
|
782
|
-
{ code: 422, message:
|
784
|
+
{ code: 400, message: 'General error' },
|
785
|
+
{ code: 422, message: 'Invalid parameter entry', model: Entities::ApiError }
|
783
786
|
] do
|
784
787
|
...
|
785
788
|
end
|
786
789
|
```
|
787
|
-
If no status code is defined [defaults](/lib/grape-swagger/endpoint.rb#
|
790
|
+
If no status code is defined [defaults](/lib/grape-swagger/endpoint.rb#L210) would be taken.
|
788
791
|
|
789
792
|
The result is then something like following:
|
790
793
|
|
@@ -805,6 +808,33 @@ The result is then something like following:
|
|
805
808
|
},
|
806
809
|
```
|
807
810
|
|
811
|
+
<a name="change-status" />
|
812
|
+
#### Changing default status codes
|
813
|
+
|
814
|
+
The default status codes, one could be found (-> [status codes](lib/grape-swagger/doc_methods/status_codes.rb)) can be changed to your specific needs, to achive it, you have to change it for grape itself and for the documentation.
|
815
|
+
|
816
|
+
```ruby
|
817
|
+
desc 'Get a list of stuff',
|
818
|
+
success: { code: 202, model: Entities::UseResponse, message: 'a changed status code' }
|
819
|
+
get do
|
820
|
+
status 202
|
821
|
+
# your code comes here
|
822
|
+
end
|
823
|
+
…
|
824
|
+
```
|
825
|
+
|
826
|
+
```json
|
827
|
+
"responses": {
|
828
|
+
"202": {
|
829
|
+
"description": "ok",
|
830
|
+
"schema": {
|
831
|
+
"$ref": "#/definitions/UseResponse"
|
832
|
+
}
|
833
|
+
}
|
834
|
+
},
|
835
|
+
```
|
836
|
+
|
837
|
+
|
808
838
|
<a name="extensions" />
|
809
839
|
#### Extensions
|
810
840
|
|
@@ -926,7 +956,7 @@ module API
|
|
926
956
|
class Client < Grape::Entity
|
927
957
|
expose :name, documentation: { type: 'string', desc: 'Name' }
|
928
958
|
expose :addresses, using: Entities::Address,
|
929
|
-
documentation: { type: '
|
959
|
+
documentation: { type: 'Entities::Address', desc: 'Addresses.', param_type: 'body', is_array: true }
|
930
960
|
end
|
931
961
|
|
932
962
|
class Address < Grape::Entity
|
@@ -937,13 +967,15 @@ module API
|
|
937
967
|
class Clients < Grape::API
|
938
968
|
version 'v1'
|
939
969
|
|
940
|
-
desc 'Clients index',
|
970
|
+
desc 'Clients index',
|
971
|
+
params: Entities::Client.documentation,
|
972
|
+
success: Entities::Client
|
941
973
|
get '/clients' do
|
942
974
|
...
|
943
975
|
end
|
944
976
|
end
|
945
977
|
|
946
|
-
add_swagger_documentation
|
978
|
+
add_swagger_documentation
|
947
979
|
end
|
948
980
|
```
|
949
981
|
|
@@ -958,7 +990,7 @@ module API
|
|
958
990
|
class Client < Grape::Entity
|
959
991
|
expose :name, documentation: { type: 'string', desc: 'Name' }
|
960
992
|
expose :address, using: Entities::Address,
|
961
|
-
documentation: { type: '
|
993
|
+
documentation: { type: 'Entities::Address', desc: 'Addresses.', param_type: 'body', is_array: false }
|
962
994
|
end
|
963
995
|
|
964
996
|
class Address < Grape::Entity
|
@@ -969,13 +1001,15 @@ module API
|
|
969
1001
|
class Clients < Grape::API
|
970
1002
|
version 'v1'
|
971
1003
|
|
972
|
-
desc 'Clients index',
|
1004
|
+
desc 'Clients index',
|
1005
|
+
params: Entities::Client.documentation,
|
1006
|
+
success: Entities::Client
|
973
1007
|
get '/clients' do
|
974
1008
|
...
|
975
1009
|
end
|
976
1010
|
end
|
977
1011
|
|
978
|
-
add_swagger_documentation
|
1012
|
+
add_swagger_documentation
|
979
1013
|
end
|
980
1014
|
```
|
981
1015
|
|
data/lib/grape-swagger.rb
CHANGED
@@ -100,7 +100,7 @@ module Grape
|
|
100
100
|
# iterate over each single namespace
|
101
101
|
namespaces.each do |name, namespace|
|
102
102
|
# get the parent route for the namespace
|
103
|
-
parent_route_name = name
|
103
|
+
parent_route_name = extract_parent_route(name)
|
104
104
|
parent_route = @target_class.combined_routes[parent_route_name]
|
105
105
|
# fetch all routes that are within the current namespace
|
106
106
|
namespace_routes = parent_route.reject do |route|
|
@@ -142,6 +142,12 @@ module Grape
|
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
|
+
def extract_parent_route(name)
|
146
|
+
route_name = name.match(%r{^/?([^/]*).*$})[1]
|
147
|
+
return route_name unless route_name.include? ':'
|
148
|
+
name.match(/\/[a-z]+/)[0].delete('/')
|
149
|
+
end
|
150
|
+
|
145
151
|
def sub_routes_from(parent_route, sub_namespaces)
|
146
152
|
sub_ns_paths = sub_namespaces.collect { |ns_name, _| ["/#{ns_name}", "/:version/#{ns_name}"] }
|
147
153
|
sub_routes = parent_route.reject do |route|
|
@@ -12,6 +12,8 @@ module GrapeSwagger
|
|
12
12
|
@definitions = definitions
|
13
13
|
unify!(params)
|
14
14
|
|
15
|
+
return correct_array_param(params) if should_correct_array?(params)
|
16
|
+
|
15
17
|
params_to_move = movable_params(params)
|
16
18
|
params << parent_definition_of_params(params_to_move, route)
|
17
19
|
|
@@ -20,6 +22,14 @@ module GrapeSwagger
|
|
20
22
|
|
21
23
|
private
|
22
24
|
|
25
|
+
def should_correct_array?(param)
|
26
|
+
param.length == 1 && param.first[:in] == 'body' && param.first[:type] == 'array'
|
27
|
+
end
|
28
|
+
|
29
|
+
def correct_array_param(param)
|
30
|
+
param.first[:schema] = { type: param.first.delete(:type), items: param.first.delete(:items) }
|
31
|
+
end
|
32
|
+
|
23
33
|
def parent_definition_of_params(params, route)
|
24
34
|
definition_name = GrapeSwagger::DocMethods::OperationId.manipulate(parse_model(route.path))
|
25
35
|
referenced_definition = build_definition(definition_name, params, route.request_method.downcase)
|
@@ -68,6 +68,8 @@ module GrapeSwagger
|
|
68
68
|
collection_format = value_type[:documentation][:collectionFormat]
|
69
69
|
end
|
70
70
|
|
71
|
+
param_type ||= value_type[:param_type]
|
72
|
+
|
71
73
|
array_items = {}
|
72
74
|
if definitions[value_type[:data_type]]
|
73
75
|
array_items['$ref'] = "#/definitions/#{@parsed_param[:type]}"
|
@@ -8,6 +8,8 @@ module GrapeSwagger
|
|
8
8
|
post: { code: 201, message: 'created {item}' },
|
9
9
|
put: { code: 200, message: 'updated {item}' },
|
10
10
|
patch: { code: 200, message: 'patched {item}' },
|
11
|
+
# 200 for delete would only be used, if a success entity is given,
|
12
|
+
# else it would be set to 204
|
11
13
|
delete: { code: 200, message: 'deleted {item}' },
|
12
14
|
head: { code: 200, message: 'head {item}' },
|
13
15
|
options: { code: 200, message: 'option {item}' }
|
@@ -178,8 +178,8 @@ module Grape
|
|
178
178
|
|
179
179
|
def response_object(route, markdown)
|
180
180
|
codes = (route.http_codes || route.options[:failure] || [])
|
181
|
-
codes = apply_defaults(route, codes) if route.options[:ignore_defaults].nil?
|
182
181
|
|
182
|
+
codes = apply_success_codes(route) + codes
|
183
183
|
codes.map! { |x| x.is_a?(Array) ? { code: x[0], message: x[1], model: x[2] } : x }
|
184
184
|
|
185
185
|
codes.each_with_object({}) do |value, memo|
|
@@ -207,11 +207,19 @@ module Grape
|
|
207
207
|
end
|
208
208
|
end
|
209
209
|
|
210
|
-
def
|
210
|
+
def apply_success_codes(route)
|
211
211
|
default_code = GrapeSwagger::DocMethods::StatusCodes.get[route.request_method.downcase.to_sym]
|
212
|
-
|
213
|
-
|
214
|
-
|
212
|
+
if @entity.is_a?(Hash)
|
213
|
+
default_code[:code] = @entity[:code] if @entity[:code].present?
|
214
|
+
default_code[:model] = @entity[:model] if @entity[:model].present?
|
215
|
+
default_code[:message] = @entity[:message] || route.description || default_code[:message].sub('{item}', @item)
|
216
|
+
else
|
217
|
+
default_code = GrapeSwagger::DocMethods::StatusCodes.get[route.request_method.downcase.to_sym]
|
218
|
+
default_code[:model] = @entity if @entity
|
219
|
+
default_code[:message] = route.description || default_code[:message].sub('{item}', @item)
|
220
|
+
end
|
221
|
+
|
222
|
+
[default_code]
|
215
223
|
end
|
216
224
|
|
217
225
|
def tag_object(route)
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#533 specify status codes' do
|
4
|
+
include_context "#{MODEL_PARSER} swagger example"
|
5
|
+
|
6
|
+
let(:app) do
|
7
|
+
Class.new(Grape::API) do
|
8
|
+
namespace :issue_533 do
|
9
|
+
desc 'Get a list of stuff',
|
10
|
+
success: { code: 202, model: Entities::UseResponse, message: 'a changed status code' }
|
11
|
+
get do
|
12
|
+
status 202
|
13
|
+
{ foo: 'that is the response' }
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Post some stuff',
|
17
|
+
success: { code: 202, model: Entities::UseResponse, message: 'a changed status code' }
|
18
|
+
post do
|
19
|
+
status 202
|
20
|
+
{ foo: 'that is the response' }
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Post some stuff',
|
24
|
+
success: { code: 204, message: 'a changed status code' }
|
25
|
+
patch do
|
26
|
+
status 204
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'Delete some stuff',
|
30
|
+
success: { code: 203 }
|
31
|
+
delete do
|
32
|
+
status 203
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
add_swagger_documentation format: :json
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
subject do
|
41
|
+
get '/swagger_doc'
|
42
|
+
JSON.parse(last_response.body)['paths']['/issue_533']
|
43
|
+
end
|
44
|
+
|
45
|
+
let(:get_response) { get '/issue_533' }
|
46
|
+
specify { expect(get_response.status).to eql 202 }
|
47
|
+
let(:get_response_documentation) { subject['get']['responses'] }
|
48
|
+
specify do
|
49
|
+
expect(get_response_documentation.keys.first).to eql '202'
|
50
|
+
expect(get_response_documentation['202']).to include 'schema'
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:post_response) { post '/issue_533' }
|
54
|
+
specify { expect(post_response.status).to eql 202 }
|
55
|
+
let(:post_response_documentation) { subject['post']['responses'] }
|
56
|
+
specify do
|
57
|
+
expect(post_response_documentation.keys.first).to eql '202'
|
58
|
+
expect(post_response_documentation['202']).to include 'schema'
|
59
|
+
end
|
60
|
+
|
61
|
+
let(:patch_response) { patch '/issue_533' }
|
62
|
+
specify { expect(patch_response.status).to eql 204 }
|
63
|
+
let(:patch_response_documentation) { subject['patch']['responses'] }
|
64
|
+
specify do
|
65
|
+
expect(patch_response_documentation.keys.first).to eql '204'
|
66
|
+
expect(patch_response_documentation['204']).not_to include 'schema'
|
67
|
+
end
|
68
|
+
|
69
|
+
let(:delete_response) { delete '/issue_533' }
|
70
|
+
specify { expect(delete_response.status).to eql 203 }
|
71
|
+
let(:delete_response_documentation) { subject['delete']['responses'] }
|
72
|
+
specify do
|
73
|
+
expect(delete_response_documentation.keys.first).to eql '203'
|
74
|
+
expect(delete_response_documentation['203']).not_to include 'schema'
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'grape-entity'
|
3
|
+
require 'grape-swagger-entity'
|
4
|
+
|
5
|
+
describe '#427 nested entity given as string' do
|
6
|
+
let(:app) do
|
7
|
+
Class.new(Grape::API) do
|
8
|
+
namespace :issue_427 do
|
9
|
+
class Element < Grape::Entity
|
10
|
+
expose :id
|
11
|
+
expose :description
|
12
|
+
expose :role
|
13
|
+
end
|
14
|
+
|
15
|
+
class ArrayOfElements < Grape::Entity
|
16
|
+
expose :elements,
|
17
|
+
documentation: {
|
18
|
+
type: Element, is_array: true, param_type: 'body', required: true
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'create account',
|
23
|
+
params: ArrayOfElements.documentation
|
24
|
+
post do
|
25
|
+
present params
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
add_swagger_documentation format: :json
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
subject do
|
34
|
+
get '/swagger_doc'
|
35
|
+
JSON.parse(last_response.body)
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:parameters) { subject['paths']['/issue_427']['post']['parameters'] }
|
39
|
+
let(:definitions) { subject['definitions'] }
|
40
|
+
|
41
|
+
specify do
|
42
|
+
expect(parameters).to eql(
|
43
|
+
[
|
44
|
+
{
|
45
|
+
'in' => 'body', 'name' => 'elements', 'required' => true, 'schema' => {
|
46
|
+
'type' => 'array', 'items' => { '$ref' => '#/definitions/Element' }
|
47
|
+
}
|
48
|
+
}
|
49
|
+
]
|
50
|
+
)
|
51
|
+
|
52
|
+
expect(definitions).to eql(
|
53
|
+
'Element' => {
|
54
|
+
'type' => 'object',
|
55
|
+
'properties' => {
|
56
|
+
'id' => { 'type' => 'string' },
|
57
|
+
'description' => { 'type' => 'string' },
|
58
|
+
'role' => { 'type' => 'string' }
|
59
|
+
}
|
60
|
+
}
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
@@ -66,6 +66,23 @@ RSpec.shared_context 'namespace example' do
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
70
|
+
class ParentLessNamespaceApi < Grape::API
|
71
|
+
route_param :animal do
|
72
|
+
route_param :breed do
|
73
|
+
resource :queues do
|
74
|
+
route_param :queue_id do
|
75
|
+
resource :reservations do
|
76
|
+
desc 'Lists all reservations specific type of animal of specific breed in specific queue'
|
77
|
+
get do
|
78
|
+
{ bla: 'Bla Black' }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
69
86
|
end
|
70
87
|
end
|
71
88
|
end
|
@@ -8,12 +8,12 @@ describe 'swagger spec v2.0' do
|
|
8
8
|
format :json
|
9
9
|
|
10
10
|
desc 'This creates Thing after a delay',
|
11
|
-
success: Entities::Something
|
11
|
+
success: { code: 202, message: 'OK', model: Entities::Something }
|
12
12
|
params do
|
13
13
|
requires :text, type: String, documentation: { type: 'string', desc: 'Content of something.' }
|
14
14
|
requires :links, type: Array, documentation: { type: 'link', is_array: true }
|
15
15
|
end
|
16
|
-
post '/delay_thing'
|
16
|
+
post '/delay_thing' do
|
17
17
|
status 202
|
18
18
|
end
|
19
19
|
|
@@ -40,7 +40,7 @@ describe 'swagger spec v2.0' do
|
|
40
40
|
let(:json) { JSON.parse(last_response.body) }
|
41
41
|
|
42
42
|
it 'only returns one response if ignore_defaults is specified' do
|
43
|
-
expect(json['paths']['/delay_thing']['post']['responses']).to eq('202' => { 'description' => 'OK' })
|
43
|
+
expect(json['paths']['/delay_thing']['post']['responses']).to eq('202' => { 'description' => 'OK', 'schema' => { '$ref' => '#/definitions/Something' } })
|
44
44
|
expect(json['paths']['/delay_thing']['post']['responses'].keys).not_to include '201'
|
45
45
|
end
|
46
46
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'a parent less namespace' do
|
4
|
+
include_context 'namespace example'
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
class ParentLessApi < Grape::API
|
8
|
+
prefix :api
|
9
|
+
mount TheApi::ParentLessNamespaceApi
|
10
|
+
add_swagger_documentation version: 'v1'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def app
|
15
|
+
ParentLessApi
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'retrieves swagger-documentation on /swagger_doc' do
|
19
|
+
let(:route_name) { ':animal/:breed/queues/:queue_id/reservations' }
|
20
|
+
subject do
|
21
|
+
get '/api/swagger_doc.json'
|
22
|
+
JSON.parse(last_response.body)
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'not raises error' do
|
26
|
+
specify do
|
27
|
+
expect(subject['tags']).to eql([{ 'name' => 'queues', 'description' => 'Operations about queues' }])
|
28
|
+
expect(subject['paths']['/api/{animal}/{breed}/queues/{queue_id}/reservations']['get']['operationId'])
|
29
|
+
.to eql('getApiAnimalBreedQueuesQueueIdReservations')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'raises error' do
|
34
|
+
specify do
|
35
|
+
allow_any_instance_of(ParentLessApi)
|
36
|
+
.to receive(:extract_parent_route).with(route_name).and_return(':animal') # BUT IT'S NOT STUBBING, CAUSE IT'S A PRIVATE METHODS
|
37
|
+
expect { subject }.to raise_error NoMethodError
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'ParentLessApi.extract_parent_route' do
|
42
|
+
specify do
|
43
|
+
expect(ParentLessApi.send(:extract_parent_route, route_name)).to eq('queues')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-swagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.25.
|
4
|
+
version: 0.25.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Vandecasteele
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
@@ -261,6 +261,8 @@ files:
|
|
261
261
|
- spec/issues/403_versions_spec.rb
|
262
262
|
- spec/issues/427_entity_as_string_spec.rb
|
263
263
|
- spec/issues/430_entity_definitions_spec.rb
|
264
|
+
- spec/issues/533_specify_status_code_spec.rb
|
265
|
+
- spec/issues/539_array_post_body.rb
|
264
266
|
- spec/lib/data_type_spec.rb
|
265
267
|
- spec/lib/endpoint_spec.rb
|
266
268
|
- spec/lib/extensions_spec.rb
|
@@ -324,6 +326,7 @@ files:
|
|
324
326
|
- spec/swagger_v2/params_array_spec.rb
|
325
327
|
- spec/swagger_v2/params_hash_spec.rb
|
326
328
|
- spec/swagger_v2/params_nested_spec.rb
|
329
|
+
- spec/swagger_v2/parent_less_namespace.rb
|
327
330
|
- spec/swagger_v2/reference_entity.rb
|
328
331
|
- spec/swagger_v2/security_requirement_spec.rb
|
329
332
|
- spec/swagger_v2/simple_mounted_api_spec.rb
|
@@ -348,7 +351,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
348
351
|
version: '0'
|
349
352
|
requirements: []
|
350
353
|
rubyforge_project:
|
351
|
-
rubygems_version: 2.6.
|
354
|
+
rubygems_version: 2.6.8
|
352
355
|
signing_key:
|
353
356
|
specification_version: 4
|
354
357
|
summary: Add auto generated documentation to your Grape API that can be displayed
|
@@ -357,6 +360,8 @@ test_files:
|
|
357
360
|
- spec/issues/403_versions_spec.rb
|
358
361
|
- spec/issues/427_entity_as_string_spec.rb
|
359
362
|
- spec/issues/430_entity_definitions_spec.rb
|
363
|
+
- spec/issues/533_specify_status_code_spec.rb
|
364
|
+
- spec/issues/539_array_post_body.rb
|
360
365
|
- spec/lib/data_type_spec.rb
|
361
366
|
- spec/lib/endpoint_spec.rb
|
362
367
|
- spec/lib/extensions_spec.rb
|
@@ -420,6 +425,7 @@ test_files:
|
|
420
425
|
- spec/swagger_v2/params_array_spec.rb
|
421
426
|
- spec/swagger_v2/params_hash_spec.rb
|
422
427
|
- spec/swagger_v2/params_nested_spec.rb
|
428
|
+
- spec/swagger_v2/parent_less_namespace.rb
|
423
429
|
- spec/swagger_v2/reference_entity.rb
|
424
430
|
- spec/swagger_v2/security_requirement_spec.rb
|
425
431
|
- spec/swagger_v2/simple_mounted_api_spec.rb
|