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,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'response' do
|
4
|
-
include_context
|
4
|
+
include_context 'the api entities'
|
5
5
|
|
6
6
|
before :all do
|
7
7
|
module TheApi
|
@@ -9,27 +9,26 @@ describe 'response' do
|
|
9
9
|
format :json
|
10
10
|
|
11
11
|
desc 'This returns something',
|
12
|
-
|
13
|
-
|
12
|
+
params: Entities::UseResponse.documentation,
|
13
|
+
failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }]
|
14
14
|
post '/params_response' do
|
15
|
-
{
|
15
|
+
{ 'declared_params' => declared(params) }
|
16
16
|
end
|
17
17
|
|
18
18
|
desc 'This returns something',
|
19
|
-
|
20
|
-
|
19
|
+
entity: Entities::UseResponse,
|
20
|
+
failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }]
|
21
21
|
get '/entity_response' do
|
22
|
-
{
|
22
|
+
{ 'declared_params' => declared(params) }
|
23
23
|
end
|
24
24
|
|
25
25
|
desc 'This returns something',
|
26
|
-
|
27
|
-
|
26
|
+
entity: Entities::UseItemResponseAsType,
|
27
|
+
failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }]
|
28
28
|
get '/nested_type' do
|
29
|
-
{
|
29
|
+
{ 'declared_params' => declared(params) }
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
32
|
add_swagger_documentation
|
34
33
|
end
|
35
34
|
end
|
@@ -39,143 +38,100 @@ describe 'response' do
|
|
39
38
|
TheApi::ResponseApi
|
40
39
|
end
|
41
40
|
|
42
|
-
describe
|
41
|
+
describe 'uses nested type as response object' do
|
43
42
|
subject do
|
44
43
|
get '/swagger_doc/nested_type'
|
45
44
|
JSON.parse(last_response.body)
|
46
45
|
end
|
47
46
|
specify do
|
48
|
-
expect(subject).to eql(
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
"ResponseItem"=>{
|
72
|
-
"type"=>"object",
|
73
|
-
"properties"=>{"id"=>{"type"=>"integer", "format"=>"int32"}, "name"=>{"type"=>"string"}}
|
74
|
-
},
|
75
|
-
"UseItemResponseAsType"=>{
|
76
|
-
"type"=>"object",
|
77
|
-
"properties"=>{"description"=>{"type"=>"string"}, "responses"=>{"$ref"=>"#/definitions/ResponseItem"}},
|
78
|
-
"description"=>"This returns something"
|
79
|
-
},
|
80
|
-
"ApiError"=>{
|
81
|
-
"type"=>"object",
|
82
|
-
"properties"=>{"code"=>{"type"=>"integer", "format"=>"int32"}, "message"=>{"type"=>"string"}},
|
83
|
-
"description"=>"This returns something"
|
84
|
-
}}
|
47
|
+
expect(subject['paths']['/nested_type']['get']).to eql(
|
48
|
+
'description' => 'This returns something',
|
49
|
+
'produces' => ['application/json'],
|
50
|
+
'responses' => {
|
51
|
+
'200' => { 'description' => 'This returns something', 'schema' => { '$ref' => '#/definitions/UseItemResponseAsType' } },
|
52
|
+
'400' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }
|
53
|
+
},
|
54
|
+
'tags' => ['nested_type'],
|
55
|
+
'operationId' => 'getNestedType')
|
56
|
+
expect(subject['definitions']).to eql(
|
57
|
+
'ResponseItem' => {
|
58
|
+
'type' => 'object',
|
59
|
+
'properties' => { 'id' => { 'type' => 'integer', 'format' => 'int32' }, 'name' => { 'type' => 'string' } }
|
60
|
+
},
|
61
|
+
'UseItemResponseAsType' => {
|
62
|
+
'type' => 'object',
|
63
|
+
'properties' => { 'description' => { 'type' => 'string' }, 'responses' => { '$ref' => '#/definitions/ResponseItem' } },
|
64
|
+
'description' => 'This returns something'
|
65
|
+
},
|
66
|
+
'ApiError' => {
|
67
|
+
'type' => 'object',
|
68
|
+
'properties' => { 'code' => { 'type' => 'integer', 'format' => 'int32' }, 'message' => { 'type' => 'string' } },
|
69
|
+
'description' => 'This returns something'
|
85
70
|
})
|
86
71
|
end
|
87
72
|
end
|
88
73
|
|
89
|
-
describe
|
74
|
+
describe 'uses entity as response object' do
|
90
75
|
subject do
|
91
76
|
get '/swagger_doc/entity_response'
|
92
77
|
JSON.parse(last_response.body)
|
93
78
|
end
|
94
79
|
|
95
80
|
specify do
|
96
|
-
expect(subject).to eql(
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
"UseResponse"=>{
|
121
|
-
"type"=>"object",
|
122
|
-
"properties"=>{"description"=>{"type"=>"string"}, "$responses"=>{"type"=>"array", "items"=>{"$ref"=>"#/definitions/ResponseItem"}}},
|
123
|
-
"description"=>"This returns something"
|
124
|
-
},
|
125
|
-
"ApiError"=>{
|
126
|
-
"type"=>"object",
|
127
|
-
"properties"=>{"code"=>{"type"=>"integer", "format"=>"int32"}, "message"=>{"type"=>"string"}},
|
128
|
-
"description"=>"This returns something"
|
129
|
-
}
|
130
|
-
}})
|
81
|
+
expect(subject['paths']['/entity_response']['get']).to eql(
|
82
|
+
'description' => 'This returns something',
|
83
|
+
'produces' => ['application/json'],
|
84
|
+
'responses' => {
|
85
|
+
'200' => { 'description' => 'This returns something', 'schema' => { '$ref' => '#/definitions/UseResponse' } },
|
86
|
+
'400' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }
|
87
|
+
},
|
88
|
+
'tags' => ['entity_response'],
|
89
|
+
'operationId' => 'getEntityResponse')
|
90
|
+
expect(subject['definitions']).to eql(
|
91
|
+
'ResponseItem' => {
|
92
|
+
'type' => 'object',
|
93
|
+
'properties' => { 'id' => { 'type' => 'integer', 'format' => 'int32' }, 'name' => { 'type' => 'string' } }
|
94
|
+
},
|
95
|
+
'UseResponse' => {
|
96
|
+
'type' => 'object',
|
97
|
+
'properties' => { 'description' => { 'type' => 'string' }, '$responses' => { 'type' => 'array', 'items' => { '$ref' => '#/definitions/ResponseItem' } } },
|
98
|
+
'description' => 'This returns something'
|
99
|
+
},
|
100
|
+
'ApiError' => {
|
101
|
+
'type' => 'object',
|
102
|
+
'properties' => { 'code' => { 'type' => 'integer', 'format' => 'int32' }, 'message' => { 'type' => 'string' } },
|
103
|
+
'description' => 'This returns something'
|
104
|
+
})
|
131
105
|
end
|
132
106
|
end
|
133
107
|
|
134
|
-
describe
|
108
|
+
describe 'uses params as response object' do
|
135
109
|
subject do
|
136
110
|
get '/swagger_doc/params_response'
|
137
111
|
JSON.parse(last_response.body)
|
138
112
|
end
|
139
113
|
|
140
114
|
specify do
|
141
|
-
expect(subject).to eql(
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
{
|
148
|
-
{"name"=>"entity_response", "description"=>"Operations about entity_responses"},
|
149
|
-
{"name"=>"nested_type", "description"=>"Operations about nested_types"}
|
115
|
+
expect(subject['paths']['/params_response']['post']).to eql(
|
116
|
+
'description' => 'This returns something',
|
117
|
+
'produces' => ['application/json'],
|
118
|
+
'consumes' => ['application/json'],
|
119
|
+
'parameters' => [
|
120
|
+
{ 'in' => 'formData', 'name' => 'description', 'type' => 'string', 'required' => false },
|
121
|
+
{ 'in' => 'formData', 'name' => '$responses', 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => false }
|
150
122
|
],
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
"201"=>{"description"=>"This returns something", "schema"=>{"$ref"=>"#/definitions/ParamsResponse"}},
|
164
|
-
"400"=>{"description"=>"NotFound", "schema"=>{"$ref"=>"#/definitions/ApiError"}}}
|
165
|
-
}}},
|
166
|
-
"definitions"=>{
|
167
|
-
"ParamsResponse"=>{
|
168
|
-
"type"=>"object",
|
169
|
-
"properties"=>{"description"=>{"type"=>"string"}, "$responses"=>{"type"=>"string"}},
|
170
|
-
"description"=>"This returns something"
|
171
|
-
},
|
172
|
-
"ApiError"=>{
|
173
|
-
"type"=>"object",
|
174
|
-
"properties"=>{"code"=>{"type"=>"integer", "format"=>"int32"}, "message"=>{"type"=>"string"}},
|
175
|
-
"description"=>"This returns something"
|
176
|
-
}
|
177
|
-
}})
|
123
|
+
'responses' => {
|
124
|
+
'201' => { 'description' => 'This returns something' },
|
125
|
+
'400' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }
|
126
|
+
},
|
127
|
+
'tags' => ['params_response'],
|
128
|
+
'operationId' => 'postParamsResponse')
|
129
|
+
expect(subject['definitions']).to eql(
|
130
|
+
'ApiError' => {
|
131
|
+
'type' => 'object',
|
132
|
+
'properties' => { 'code' => { 'type' => 'integer', 'format' => 'int32' }, 'message' => { 'type' => 'string' } },
|
133
|
+
'description' => 'This returns something'
|
134
|
+
})
|
178
135
|
end
|
179
136
|
end
|
180
|
-
|
181
137
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'swagger spec v2.0' do
|
4
|
-
include_context
|
4
|
+
include_context 'swagger example'
|
5
5
|
|
6
6
|
def app
|
7
7
|
Class.new(Grape::API) do
|
@@ -10,7 +10,7 @@ describe 'swagger spec v2.0' do
|
|
10
10
|
# Thing stuff
|
11
11
|
desc 'This gets Things.' do
|
12
12
|
params Entities::Something.documentation
|
13
|
-
http_codes [
|
13
|
+
http_codes [{ code: 401, message: 'Unauthorized', model: Entities::ApiError }]
|
14
14
|
end
|
15
15
|
get '/thing' do
|
16
16
|
something = OpenStruct.new text: 'something'
|
@@ -29,7 +29,7 @@ describe 'swagger spec v2.0' do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
desc 'This gets Thing.' do
|
32
|
-
http_codes [
|
32
|
+
http_codes [{ code: 200, message: 'getting a single thing' }, { code: 401, message: 'Unauthorized' }]
|
33
33
|
end
|
34
34
|
params do
|
35
35
|
requires :id, type: Integer
|
@@ -40,18 +40,18 @@ describe 'swagger spec v2.0' do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
desc 'This creates Thing.',
|
43
|
-
|
43
|
+
success: Entities::Something
|
44
44
|
params do
|
45
45
|
requires :text, type: String, documentation: { type: 'string', desc: 'Content of something.' }
|
46
46
|
requires :links, type: Array, documentation: { type: 'link', is_array: true }
|
47
47
|
end
|
48
|
-
post '/thing', http_codes: [
|
48
|
+
post '/thing', http_codes: [{ code: 422, message: 'Unprocessible Entity' }] do
|
49
49
|
something = OpenStruct.new text: 'something'
|
50
50
|
present something, with: Entities::Something
|
51
51
|
end
|
52
52
|
|
53
53
|
desc 'This updates Thing.',
|
54
|
-
|
54
|
+
success: Entities::Something
|
55
55
|
params do
|
56
56
|
requires :id, type: Integer
|
57
57
|
optional :text, type: String, desc: 'Content of something.'
|
@@ -63,7 +63,7 @@ describe 'swagger spec v2.0' do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
desc 'This deletes Thing.',
|
66
|
-
|
66
|
+
entity: Entities::Something
|
67
67
|
params do
|
68
68
|
requires :id, type: Integer
|
69
69
|
end
|
@@ -73,7 +73,7 @@ describe 'swagger spec v2.0' do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
desc 'dummy route.',
|
76
|
-
|
76
|
+
failure: [{ code: 401, message: 'Unauthorized' }]
|
77
77
|
params do
|
78
78
|
requires :id, type: Integer
|
79
79
|
end
|
@@ -82,11 +82,11 @@ describe 'swagger spec v2.0' do
|
|
82
82
|
|
83
83
|
namespace :other_thing do
|
84
84
|
desc 'nested route inside namespace',
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
entity: Entities::QueryInput,
|
86
|
+
x: {
|
87
|
+
'amazon-apigateway-auth' => { type: 'none' },
|
88
|
+
'amazon-apigateway-integration' => { type: 'aws', uri: 'foo_bar_uri', httpMethod: 'get' }
|
89
|
+
}
|
90
90
|
|
91
91
|
params do
|
92
92
|
requires :elements, documentation: {
|
@@ -102,19 +102,18 @@ describe 'swagger spec v2.0' do
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
|
106
105
|
version 'v3', using: :path
|
107
106
|
add_swagger_documentation api_version: 'v1',
|
108
107
|
base_path: '/api',
|
109
108
|
info: {
|
110
|
-
title:
|
111
|
-
description:
|
112
|
-
contact_name:
|
113
|
-
contact_email:
|
114
|
-
contact_url:
|
115
|
-
license:
|
116
|
-
license_url:
|
117
|
-
terms_of_service_url:
|
109
|
+
title: 'The API title to be displayed on the API homepage.',
|
110
|
+
description: 'A description of the API.',
|
111
|
+
contact_name: 'Contact name',
|
112
|
+
contact_email: 'Contact@email.com',
|
113
|
+
contact_url: 'Contact URL',
|
114
|
+
license: 'The name of the license.',
|
115
|
+
license_url: 'www.The-URL-of-the-license.org',
|
116
|
+
terms_of_service_url: 'www.The-URL-of-the-terms-and-service.com'
|
118
117
|
}
|
119
118
|
end
|
120
119
|
end
|
@@ -128,28 +127,28 @@ describe 'swagger spec v2.0' do
|
|
128
127
|
describe 'swagger object' do
|
129
128
|
describe 'required keys' do
|
130
129
|
it { expect(json.keys).to include 'swagger' }
|
131
|
-
it { expect(json['swagger']).to eql '2.0'
|
130
|
+
it { expect(json['swagger']).to eql '2.0' }
|
132
131
|
it { expect(json.keys).to include 'info' }
|
133
|
-
it { expect(json['info']).to be_a Hash
|
132
|
+
it { expect(json['info']).to be_a Hash }
|
134
133
|
it { expect(json.keys).to include 'paths' }
|
135
|
-
it { expect(json['paths']).to be_a Hash
|
134
|
+
it { expect(json['paths']).to be_a Hash }
|
136
135
|
end
|
137
136
|
|
138
137
|
describe 'info object required keys' do
|
139
138
|
let(:info) { json['info'] }
|
140
139
|
|
141
140
|
it { expect(info.keys).to include 'title' }
|
142
|
-
it { expect(info['title']).to be_a String
|
141
|
+
it { expect(info['title']).to be_a String }
|
143
142
|
it { expect(info.keys).to include 'version' }
|
144
|
-
it { expect(info['version']).to be_a String
|
143
|
+
it { expect(info['version']).to be_a String }
|
145
144
|
|
146
145
|
describe 'license object' do
|
147
146
|
let(:license) { json['info']['license'] }
|
148
147
|
|
149
148
|
it { expect(license.keys).to include 'name' }
|
150
|
-
it { expect(license['name']).to be_a String
|
149
|
+
it { expect(license['name']).to be_a String }
|
151
150
|
it { expect(license.keys).to include 'url' }
|
152
|
-
it { expect(license['url']).to be_a String
|
151
|
+
it { expect(license['url']).to be_a String }
|
153
152
|
end
|
154
153
|
|
155
154
|
describe 'contact object' do
|
@@ -158,16 +157,16 @@ describe 'swagger spec v2.0' do
|
|
158
157
|
it { expect(contact.keys).to include 'name' }
|
159
158
|
it { expect(contact['name']).to be_a String }
|
160
159
|
it { expect(contact.keys).to include 'email' }
|
161
|
-
it { expect(contact['email']).to be_a String
|
160
|
+
it { expect(contact['email']).to be_a String }
|
162
161
|
it { expect(contact.keys).to include 'url' }
|
163
|
-
it { expect(contact['url']).to be_a String
|
162
|
+
it { expect(contact['url']).to be_a String }
|
164
163
|
end
|
165
164
|
end
|
166
165
|
|
167
166
|
describe 'path object' do
|
168
167
|
let(:paths) { json['paths'] }
|
169
168
|
|
170
|
-
it
|
169
|
+
it 'hides documentation paths per default' do
|
171
170
|
expect(paths.keys).not_to include '/swagger_doc', '/swagger_doc/{name}'
|
172
171
|
end
|
173
172
|
|
@@ -181,7 +180,7 @@ describe 'swagger spec v2.0' do
|
|
181
180
|
expect(http_verbs).to include method
|
182
181
|
expect(declaration).to have_key('responses')
|
183
182
|
|
184
|
-
declaration[
|
183
|
+
declaration['responses'].each do |status_code, response|
|
185
184
|
expect(status_code).to match(/\d{3}/)
|
186
185
|
expect(response).to have_key('description')
|
187
186
|
end
|
@@ -201,7 +200,7 @@ describe 'swagger spec v2.0' do
|
|
201
200
|
end
|
202
201
|
end
|
203
202
|
|
204
|
-
describe
|
203
|
+
describe 'swagger file' do
|
205
204
|
it { expect(json).to eql swagger_json }
|
206
205
|
end
|
207
206
|
end
|
@@ -43,7 +43,7 @@ describe 'type format settings' do
|
|
43
43
|
|
44
44
|
class TypeFormatApi < Grape::API
|
45
45
|
desc 'full set of request data types',
|
46
|
-
|
46
|
+
success: TheApi::Entities::TypedDefinition
|
47
47
|
|
48
48
|
params do
|
49
49
|
# grape supported data types
|
@@ -56,15 +56,13 @@ describe 'type format settings' do
|
|
56
56
|
requires :param_date, type: Date
|
57
57
|
requires :param_date_time, type: DateTime
|
58
58
|
requires :param_time, type: Time
|
59
|
-
requires :param_password, type: 'password'
|
60
|
-
requires :param_email, type: 'email'
|
61
59
|
optional :param_boolean, type: Boolean
|
62
60
|
optional :param_file, type: File
|
63
61
|
optional :param_json, type: JSON
|
64
62
|
end
|
65
63
|
|
66
64
|
post '/request_types' do
|
67
|
-
{
|
65
|
+
{ 'declared_params' => declared(params) }
|
68
66
|
end
|
69
67
|
|
70
68
|
add_swagger_documentation
|
@@ -82,40 +80,38 @@ describe 'type format settings' do
|
|
82
80
|
end
|
83
81
|
|
84
82
|
specify do
|
85
|
-
expect(subject['paths']['/request_types']['post']['parameters']).to eql(
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
])
|
83
|
+
expect(subject['paths']['/request_types']['post']['parameters']).to eql(
|
84
|
+
[
|
85
|
+
{ 'in' => 'formData', 'name' => 'param_integer', 'required' => true, 'type' => 'integer', 'format' => 'int32' },
|
86
|
+
{ 'in' => 'formData', 'name' => 'param_long', 'required' => true, 'type' => 'integer', 'format' => 'int64' },
|
87
|
+
{ 'in' => 'formData', 'name' => 'param_float', 'required' => true, 'type' => 'number', 'format' => 'float' },
|
88
|
+
{ 'in' => 'formData', 'name' => 'param_double', 'required' => true, 'type' => 'number', 'format' => 'double' },
|
89
|
+
{ 'in' => 'formData', 'name' => 'param_string', 'required' => false, 'type' => 'string' },
|
90
|
+
{ 'in' => 'formData', 'name' => 'param_symbol', 'required' => false, 'type' => 'string' },
|
91
|
+
{ 'in' => 'formData', 'name' => 'param_date', 'required' => true, 'type' => 'string', 'format' => 'date' },
|
92
|
+
{ 'in' => 'formData', 'name' => 'param_date_time', 'required' => true, 'type' => 'string', 'format' => 'date-time' },
|
93
|
+
{ 'in' => 'formData', 'name' => 'param_time', 'required' => true, 'type' => 'string', 'format' => 'date-time' },
|
94
|
+
{ 'in' => 'formData', 'name' => 'param_boolean', 'required' => false, 'type' => 'boolean' },
|
95
|
+
{ 'in' => 'formData', 'name' => 'param_file', 'required' => false, 'type' => 'file' },
|
96
|
+
{ 'in' => 'formData', 'name' => 'param_json', 'required' => false, 'type' => 'json' }
|
97
|
+
])
|
101
98
|
end
|
102
99
|
|
103
100
|
specify do
|
104
|
-
expect(subject['definitions']['TypedDefinition']['properties']).to eql(
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
})
|
101
|
+
expect(subject['definitions']['TypedDefinition']['properties']).to eql(
|
102
|
+
'prop_integer' => { 'type' => 'integer', 'format' => 'int32', 'description' => 'prop_integer description' },
|
103
|
+
'prop_long' => { 'type' => 'integer', 'format' => 'int64', 'description' => 'prop_long description' },
|
104
|
+
'prop_float' => { 'type' => 'number', 'format' => 'float', 'description' => 'prop_float description' },
|
105
|
+
'prop_double' => { 'type' => 'number', 'format' => 'double', 'description' => 'prop_double description' },
|
106
|
+
'prop_string' => { 'type' => 'string', 'description' => 'prop_string description' },
|
107
|
+
'prop_symbol' => { 'type' => 'string', 'description' => 'prop_symbol description' },
|
108
|
+
'prop_date' => { 'type' => 'string', 'format' => 'date', 'description' => 'prop_date description' },
|
109
|
+
'prop_date_time' => { 'type' => 'string', 'format' => 'date-time', 'description' => 'prop_date_time description' },
|
110
|
+
'prop_time' => { 'type' => 'string', 'format' => 'date-time', 'description' => 'prop_time description' },
|
111
|
+
'prop_password' => { 'type' => 'string', 'format' => 'password', 'description' => 'prop_password description' },
|
112
|
+
'prop_email' => { 'type' => 'string', 'format' => 'email', 'description' => 'prop_email description' },
|
113
|
+
'prop_boolean' => { 'type' => 'boolean', 'description' => 'prop_boolean description' },
|
114
|
+
'prop_file' => { 'type' => 'file', 'description' => 'prop_file description' },
|
115
|
+
'prop_json' => { 'type' => 'json', 'description' => 'prop_json description' })
|
120
116
|
end
|
121
117
|
end
|