grape-swagger 0.11.0 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +8 -1
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +14 -22
- data/.travis.yml +7 -4
- data/CHANGELOG.md +53 -26
- data/Gemfile +1 -1
- data/README.md +414 -327
- data/RELEASING.md +3 -4
- data/example/api/endpoints.rb +132 -0
- data/example/api/entities.rb +18 -0
- data/example/config.ru +36 -2
- data/example/example_requests.postman_collection +146 -0
- data/example/swagger-example.png +0 -0
- data/grape-swagger.gemspec +9 -6
- data/lib/grape-swagger.rb +69 -99
- data/lib/grape-swagger/doc_methods.rb +69 -544
- data/lib/grape-swagger/doc_methods/data_type.rb +77 -0
- data/lib/grape-swagger/doc_methods/extensions.rb +75 -0
- data/lib/grape-swagger/doc_methods/move_params.rb +153 -0
- data/lib/grape-swagger/doc_methods/operation_id.rb +27 -0
- data/lib/grape-swagger/doc_methods/optional_object.rb +15 -0
- data/lib/grape-swagger/doc_methods/parse_params.rb +113 -0
- data/lib/grape-swagger/doc_methods/path_string.rb +29 -0
- data/lib/grape-swagger/doc_methods/produces_consumes.rb +12 -0
- data/lib/grape-swagger/doc_methods/status_codes.rb +17 -0
- data/lib/grape-swagger/doc_methods/tag_name_description.rb +26 -0
- data/lib/grape-swagger/endpoint.rb +317 -0
- data/lib/grape-swagger/version.rb +1 -1
- data/spec/lib/data_type_spec.rb +57 -0
- data/spec/lib/endpoint_spec.rb +6 -0
- data/spec/lib/extensions_spec.rb +127 -0
- data/spec/lib/move_params_spec.rb +298 -0
- data/spec/lib/operation_id_spec.rb +24 -0
- data/spec/lib/optional_object_spec.rb +40 -0
- data/spec/lib/path_string_spec.rb +38 -0
- data/spec/lib/produces_consumes_spec.rb +98 -0
- data/spec/markdown/kramdown_adapter_spec.rb +2 -9
- data/spec/markdown/redcarpet_adapter_spec.rb +2 -16
- data/spec/spec_helper.rb +7 -13
- data/spec/support/api_swagger_v2_result.rb +204 -0
- data/spec/support/namespace_tags.rb +73 -0
- data/spec/support/the_api_entities.rb +52 -0
- data/spec/support/the_paths_definitions.rb +94 -0
- data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +32 -0
- data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +151 -0
- data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +109 -0
- data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +124 -0
- data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +51 -0
- data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +44 -0
- data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +56 -0
- data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +146 -0
- data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +197 -0
- data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +151 -0
- data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +217 -0
- data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +64 -0
- data/spec/swagger_v2/api_swagger_v2_response_spec.rb +184 -0
- data/spec/swagger_v2/api_swagger_v2_spec.rb +207 -0
- data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +121 -0
- data/spec/{boolean_params_spec.rb → swagger_v2/boolean_params_spec.rb} +2 -2
- data/spec/{default_api_spec.rb → swagger_v2/default_api_spec.rb} +40 -36
- data/spec/swagger_v2/description_not_initialized.rb +39 -0
- data/spec/{float_api_spec.rb → swagger_v2/float_api_spec.rb} +2 -2
- data/spec/{form_params_spec.rb → swagger_v2/form_params_spec.rb} +9 -9
- data/spec/{grape-swagger_spec.rb → swagger_v2/grape-swagger_spec.rb} +0 -0
- data/spec/swagger_v2/hide_api_spec.rb +131 -0
- data/spec/swagger_v2/mounted_target_class_spec.rb +76 -0
- data/spec/swagger_v2/namespace_tags_prefix_spec.rb +84 -0
- data/spec/swagger_v2/namespace_tags_spec.rb +76 -0
- data/spec/{namespaced_api_spec.rb → swagger_v2/namespaced_api_spec.rb} +6 -26
- data/spec/{param_type_spec.rb → swagger_v2/param_type_spec.rb} +10 -8
- data/spec/{param_values_spec.rb → swagger_v2/param_values_spec.rb} +52 -22
- data/spec/swagger_v2/params_array_spec.rb +63 -0
- data/spec/swagger_v2/params_hash_spec.rb +65 -0
- data/spec/swagger_v2/params_nested_spec.rb +63 -0
- data/spec/{reference_entity.rb → swagger_v2/reference_entity.rb} +18 -23
- data/spec/swagger_v2/response_model_spec.rb +212 -0
- data/spec/swagger_v2/simple_mounted_api_spec.rb +264 -0
- metadata +175 -90
- data/example/api.rb +0 -66
- data/lib/grape-swagger/markdown.rb +0 -23
- data/spec/api_description_spec.rb +0 -43
- data/spec/api_global_models_spec.rb +0 -77
- data/spec/api_models_spec.rb +0 -364
- data/spec/api_paths_spec.rb +0 -128
- data/spec/api_root_spec.rb +0 -30
- data/spec/api_with_nil_types.rb +0 -50
- data/spec/api_with_path_versioning_spec.rb +0 -33
- data/spec/api_with_prefix_and_namespace_spec.rb +0 -32
- data/spec/api_with_standalone_namespace_spec.rb +0 -215
- data/spec/array_entity_spec.rb +0 -34
- data/spec/array_params_spec.rb +0 -85
- data/spec/grape-swagger_helper_spec.rb +0 -152
- data/spec/group_params_spec.rb +0 -31
- data/spec/hash_params_spec.rb +0 -30
- data/spec/hide_api_spec.rb +0 -124
- data/spec/i18n_spec.rb +0 -364
- data/spec/markdown/markdown_spec.rb +0 -27
- data/spec/mounted_target_class_spec.rb +0 -63
- data/spec/mutually_exclusive_spec.rb +0 -36
- data/spec/non_default_api_spec.rb +0 -733
- data/spec/response_model_spec.rb +0 -121
- data/spec/simple_mounted_api_spec.rb +0 -213
- data/spec/support/i18n_helper.rb +0 -8
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'API Description' do
|
4
|
-
context 'with no additional options' do
|
5
|
-
subject do
|
6
|
-
Class.new(Grape::API) do
|
7
|
-
add_swagger_documentation
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'describes the API with defaults' do
|
12
|
-
routes = subject.endpoints.first.routes
|
13
|
-
expect(routes.count).to eq 2
|
14
|
-
expect(routes.first.description).to eq 'Swagger compatible API description'
|
15
|
-
expect(routes.first.params).to eq('locale' => { desc: 'Locale of API documentation', type: 'Symbol', required: false })
|
16
|
-
expect(routes.last.description).to eq 'Swagger compatible API description for specific API'
|
17
|
-
expect(routes.last.params).to eq('name' => { desc: 'Resource name of mounted API', type: 'String', required: true },
|
18
|
-
'locale' => { desc: 'Locale of API documentation', type: 'Symbol', required: false })
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'with additional options' do
|
23
|
-
subject do
|
24
|
-
Class.new(Grape::API) do
|
25
|
-
add_swagger_documentation \
|
26
|
-
api_documentation: { desc: 'First', params: { x: 1 }, xx: 11 },
|
27
|
-
specific_api_documentation: { desc: 'Second', params: { y: 42 }, yy: 4242 }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'describes the API with defaults' do
|
32
|
-
routes = subject.endpoints.first.routes
|
33
|
-
expect(routes.count).to eq 2
|
34
|
-
expect(routes.first.description).to eq 'First'
|
35
|
-
expect(routes.first.params).to eq(x: 1, 'locale' => { desc: 'Locale of API documentation', type: 'Symbol', required: false })
|
36
|
-
expect(routes.first.settings[:description][:xx]).to eq(11)
|
37
|
-
expect(routes.last.description).to eq 'Second'
|
38
|
-
expect(routes.last.params).to eq('name' => { desc: 'Resource name of mounted API', type: 'String', required: true }, y: 42,
|
39
|
-
'locale' => { desc: 'Locale of API documentation', type: 'Symbol', required: false })
|
40
|
-
expect(routes.last.options[:yy]).to eq(4242)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Global Models' do
|
4
|
-
before :all do
|
5
|
-
module Entities
|
6
|
-
module Some
|
7
|
-
class Thing < Grape::Entity
|
8
|
-
expose :text, documentation: { type: 'string', desc: 'Content of something.' }
|
9
|
-
expose :name, documentation: { type: String, desc: 'Name of something.' }
|
10
|
-
end
|
11
|
-
|
12
|
-
class CombinedThing < Grape::Entity
|
13
|
-
expose :text, documentation: { type: 'string', desc: 'Content of something.' }
|
14
|
-
expose :created_at, documentation: { type: DateTime, desc: 'Creation of something.' }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
subject do
|
21
|
-
Class.new(Grape::API) do
|
22
|
-
desc 'This gets thing.'
|
23
|
-
get '/thing' do
|
24
|
-
thing = OpenStruct.new text: 'thing'
|
25
|
-
present thing, with: Entities::Some::Thing
|
26
|
-
end
|
27
|
-
|
28
|
-
desc 'This gets combined thing.', entity: Entities::Some::CombinedThing
|
29
|
-
get '/combined_thing' do
|
30
|
-
thing = OpenStruct.new text: 'thing'
|
31
|
-
present thing, with: Entities::Some::CombinedThing
|
32
|
-
end
|
33
|
-
|
34
|
-
add_swagger_documentation models: [Entities::Some::Thing]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def app
|
39
|
-
subject
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'includes models specified' do
|
43
|
-
get '/swagger_doc/thing.json'
|
44
|
-
json = JSON.parse(last_response.body)
|
45
|
-
expect(json['models']).to eq(
|
46
|
-
'Some::Thing' => {
|
47
|
-
'id' => 'Some::Thing',
|
48
|
-
'properties' => {
|
49
|
-
'text' => { 'type' => 'string', 'description' => 'Content of something.' },
|
50
|
-
'name' => { 'type' => 'string', 'description' => 'Name of something.' }
|
51
|
-
}
|
52
|
-
})
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'uses global models and route endpoint specific entities together' do
|
56
|
-
get '/swagger_doc/combined_thing.json'
|
57
|
-
json = JSON.parse(last_response.body)
|
58
|
-
|
59
|
-
expect(json['models']).to include(
|
60
|
-
'Some::Thing' => {
|
61
|
-
'id' => 'Some::Thing',
|
62
|
-
'properties' => {
|
63
|
-
'text' => { 'type' => 'string', 'description' => 'Content of something.' },
|
64
|
-
'name' => { 'type' => 'string', 'description' => 'Name of something.' }
|
65
|
-
}
|
66
|
-
})
|
67
|
-
|
68
|
-
expect(json['models']).to include(
|
69
|
-
'Some::CombinedThing' => {
|
70
|
-
'id' => 'Some::CombinedThing',
|
71
|
-
'properties' => {
|
72
|
-
'text' => { 'type' => 'string', 'description' => 'Content of something.' },
|
73
|
-
'created_at' => { 'type' => 'string', 'format' => 'date-time', 'description' => 'Creation of something.' }
|
74
|
-
}
|
75
|
-
})
|
76
|
-
end
|
77
|
-
end
|
data/spec/api_models_spec.rb
DELETED
@@ -1,364 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'API Models' do
|
4
|
-
before :all do
|
5
|
-
module Entities
|
6
|
-
class Something < Grape::Entity
|
7
|
-
expose :text, documentation: { type: 'string', desc: 'Content of something.' }
|
8
|
-
expose :links, documentation: { type: 'link', is_array: true }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
module Entities
|
13
|
-
class EnumValues < Grape::Entity
|
14
|
-
expose :gender, documentation: { type: 'string', desc: 'Content of something.', values: %w(Male Female) }
|
15
|
-
expose :number, documentation: { type: 'integer', desc: 'Content of something.', values: proc { [1, 2] } }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
module Entities
|
20
|
-
module Some
|
21
|
-
class Thing < Grape::Entity
|
22
|
-
expose :text, documentation: { type: 'string', desc: 'Content of something.' }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
module Entities
|
28
|
-
class ComposedOf < Grape::Entity
|
29
|
-
expose :part_text, documentation: { type: 'string', desc: 'Content of composedof.' }
|
30
|
-
end
|
31
|
-
|
32
|
-
class ComposedOfElse < Grape::Entity
|
33
|
-
def self.entity_name
|
34
|
-
'composed'
|
35
|
-
end
|
36
|
-
expose :part_text, documentation: { type: 'string', desc: 'Content of composedof else.' }
|
37
|
-
end
|
38
|
-
|
39
|
-
class SomeThingElse < Grape::Entity
|
40
|
-
expose :else_text, documentation: { type: 'string', desc: 'Content of something else.' }
|
41
|
-
expose :parts, using: Entities::ComposedOf, documentation: { type: 'ComposedOf',
|
42
|
-
is_array: true,
|
43
|
-
required: true }
|
44
|
-
|
45
|
-
expose :part, using: Entities::ComposedOfElse, documentation: { type: 'composes' }
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
module Entities
|
50
|
-
class AliasedThing < Grape::Entity
|
51
|
-
expose :something, as: :post, using: Entities::Something, documentation: { type: 'Something', desc: 'Reference to something.' }
|
52
|
-
end
|
53
|
-
|
54
|
-
class AliasedThingWithoutType < Grape::Entity
|
55
|
-
expose :something, as: :post, using: Entities::Something, documentation: { desc: 'Reference to something without type.' }
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
module Entities
|
60
|
-
class FourthLevel < Grape::Entity
|
61
|
-
expose :text, documentation: { type: 'string' }
|
62
|
-
end
|
63
|
-
|
64
|
-
class ThirdLevel < Grape::Entity
|
65
|
-
expose :parts, using: Entities::FourthLevel, documentation: { type: 'FourthLevel' }
|
66
|
-
end
|
67
|
-
|
68
|
-
class SecondLevel < Grape::Entity
|
69
|
-
expose :parts, using: Entities::ThirdLevel, documentation: { type: 'ThirdLevel' }
|
70
|
-
end
|
71
|
-
|
72
|
-
class FirstLevel < Grape::Entity
|
73
|
-
expose :parts, using: Entities::SecondLevel, documentation: { type: 'SecondLevel' }
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
module Entities
|
79
|
-
class QueryInputElement < Grape::Entity
|
80
|
-
expose :key, documentation: {
|
81
|
-
type: String, desc: 'Name of parameter', required: true }
|
82
|
-
expose :value, documentation: {
|
83
|
-
type: String, desc: 'Value of parameter', required: true }
|
84
|
-
end
|
85
|
-
|
86
|
-
class QueryInput < Grape::Entity
|
87
|
-
expose :elements, using: Entities::QueryInputElement, documentation: {
|
88
|
-
type: 'QueryInputElement',
|
89
|
-
desc: 'Set of configuration',
|
90
|
-
param_type: 'body',
|
91
|
-
is_array: true,
|
92
|
-
required: true
|
93
|
-
}
|
94
|
-
end
|
95
|
-
|
96
|
-
class QueryResult < Grape::Entity
|
97
|
-
expose :elements_size, documentation: { type: Integer, desc: 'Return input elements size' }
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
module Entities
|
102
|
-
class ThingWithRoot < Grape::Entity
|
103
|
-
root 'things', 'thing'
|
104
|
-
expose :text, documentation: { type: 'string', desc: 'Content of something.' }
|
105
|
-
end
|
106
|
-
|
107
|
-
class ThingWithRootAndEntityName < Grape::Entity
|
108
|
-
root 'things', 'thing'
|
109
|
-
|
110
|
-
def self.entity_name
|
111
|
-
'TheThing'
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def app
|
117
|
-
Class.new(Grape::API) do
|
118
|
-
format :json
|
119
|
-
desc 'This gets something.', entity: Entities::Something
|
120
|
-
|
121
|
-
get '/something' do
|
122
|
-
something = OpenStruct.new text: 'something'
|
123
|
-
present something, with: Entities::Something
|
124
|
-
end
|
125
|
-
|
126
|
-
desc 'This gets thing.', entity: Entities::Some::Thing
|
127
|
-
get '/thing' do
|
128
|
-
thing = OpenStruct.new text: 'thing'
|
129
|
-
present thing, with: Entities::Some::Thing
|
130
|
-
end
|
131
|
-
|
132
|
-
desc 'This gets somthing else.', entity: Entities::SomeThingElse
|
133
|
-
get '/somethingelse' do
|
134
|
-
part = OpenStruct.new part_text: 'part thing'
|
135
|
-
thing = OpenStruct.new else_text: 'else thing', parts: [part], part: part
|
136
|
-
|
137
|
-
present thing, with: Entities::SomeThingElse
|
138
|
-
end
|
139
|
-
|
140
|
-
desc 'This tests the enum values in params and documentation.', entity: Entities::EnumValues, params: Entities::EnumValues.documentation
|
141
|
-
get '/enum_description_in_entity' do
|
142
|
-
enum_value = OpenStruct.new gender: 'Male', number: 1
|
143
|
-
|
144
|
-
present enum_value, with: Entities::EnumValues
|
145
|
-
end
|
146
|
-
|
147
|
-
desc 'This gets an aliased thing.', entity: Entities::AliasedThing
|
148
|
-
get '/aliasedthing' do
|
149
|
-
something = OpenStruct.new(something: OpenStruct.new(text: 'something'))
|
150
|
-
present something, with: Entities::AliasedThing
|
151
|
-
end
|
152
|
-
|
153
|
-
desc 'This also gets an aliased thing', entity: Entities::AliasedThingWithoutType
|
154
|
-
get '/aliased_thing_without_type' do
|
155
|
-
something = OpenStruct.new(something: OpenStruct.new(text: 'something'))
|
156
|
-
present something, with: Entities::AliasedThingWithoutType
|
157
|
-
end
|
158
|
-
|
159
|
-
desc 'This gets all nested entities.', entity: Entities::FirstLevel
|
160
|
-
get '/nesting' do
|
161
|
-
fourth_level = OpenStruct.new text: 'something'
|
162
|
-
third_level = OpenStruct.new parts: [fourth_level]
|
163
|
-
second_level = OpenStruct.new parts: [third_level]
|
164
|
-
first_level = OpenStruct.new parts: [second_level]
|
165
|
-
|
166
|
-
present first_level, with: Entities::FirstLevel
|
167
|
-
end
|
168
|
-
|
169
|
-
desc 'This tests diffrent entity for input and diffrent for output',
|
170
|
-
entity: [Entities::QueryResult, Entities::QueryInput],
|
171
|
-
params: Entities::QueryInput.documentation
|
172
|
-
get '/multiple_entities' do
|
173
|
-
result = OpenStruct.new(elements_size: params[:elements].size)
|
174
|
-
present result, with: Entities::QueryResult
|
175
|
-
end
|
176
|
-
|
177
|
-
desc 'This gets thing_with_root.', entity: Entities::ThingWithRoot
|
178
|
-
get '/thing_with_root' do
|
179
|
-
thing = OpenStruct.new text: 'thing'
|
180
|
-
present thing, with: Entities::ThingWithRoot
|
181
|
-
end
|
182
|
-
|
183
|
-
desc 'This gets thing with root and entity name', entity: Entities::ThingWithRootAndEntityName
|
184
|
-
get '/thing_with_root_and_entity_name' do
|
185
|
-
thing = Object.new
|
186
|
-
present thing, with: Entities::ThingWithRootAndEntityName
|
187
|
-
end
|
188
|
-
|
189
|
-
add_swagger_documentation
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
context 'swagger_doc' do
|
194
|
-
subject do
|
195
|
-
get '/swagger_doc'
|
196
|
-
JSON.parse(last_response.body)
|
197
|
-
end
|
198
|
-
|
199
|
-
it 'returns a swagger-compatible doc' do
|
200
|
-
expect(subject).to include(
|
201
|
-
'apiVersion' => '0.1',
|
202
|
-
'swaggerVersion' => '1.2',
|
203
|
-
'info' => {},
|
204
|
-
'produces' => ['application/json']
|
205
|
-
)
|
206
|
-
end
|
207
|
-
|
208
|
-
it 'documents apis' do
|
209
|
-
expect(subject['apis']).to eq [
|
210
|
-
{ 'path' => '/something.{format}', 'description' => 'Operations about somethings' },
|
211
|
-
{ 'path' => '/thing.{format}', 'description' => 'Operations about things' },
|
212
|
-
{ 'path' => '/somethingelse.{format}', 'description' => 'Operations about somethingelses' },
|
213
|
-
{ 'path' => '/enum_description_in_entity.{format}', 'description' => 'Operations about enum_description_in_entities' },
|
214
|
-
{ 'path' => '/aliasedthing.{format}', 'description' => 'Operations about aliasedthings' },
|
215
|
-
{ 'path' => '/aliased_thing_without_type.{format}', 'description' => 'Operations about aliased_thing_without_types' },
|
216
|
-
{ 'path' => '/nesting.{format}', 'description' => 'Operations about nestings' },
|
217
|
-
{ 'path' => '/multiple_entities.{format}', 'description' => 'Operations about multiple_entities' },
|
218
|
-
{ 'path' => '/thing_with_root.{format}', 'description' => 'Operations about thing_with_roots' },
|
219
|
-
{ 'path' => '/thing_with_root_and_entity_name.{format}', 'description' => 'Operations about thing_with_root_and_entity_names' },
|
220
|
-
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
|
221
|
-
]
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
it 'returns type' do
|
226
|
-
get '/swagger_doc/something'
|
227
|
-
result = JSON.parse(last_response.body)
|
228
|
-
expect(result['apis'].first['operations'].first['type']).to eq 'Something'
|
229
|
-
end
|
230
|
-
|
231
|
-
it 'includes nested type' do
|
232
|
-
get '/swagger_doc/thing'
|
233
|
-
result = JSON.parse(last_response.body)
|
234
|
-
expect(result['apis'].first['operations'].first['type']).to eq 'Some::Thing'
|
235
|
-
end
|
236
|
-
|
237
|
-
it 'includes entities which are only used as composition' do
|
238
|
-
get '/swagger_doc/somethingelse'
|
239
|
-
result = JSON.parse(last_response.body)
|
240
|
-
expect(result['apis'][0]['path']).to start_with '/somethingelse'
|
241
|
-
|
242
|
-
expect(result['models']['SomeThingElse']).to include('id' => 'SomeThingElse',
|
243
|
-
'properties' => {
|
244
|
-
'else_text' => {
|
245
|
-
'type' => 'string',
|
246
|
-
'description' => 'Content of something else.'
|
247
|
-
},
|
248
|
-
'parts' => {
|
249
|
-
'type' => 'array',
|
250
|
-
'items' => { '$ref' => 'ComposedOf' }
|
251
|
-
},
|
252
|
-
'part' => { '$ref' => 'composes' }
|
253
|
-
},
|
254
|
-
'required' => ['parts']
|
255
|
-
|
256
|
-
)
|
257
|
-
|
258
|
-
expect(result['models']['ComposedOf']).to include(
|
259
|
-
'id' => 'ComposedOf',
|
260
|
-
'properties' => {
|
261
|
-
'part_text' => {
|
262
|
-
'type' => 'string',
|
263
|
-
'description' => 'Content of composedof.'
|
264
|
-
}
|
265
|
-
}
|
266
|
-
)
|
267
|
-
|
268
|
-
expect(result['models']['composed']).to include(
|
269
|
-
'id' => 'composed',
|
270
|
-
'properties' => {
|
271
|
-
'part_text' => {
|
272
|
-
'type' => 'string',
|
273
|
-
'description' => 'Content of composedof else.'
|
274
|
-
}
|
275
|
-
|
276
|
-
}
|
277
|
-
)
|
278
|
-
end
|
279
|
-
|
280
|
-
it 'includes enum values in params and documentation.' do
|
281
|
-
get '/swagger_doc/enum_description_in_entity'
|
282
|
-
result = JSON.parse(last_response.body)
|
283
|
-
expect(result['models']['EnumValues']).to eq(
|
284
|
-
'id' => 'EnumValues',
|
285
|
-
'properties' => {
|
286
|
-
'gender' => { 'type' => 'string', 'description' => 'Content of something.', 'enum' => %w(Male Female) },
|
287
|
-
'number' => { 'type' => 'integer', 'format' => 'int32', 'description' => 'Content of something.', 'enum' => [1, 2] }
|
288
|
-
}
|
289
|
-
)
|
290
|
-
|
291
|
-
expect(result['apis'][0]['operations'][0]).to include(
|
292
|
-
'parameters' =>
|
293
|
-
[
|
294
|
-
{ 'paramType' => 'query', 'name' => 'gender', 'description' => 'Content of something.', 'type' => 'string', 'required' => false, 'allowMultiple' => false, 'enum' => %w(Male Female) },
|
295
|
-
{ 'paramType' => 'query', 'name' => 'number', 'description' => 'Content of something.', 'type' => 'integer', 'required' => false, 'allowMultiple' => false, 'format' => 'int32', 'enum' => [1, 2] }
|
296
|
-
],
|
297
|
-
'type' => 'EnumValues'
|
298
|
-
)
|
299
|
-
end
|
300
|
-
|
301
|
-
it 'includes referenced models in those with aliased references.' do
|
302
|
-
get '/swagger_doc/aliasedthing'
|
303
|
-
result = JSON.parse(last_response.body)
|
304
|
-
expect(result['models']['AliasedThing']).to eq(
|
305
|
-
'id' => 'AliasedThing',
|
306
|
-
'properties' => {
|
307
|
-
'post' => { '$ref' => 'Something', 'description' => 'Reference to something.' }
|
308
|
-
}
|
309
|
-
)
|
310
|
-
|
311
|
-
expect(result['models']['Something']).to eq(
|
312
|
-
'id' => 'Something',
|
313
|
-
'properties' => {
|
314
|
-
'text' => { 'type' => 'string', 'description' => 'Content of something.' },
|
315
|
-
'links' => { 'type' => 'array', 'items' => { '$ref' => 'link' } }
|
316
|
-
}
|
317
|
-
)
|
318
|
-
end
|
319
|
-
|
320
|
-
it 'includes referenced models in those with aliased references and omitted types.' do
|
321
|
-
get '/swagger_doc/aliased_thing_without_type'
|
322
|
-
result = JSON.parse(last_response.body)
|
323
|
-
expect(result['models']['AliasedThingWithoutType']).to eq(
|
324
|
-
'id' => 'AliasedThingWithoutType',
|
325
|
-
'properties' => {
|
326
|
-
'post' => { '$ref' => 'Something', 'description' => 'Reference to something without type.' }
|
327
|
-
}
|
328
|
-
)
|
329
|
-
|
330
|
-
expect(result['models']['Something']).to eq(
|
331
|
-
'id' => 'Something',
|
332
|
-
'properties' => {
|
333
|
-
'text' => { 'type' => 'string', 'description' => 'Content of something.' },
|
334
|
-
'links' => { 'type' => 'array', 'items' => { '$ref' => 'link' } }
|
335
|
-
}
|
336
|
-
)
|
337
|
-
end
|
338
|
-
|
339
|
-
it 'includes all entities with four levels of nesting' do
|
340
|
-
get '/swagger_doc/nesting'
|
341
|
-
result = JSON.parse(last_response.body)
|
342
|
-
|
343
|
-
expect(result['models']).to include('FirstLevel', 'SecondLevel', 'ThirdLevel', 'FourthLevel')
|
344
|
-
end
|
345
|
-
|
346
|
-
it 'includes all entities while using multiple entities' do
|
347
|
-
get '/swagger_doc/multiple_entities'
|
348
|
-
result = JSON.parse(last_response.body)
|
349
|
-
|
350
|
-
expect(result['models']).to include('QueryInput', 'QueryInputElement', 'QueryResult')
|
351
|
-
end
|
352
|
-
|
353
|
-
it 'includes an id equal to the model name (defined with root)' do
|
354
|
-
get '/swagger_doc/thing_with_root'
|
355
|
-
result = JSON.parse(last_response.body)
|
356
|
-
expect(result['models']['thing']['id']).to eq('thing')
|
357
|
-
end
|
358
|
-
|
359
|
-
it 'prefers entity_name for id over root' do
|
360
|
-
get 'swagger_doc/thing_with_root_and_entity_name'
|
361
|
-
result = JSON.parse(last_response.body)
|
362
|
-
expect(result['models']['TheThing']['id']).to eq('TheThing')
|
363
|
-
end
|
364
|
-
end
|