grape-swagger 0.20.2 → 0.20.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -3
- data/.rubocop_todo.yml +43 -33
- data/.travis.yml +22 -13
- data/CHANGELOG.md +29 -53
- data/Gemfile +1 -1
- data/README.md +24 -24
- data/example/api/endpoints.rb +28 -29
- data/example/api/entities.rb +1 -1
- data/example/config.ru +5 -7
- data/grape-swagger.gemspec +1 -1
- data/lib/grape-swagger.rb +9 -6
- data/lib/grape-swagger/doc_methods.rb +1 -1
- data/lib/grape-swagger/doc_methods/extensions.rb +3 -3
- data/lib/grape-swagger/doc_methods/headers.rb +1 -1
- data/lib/grape-swagger/doc_methods/move_params.rb +25 -16
- data/lib/grape-swagger/doc_methods/operation_id.rb +2 -2
- data/lib/grape-swagger/doc_methods/parse_params.rb +12 -5
- data/lib/grape-swagger/doc_methods/path_string.rb +1 -1
- data/lib/grape-swagger/doc_methods/status_codes.rb +3 -1
- data/lib/grape-swagger/doc_methods/tag_name_description.rb +1 -1
- data/lib/grape-swagger/endpoint.rb +33 -46
- data/lib/grape-swagger/grape/route.rb +16 -0
- data/lib/grape-swagger/version.rb +1 -1
- data/spec/issues/403_versions_spec.rb +158 -0
- data/spec/lib/data_type_spec.rb +9 -10
- data/spec/lib/endpoint_spec.rb +1 -2
- data/spec/lib/extensions_spec.rb +44 -40
- data/spec/lib/move_params_spec.rb +113 -93
- data/spec/lib/operation_id_spec.rb +42 -12
- data/spec/lib/optional_object_spec.rb +3 -4
- data/spec/lib/path_string_spec.rb +2 -2
- data/spec/lib/produces_consumes_spec.rb +64 -53
- data/spec/markdown/redcarpet_adapter_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/api_swagger_v2_result.rb +122 -128
- data/spec/support/namespace_tags.rb +17 -19
- data/spec/support/the_api_entities.rb +1 -3
- data/spec/support/the_paths_definitions.rb +95 -85
- data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +1 -1
- data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +19 -19
- data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +21 -21
- data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +34 -32
- data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +5 -7
- data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +19 -18
- data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +9 -10
- data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +21 -24
- data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +90 -92
- data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +54 -54
- data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +65 -57
- data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +17 -14
- data/spec/swagger_v2/api_swagger_v2_response_spec.rb +79 -123
- data/spec/swagger_v2/api_swagger_v2_spec.rb +33 -34
- data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +32 -36
- data/spec/swagger_v2/boolean_params_spec.rb +1 -1
- data/spec/swagger_v2/default_api_spec.rb +26 -29
- data/spec/swagger_v2/description_not_initialized.rb +3 -3
- data/spec/swagger_v2/float_api_spec.rb +1 -1
- data/spec/swagger_v2/form_params_spec.rb +4 -4
- data/spec/swagger_v2/hide_api_spec.rb +48 -51
- data/spec/swagger_v2/host.rb +1 -1
- data/spec/swagger_v2/mounted_target_class_spec.rb +31 -33
- data/spec/swagger_v2/namespace_tags_prefix_spec.rb +23 -21
- data/spec/swagger_v2/namespace_tags_spec.rb +23 -20
- data/spec/swagger_v2/param_type_spec.rb +5 -6
- data/spec/swagger_v2/param_values_spec.rb +31 -37
- data/spec/swagger_v2/params_array_spec.rb +17 -15
- data/spec/swagger_v2/params_hash_spec.rb +17 -15
- data/spec/swagger_v2/params_nested_spec.rb +12 -10
- data/spec/swagger_v2/reference_entity.rb +9 -9
- data/spec/swagger_v2/response_model_spec.rb +58 -62
- data/spec/swagger_v2/simple_mounted_api_spec.rb +179 -147
- metadata +5 -10
- data/spec/params_entity_spec.rb +0 -49
@@ -1,11 +1,9 @@
|
|
1
|
-
RSpec.shared_context
|
1
|
+
RSpec.shared_context 'namespace example' do
|
2
2
|
before :all do
|
3
3
|
module TheApi
|
4
|
-
|
5
4
|
class CustomType; end
|
6
5
|
|
7
6
|
class NamespaceApi < Grape::API
|
8
|
-
|
9
7
|
namespace :hudson do
|
10
8
|
desc 'Document root'
|
11
9
|
get '/' do
|
@@ -14,7 +12,7 @@ RSpec.shared_context "namespace example" do
|
|
14
12
|
|
15
13
|
namespace :colorado do
|
16
14
|
desc 'This gets something.',
|
17
|
-
|
15
|
+
notes: '_test_'
|
18
16
|
|
19
17
|
get '/simple' do
|
20
18
|
{ bla: 'something' }
|
@@ -23,7 +21,7 @@ RSpec.shared_context "namespace example" do
|
|
23
21
|
|
24
22
|
namespace :colorado do
|
25
23
|
desc 'This gets something for URL using - separator.',
|
26
|
-
|
24
|
+
notes: '_test_'
|
27
25
|
|
28
26
|
get '/simple-test' do
|
29
27
|
{ bla: 'something' }
|
@@ -32,14 +30,14 @@ RSpec.shared_context "namespace example" do
|
|
32
30
|
|
33
31
|
namespace :thames do
|
34
32
|
desc 'this gets something else',
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
33
|
+
headers: {
|
34
|
+
'XAuthToken' => { description: 'A required header.', required: true },
|
35
|
+
'XOtherHeader' => { description: 'An optional header.', required: false }
|
36
|
+
},
|
37
|
+
http_codes: [
|
38
|
+
{ code: 403, message: 'invalid pony' },
|
39
|
+
{ code: 405, message: 'no ponies left!' }
|
40
|
+
]
|
43
41
|
|
44
42
|
get '/simple_with_headers' do
|
45
43
|
{ bla: 'something_else' }
|
@@ -48,9 +46,9 @@ RSpec.shared_context "namespace example" do
|
|
48
46
|
|
49
47
|
namespace :niles do
|
50
48
|
desc 'this takes an array of parameters',
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
params: {
|
50
|
+
'items[]' => { description: 'array of items', is_array: true }
|
51
|
+
}
|
54
52
|
|
55
53
|
post '/items' do
|
56
54
|
{}
|
@@ -59,9 +57,9 @@ RSpec.shared_context "namespace example" do
|
|
59
57
|
|
60
58
|
namespace :niles do
|
61
59
|
desc 'this uses a custom parameter',
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
params: {
|
61
|
+
'custom' => { type: CustomType, description: 'array of items', is_array: true }
|
62
|
+
}
|
65
63
|
|
66
64
|
get '/custom' do
|
67
65
|
{}
|
@@ -1,94 +1,104 @@
|
|
1
|
-
RSpec.shared_context
|
2
|
-
let(:paths)
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
"/in_body/{key}" => {
|
24
|
-
put: {
|
25
|
-
produces: ["application/json"],
|
26
|
-
consumes: ["application/json"],
|
27
|
-
parameters: [
|
28
|
-
{in: "path", name: "key", description: nil, type: "integer", format: "int32", required: true},
|
29
|
-
{in: "body", name: "in_body_1", description: "in_body_1", type: "integer", format: "int32", required: true},
|
30
|
-
{in: "body", name: "in_body_2", description: "in_body_2", type: "string", required: false},
|
31
|
-
{in: "body", name: "in_body_3", description: "in_body_3", type: "string", required: false}
|
32
|
-
],
|
33
|
-
responses: {200 => {description: "put in body /wo entity", schema: {"$ref" => "#/definitions/InBody"}}},
|
34
|
-
tags: ["in_body"],
|
35
|
-
operationId: "putInBodyKey"
|
1
|
+
RSpec.shared_context 'the api paths/defs' do
|
2
|
+
let(:paths) do
|
3
|
+
{
|
4
|
+
'/in_body' => {
|
5
|
+
post: {
|
6
|
+
produces: ['application/json'],
|
7
|
+
consumes: ['application/json'],
|
8
|
+
parameters: [
|
9
|
+
{ in: 'body', name: 'in_body_1', description: 'in_body_1', type: 'integer', format: 'int32', required: true },
|
10
|
+
{ in: 'body', name: 'in_body_2', description: 'in_body_2', type: 'string', required: false },
|
11
|
+
{ in: 'body', name: 'in_body_3', description: 'in_body_3', type: 'string', required: false }
|
12
|
+
],
|
13
|
+
responses: { 201 => { description: 'post in body /wo entity', schema: { '$ref' => '#/definitions/InBody' } } },
|
14
|
+
tags: ['in_body'],
|
15
|
+
operationId: 'postInBody'
|
16
|
+
},
|
17
|
+
get: {
|
18
|
+
produces: ['application/json'],
|
19
|
+
responses: { 200 => { description: 'get in path /wo entity', schema: { '$ref' => '#/definitions/InBody' } } },
|
20
|
+
tags: ['in_body'],
|
21
|
+
operationId: 'getInBody'
|
22
|
+
}
|
36
23
|
},
|
37
|
-
|
38
|
-
|
24
|
+
'/in_body/{key}' => {
|
25
|
+
put: {
|
26
|
+
produces: ['application/json'],
|
27
|
+
consumes: ['application/json'],
|
28
|
+
parameters: [
|
29
|
+
{ in: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true },
|
30
|
+
{ in: 'body', name: 'in_body_1', description: 'in_body_1', type: 'integer', format: 'int32', required: true },
|
31
|
+
{ in: 'body', name: 'in_body_2', description: 'in_body_2', type: 'string', required: false },
|
32
|
+
{ in: 'body', name: 'in_body_3', description: 'in_body_3', type: 'string', required: false }
|
33
|
+
],
|
34
|
+
responses: { 200 => { description: 'put in body /wo entity', schema: { '$ref' => '#/definitions/InBody' } } },
|
35
|
+
tags: ['in_body'],
|
36
|
+
operationId: 'putInBodyKey'
|
37
|
+
},
|
38
|
+
get: {
|
39
|
+
produces: ['application/json'],
|
40
|
+
parameters: [
|
41
|
+
{ in: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true }
|
42
|
+
],
|
43
|
+
responses: { 200 => { description: 'get in path /wo entity', schema: { '$ref' => '#/definitions/InBody' } } },
|
44
|
+
tags: ['in_body'],
|
45
|
+
operationId: 'getInBodyKey'
|
46
|
+
} }
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
let(:found_path) do
|
51
|
+
{
|
52
|
+
post: {
|
53
|
+
produces: ['application/json'],
|
54
|
+
consumes: ['application/json'],
|
39
55
|
parameters: [
|
40
|
-
{in:
|
56
|
+
{ in: 'body', name: 'in_body_1', description: 'in_body_1', type: 'integer', format: 'int32', required: true },
|
57
|
+
{ in: 'body', name: 'in_body_2', description: 'in_body_2', type: 'string', required: false },
|
58
|
+
{ in: 'body', name: 'in_body_3', description: 'in_body_3', type: 'string', required: false }
|
41
59
|
],
|
42
|
-
responses: {
|
43
|
-
tags: [
|
44
|
-
operationId:
|
45
|
-
|
46
|
-
|
60
|
+
responses: { 201 => { description: 'post in body /wo entity', schema: { '$ref' => '#/definitions/InBody' } } },
|
61
|
+
tags: ['in_body'],
|
62
|
+
operationId: 'postInBody'
|
63
|
+
} }
|
64
|
+
end
|
47
65
|
|
48
|
-
let(:
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
operationId: "postInBody"
|
60
|
-
}}}
|
66
|
+
let(:definitions) do
|
67
|
+
{
|
68
|
+
'InBody' => {
|
69
|
+
type: 'object',
|
70
|
+
properties: {
|
71
|
+
in_body_1: { type: 'integer', format: 'int32' },
|
72
|
+
in_body_2: { type: 'string' },
|
73
|
+
in_body_3: { type: 'string' },
|
74
|
+
key: { type: 'integer', format: 'int32' }
|
75
|
+
} } }
|
76
|
+
end
|
61
77
|
|
62
|
-
let(:
|
63
|
-
|
64
|
-
type:
|
78
|
+
let(:expected_post_defs) do
|
79
|
+
{
|
80
|
+
type: 'object',
|
65
81
|
properties: {
|
66
|
-
in_body_1: {type:
|
67
|
-
in_body_2: {type:
|
68
|
-
in_body_3: {type:
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
type: "object",
|
74
|
-
properties: {
|
75
|
-
in_body_1: {type: "integer", format: "int32", description: "in_body_1"},
|
76
|
-
in_body_2: {type: "string", description: "in_body_2"},
|
77
|
-
in_body_3: {type: "string", description: "in_body_3"}
|
78
|
-
},
|
79
|
-
:required=>[:in_body_1]
|
80
|
-
}}
|
82
|
+
in_body_1: { type: 'integer', format: 'int32', description: 'in_body_1' },
|
83
|
+
in_body_2: { type: 'string', description: 'in_body_2' },
|
84
|
+
in_body_3: { type: 'string', description: 'in_body_3' }
|
85
|
+
},
|
86
|
+
required: [:in_body_1]
|
87
|
+
}
|
88
|
+
end
|
81
89
|
|
82
|
-
let(:expected_put_defs)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
90
|
+
let(:expected_put_defs) do
|
91
|
+
{
|
92
|
+
type: 'object',
|
93
|
+
properties: {
|
94
|
+
in_body_1: { type: 'integer', format: 'int32', description: 'in_body_1' },
|
95
|
+
in_body_2: { type: 'string', description: 'in_body_2' },
|
96
|
+
in_body_3: { type: 'string', description: 'in_body_3' },
|
97
|
+
key: { type: 'integer', format: 'int32', readOnly: true }
|
98
|
+
},
|
99
|
+
required: [:in_body_1]
|
100
|
+
}
|
101
|
+
end
|
92
102
|
|
93
|
-
let(:expected_path) {[]}
|
103
|
+
let(:expected_path) { [] }
|
94
104
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
def details
|
6
|
-
<<-DETAILS
|
6
|
+
<<-DETAILS
|
7
7
|
# Burgers in Heaven
|
8
8
|
|
9
9
|
> A burger doesn't come for free
|
@@ -23,8 +23,8 @@ DETAILS
|
|
23
23
|
end
|
24
24
|
|
25
25
|
describe 'details' do
|
26
|
-
describe
|
27
|
-
include_context
|
26
|
+
describe 'take deatils as it is' do
|
27
|
+
include_context 'the api entities'
|
28
28
|
|
29
29
|
before :all do
|
30
30
|
module TheApi
|
@@ -32,20 +32,20 @@ describe 'details' do
|
|
32
32
|
format :json
|
33
33
|
|
34
34
|
desc 'This returns something',
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
detail: 'detailed description of the route',
|
36
|
+
entity: Entities::UseResponse,
|
37
|
+
failure: [{ code: 400, model: Entities::ApiError }]
|
38
38
|
get '/use_detail' do
|
39
|
-
{
|
39
|
+
{ 'declared_params' => declared(params) }
|
40
40
|
end
|
41
41
|
|
42
42
|
desc 'This returns something' do
|
43
43
|
detail 'detailed description of the route inside the `desc` block'
|
44
44
|
entity Entities::UseResponse
|
45
|
-
failure [{code: 400, model: Entities::ApiError}]
|
45
|
+
failure [{ code: 400, model: Entities::ApiError }]
|
46
46
|
end
|
47
47
|
get '/use_detail_block' do
|
48
|
-
{
|
48
|
+
{ 'declared_params' => declared(params) }
|
49
49
|
end
|
50
50
|
|
51
51
|
add_swagger_documentation
|
@@ -74,7 +74,7 @@ describe 'details' do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
describe 'details, convert markdown with kramdown' do
|
77
|
-
include_context
|
77
|
+
include_context 'the api entities'
|
78
78
|
|
79
79
|
before :all do
|
80
80
|
module TheApi
|
@@ -82,11 +82,11 @@ describe 'details' do
|
|
82
82
|
format :json
|
83
83
|
|
84
84
|
desc 'This returns something',
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
detail: details,
|
86
|
+
entity: Entities::UseResponse,
|
87
|
+
failure: [{ code: 400, model: Entities::ApiError }]
|
88
88
|
get '/use_gfm_detail' do
|
89
|
-
{
|
89
|
+
{ 'declared_params' => declared(params) }
|
90
90
|
end
|
91
91
|
|
92
92
|
add_swagger_documentation markdown: GrapeSwagger::Markdown::KramdownAdapter.new
|
@@ -112,7 +112,7 @@ describe 'details' do
|
|
112
112
|
end
|
113
113
|
|
114
114
|
describe 'details, convert markdown with redcarpet', unless: RUBY_PLATFORM.eql?('java') do
|
115
|
-
include_context
|
115
|
+
include_context 'the api entities'
|
116
116
|
|
117
117
|
before :all do
|
118
118
|
module TheApi
|
@@ -120,11 +120,11 @@ describe 'details' do
|
|
120
120
|
format :json
|
121
121
|
|
122
122
|
desc 'This returns something',
|
123
|
-
|
124
|
-
|
125
|
-
|
123
|
+
detail: details,
|
124
|
+
entity: Entities::UseResponse,
|
125
|
+
failure: [{ code: 400, model: Entities::ApiError }]
|
126
126
|
get '/use_gfm_rc_detail' do
|
127
|
-
{
|
127
|
+
{ 'declared_params' => declared(params) }
|
128
128
|
end
|
129
129
|
|
130
130
|
add_swagger_documentation markdown: GrapeSwagger::Markdown::RedcarpetAdapter.new
|
@@ -1,50 +1,50 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'extension' do
|
4
|
-
include_context
|
4
|
+
include_context 'the api entities'
|
5
5
|
|
6
6
|
before :all do
|
7
7
|
module TheApi
|
8
8
|
class ExtensionsApi < Grape::API
|
9
9
|
format :json
|
10
10
|
|
11
|
-
route_setting :x_path,
|
11
|
+
route_setting :x_path, some: 'stuff'
|
12
12
|
|
13
13
|
desc 'This returns something with extension on path level',
|
14
|
-
|
15
|
-
|
14
|
+
params: Entities::UseResponse.documentation,
|
15
|
+
failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }]
|
16
16
|
get '/path_extension' do
|
17
|
-
{
|
17
|
+
{ 'declared_params' => declared(params) }
|
18
18
|
end
|
19
19
|
|
20
20
|
desc 'This returns something with extension on verb level',
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
params: Entities::UseResponse.documentation,
|
22
|
+
failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }],
|
23
|
+
x: { some: 'stuff' }
|
24
24
|
params do
|
25
25
|
requires :id, type: Integer
|
26
26
|
end
|
27
27
|
get '/verb_extension' do
|
28
|
-
{
|
28
|
+
{ 'declared_params' => declared(params) }
|
29
29
|
end
|
30
30
|
|
31
|
-
route_setting :x_def,
|
31
|
+
route_setting :x_def, for: 200, some: 'stuff'
|
32
32
|
|
33
33
|
desc 'This returns something with extension on definition level',
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
params: Entities::ResponseItem.documentation,
|
35
|
+
success: Entities::ResponseItem,
|
36
|
+
failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }]
|
37
37
|
get '/definitions_extension' do
|
38
|
-
{
|
38
|
+
{ 'declared_params' => declared(params) }
|
39
39
|
end
|
40
40
|
|
41
41
|
route_setting :x_def, [{ for: 422, other: 'stuff' }, { for: 200, some: 'stuff' }]
|
42
42
|
|
43
43
|
desc 'This returns something with extension on definition level',
|
44
|
-
|
45
|
-
|
44
|
+
success: Entities::OtherItem,
|
45
|
+
failure: [{ code: 422, message: 'NotFound', model: Entities::SecondApiError }]
|
46
46
|
get '/multiple_definitions_extension' do
|
47
|
-
{
|
47
|
+
{ 'declared_params' => declared(params) }
|
48
48
|
end
|
49
49
|
|
50
50
|
add_swagger_documentation
|
@@ -56,7 +56,7 @@ describe 'extension' do
|
|
56
56
|
TheApi::ExtensionsApi
|
57
57
|
end
|
58
58
|
|
59
|
-
describe
|
59
|
+
describe 'extension on path level' do
|
60
60
|
subject do
|
61
61
|
get '/swagger_doc/path_extension'
|
62
62
|
JSON.parse(last_response.body)
|
@@ -68,7 +68,7 @@ describe 'extension' do
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
describe
|
71
|
+
describe 'extension on verb level' do
|
72
72
|
subject do
|
73
73
|
get '/swagger_doc/verb_extension'
|
74
74
|
JSON.parse(last_response.body)
|
@@ -80,7 +80,7 @@ describe 'extension' do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
describe
|
83
|
+
describe 'extension on definition level' do
|
84
84
|
subject do
|
85
85
|
get '/swagger_doc/definitions_extension'
|
86
86
|
JSON.parse(last_response.body)
|
@@ -93,7 +93,7 @@ describe 'extension' do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
describe
|
96
|
+
describe 'extension on definition level' do
|
97
97
|
subject do
|
98
98
|
get '/swagger_doc/multiple_definitions_extension'
|
99
99
|
JSON.parse(last_response.body)
|