2016-05-07 09:12:26 +08:00
|
|
|
RSpec.shared_context 'mock swagger example' do
|
2015-10-03 21:31:30 +08:00
|
|
|
before :all do
|
|
|
|
module Entities
|
2016-05-07 09:12:26 +08:00
|
|
|
class Something < OpenStruct
|
|
|
|
class << self
|
|
|
|
# Representable doesn't have documentation method, mock this
|
|
|
|
def documentation
|
|
|
|
{
|
|
|
|
id: { type: Integer, desc: 'Identity of Something' },
|
|
|
|
text: { type: String, desc: 'Content of something.' },
|
|
|
|
links: { type: 'link', is_array: true },
|
|
|
|
others: { type: 'text', is_array: false }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2015-10-03 21:31:30 +08:00
|
|
|
end
|
|
|
|
|
2016-05-07 09:12:26 +08:00
|
|
|
class UseResponse < OpenStruct
|
|
|
|
class << self
|
|
|
|
def documentation
|
|
|
|
{
|
|
|
|
:description => { type: String },
|
|
|
|
'$responses' => { is_array: true }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2015-10-03 21:31:30 +08:00
|
|
|
end
|
|
|
|
|
2016-05-07 09:12:26 +08:00
|
|
|
class ResponseItem < OpenStruct
|
|
|
|
class << self
|
|
|
|
def documentation
|
|
|
|
{
|
|
|
|
id: { type: Integer },
|
|
|
|
name: { type: String }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2015-10-03 21:31:30 +08:00
|
|
|
end
|
|
|
|
|
2016-05-07 09:12:26 +08:00
|
|
|
class UseNestedWithAddress < OpenStruct; end
|
|
|
|
class TypedDefinition < OpenStruct; end
|
|
|
|
class UseItemResponseAsType < OpenStruct; end
|
|
|
|
class OtherItem < OpenStruct; end
|
|
|
|
class EnumValues < OpenStruct; end
|
|
|
|
class AliasedThing < OpenStruct; end
|
|
|
|
class FourthLevel < OpenStruct; end
|
|
|
|
class ThirdLevel < OpenStruct; end
|
|
|
|
class SecondLevel < OpenStruct; end
|
|
|
|
class FirstLevel < OpenStruct; end
|
|
|
|
class QueryInputElement < OpenStruct; end
|
|
|
|
class QueryInput < OpenStruct; end
|
|
|
|
class ApiError < OpenStruct; end
|
|
|
|
class SecondApiError < OpenStruct; end
|
2016-05-11 03:42:06 +08:00
|
|
|
class RecursiveModel < OpenStruct; end
|
2016-06-14 20:12:46 +08:00
|
|
|
class DocumentedHashAndArrayModel < OpenStruct; end
|
2016-10-14 05:06:03 +08:00
|
|
|
module NestedModule
|
|
|
|
class ApiResponse < OpenStruct; end
|
|
|
|
end
|
2016-05-07 09:12:26 +08:00
|
|
|
end
|
|
|
|
end
|
2015-10-03 21:31:30 +08:00
|
|
|
|
2016-05-07 09:12:26 +08:00
|
|
|
let(:swagger_definitions_models) do
|
|
|
|
{
|
2016-05-12 04:54:01 +08:00
|
|
|
'ApiError' => {
|
|
|
|
'type' => 'object',
|
|
|
|
'properties' => {
|
|
|
|
'mock_data' => {
|
|
|
|
'type' => 'string',
|
|
|
|
'description' => "it's a mock"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'RecursiveModel' => {
|
|
|
|
'type' => 'object',
|
|
|
|
'properties' => {
|
|
|
|
'mock_data' => {
|
|
|
|
'type' => 'string',
|
|
|
|
'description' => "it's a mock"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'UseResponse' => {
|
|
|
|
'type' => 'object',
|
|
|
|
'properties' => {
|
|
|
|
'mock_data' => {
|
|
|
|
'type' => 'string',
|
|
|
|
'description' => "it's a mock"
|
|
|
|
}
|
|
|
|
}
|
2016-06-14 20:12:46 +08:00
|
|
|
},
|
|
|
|
'DocumentedHashAndArrayModel' => {
|
|
|
|
'type' => 'object',
|
|
|
|
'properties' => {
|
|
|
|
'mock_data' => {
|
|
|
|
'type' => 'string',
|
|
|
|
'description' => "it's a mock"
|
|
|
|
}
|
|
|
|
}
|
2016-05-12 04:54:01 +08:00
|
|
|
}
|
2016-05-07 09:12:26 +08:00
|
|
|
}
|
|
|
|
end
|
2015-10-03 21:31:30 +08:00
|
|
|
|
2016-05-07 09:12:26 +08:00
|
|
|
let(:swagger_nested_type) do
|
|
|
|
{
|
2016-05-12 04:54:01 +08:00
|
|
|
'ApiError' => {
|
2016-05-07 09:12:26 +08:00
|
|
|
'type' => 'object',
|
2016-05-12 04:54:01 +08:00
|
|
|
'properties' => {
|
|
|
|
'mock_data' => {
|
|
|
|
'type' => 'string',
|
|
|
|
'description' => "it's a mock"
|
|
|
|
}
|
|
|
|
},
|
2016-05-07 09:12:26 +08:00
|
|
|
'description' => 'This returns something'
|
|
|
|
},
|
2016-05-12 04:54:01 +08:00
|
|
|
'UseItemResponseAsType' => {
|
2016-05-07 09:12:26 +08:00
|
|
|
'type' => 'object',
|
2016-05-12 04:54:01 +08:00
|
|
|
'properties' => {
|
|
|
|
'mock_data' => {
|
|
|
|
'type' => 'string',
|
|
|
|
'description' => "it's a mock"
|
|
|
|
}
|
|
|
|
},
|
2016-05-07 09:12:26 +08:00
|
|
|
'description' => 'This returns something'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2015-10-03 21:31:30 +08:00
|
|
|
|
2016-05-07 09:12:26 +08:00
|
|
|
let(:swagger_entity_as_response_object) do
|
|
|
|
{
|
|
|
|
'UseResponse' => {
|
|
|
|
'type' => 'object',
|
2016-05-12 04:54:01 +08:00
|
|
|
'properties' => {
|
|
|
|
'mock_data' => {
|
|
|
|
'type' => 'string',
|
|
|
|
'description' => "it's a mock"
|
|
|
|
}
|
|
|
|
},
|
2016-05-07 09:12:26 +08:00
|
|
|
'description' => 'This returns something'
|
|
|
|
},
|
|
|
|
'ApiError' => {
|
|
|
|
'type' => 'object',
|
2016-05-12 04:54:01 +08:00
|
|
|
'properties' => {
|
|
|
|
'mock_data' => {
|
|
|
|
'type' => 'string',
|
|
|
|
'description' => "it's a mock"
|
|
|
|
}
|
|
|
|
},
|
2016-05-07 09:12:26 +08:00
|
|
|
'description' => 'This returns something'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2015-10-03 21:31:30 +08:00
|
|
|
|
2016-05-07 09:12:26 +08:00
|
|
|
let(:swagger_params_as_response_object) do
|
|
|
|
{
|
|
|
|
'ApiError' => {
|
|
|
|
'type' => 'object',
|
2016-05-12 04:54:01 +08:00
|
|
|
'properties' => {
|
|
|
|
'mock_data' => {
|
|
|
|
'type' => 'string',
|
|
|
|
'description' => "it's a mock"
|
|
|
|
}
|
|
|
|
},
|
2016-05-07 09:12:26 +08:00
|
|
|
'description' => 'This returns something'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2015-10-03 21:31:30 +08:00
|
|
|
|
2016-05-07 09:12:26 +08:00
|
|
|
let(:swagger_typed_defintion) do
|
2016-05-12 04:54:01 +08:00
|
|
|
{
|
|
|
|
'mock_data' => {
|
|
|
|
'type' => 'string',
|
|
|
|
'description' => "it's a mock"
|
|
|
|
}
|
|
|
|
}
|
2015-10-03 21:31:30 +08:00
|
|
|
end
|
|
|
|
|
2015-10-01 04:59:11 +08:00
|
|
|
let(:swagger_json) do
|
2015-12-19 01:40:53 +08:00
|
|
|
{
|
2016-05-07 03:00:36 +08:00
|
|
|
'info' => {
|
|
|
|
'title' => 'The API title to be displayed on the API homepage.',
|
|
|
|
'description' => 'A description of the API.',
|
|
|
|
'termsOfServiceUrl' => 'www.The-URL-of-the-terms-and-service.com',
|
|
|
|
'contact' => { 'name' => 'Contact name', 'email' => 'Contact@email.com', 'url' => 'Contact URL' },
|
|
|
|
'license' => { 'name' => 'The name of the license.', 'url' => 'www.The-URL-of-the-license.org' },
|
|
|
|
'version' => '0.0.1'
|
2016-04-08 09:05:35 +08:00
|
|
|
},
|
2016-05-07 03:00:36 +08:00
|
|
|
'swagger' => '2.0',
|
|
|
|
'produces' => ['application/json'],
|
|
|
|
'host' => 'example.org',
|
|
|
|
'basePath' => '/api',
|
|
|
|
'tags' => [
|
|
|
|
{ 'name' => 'other_thing', 'description' => 'Operations about other_things' },
|
|
|
|
{ 'name' => 'thing', 'description' => 'Operations about things' },
|
|
|
|
{ 'name' => 'thing2', 'description' => 'Operations about thing2s' },
|
|
|
|
{ 'name' => 'dummy', 'description' => 'Operations about dummies' }
|
2016-04-08 09:05:35 +08:00
|
|
|
],
|
2016-05-07 03:00:36 +08:00
|
|
|
'paths' => {
|
|
|
|
'/v3/other_thing/{elements}' => {
|
|
|
|
'get' => {
|
2016-05-23 15:23:16 +08:00
|
|
|
'summary' => 'nested route inside namespace',
|
2016-05-07 03:00:36 +08:00
|
|
|
'description' => 'nested route inside namespace',
|
|
|
|
'produces' => ['application/json'],
|
|
|
|
'parameters' => [{ 'in' => 'body', 'name' => 'elements', 'description' => 'Set of configuration', 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => true }],
|
|
|
|
'responses' => { '200' => { 'description' => 'nested route inside namespace', 'schema' => { '$ref' => '#/definitions/QueryInput' } } },
|
|
|
|
'tags' => ['other_thing'],
|
|
|
|
'operationId' => 'getV3OtherThingElements',
|
|
|
|
'x-amazon-apigateway-auth' => { 'type' => 'none' },
|
|
|
|
'x-amazon-apigateway-integration' => { 'type' => 'aws', 'uri' => 'foo_bar_uri', 'httpMethod' => 'get' }
|
2016-05-11 04:01:13 +08:00
|
|
|
}
|
|
|
|
},
|
2016-05-07 03:00:36 +08:00
|
|
|
'/thing' => {
|
|
|
|
'get' => {
|
2016-05-23 15:23:16 +08:00
|
|
|
'summary' => 'This gets Things.',
|
2016-05-07 03:00:36 +08:00
|
|
|
'description' => 'This gets Things.',
|
|
|
|
'produces' => ['application/json'],
|
|
|
|
'parameters' => [
|
|
|
|
{ 'in' => 'query', 'name' => 'id', 'description' => 'Identity of Something', 'type' => 'integer', 'format' => 'int32', 'required' => false },
|
|
|
|
{ 'in' => 'query', 'name' => 'text', 'description' => 'Content of something.', 'type' => 'string', 'required' => false },
|
|
|
|
{ 'in' => 'formData', 'name' => 'links', 'type' => 'array', 'items' => { 'type' => 'link' }, 'required' => false },
|
|
|
|
{ 'in' => 'query', 'name' => 'others', 'type' => 'text', 'required' => false }
|
2016-04-08 09:05:35 +08:00
|
|
|
],
|
2016-05-07 03:00:36 +08:00
|
|
|
'responses' => { '200' => { 'description' => 'This gets Things.' }, '401' => { 'description' => 'Unauthorized', 'schema' => { '$ref' => '#/definitions/ApiError' } } },
|
|
|
|
'tags' => ['thing'],
|
|
|
|
'operationId' => 'getThing'
|
2016-03-30 06:43:33 +08:00
|
|
|
},
|
2016-05-07 03:00:36 +08:00
|
|
|
'post' => {
|
2016-05-23 15:23:16 +08:00
|
|
|
'summary' => 'This creates Thing.',
|
2016-05-07 03:00:36 +08:00
|
|
|
'description' => 'This creates Thing.',
|
|
|
|
'produces' => ['application/json'],
|
|
|
|
'consumes' => ['application/json'],
|
|
|
|
'parameters' => [
|
|
|
|
{ 'in' => 'formData', 'name' => 'text', 'description' => 'Content of something.', 'type' => 'string', 'required' => true },
|
|
|
|
{ 'in' => 'formData', 'name' => 'links', 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => true }
|
2016-04-08 09:05:35 +08:00
|
|
|
],
|
2016-05-07 03:00:36 +08:00
|
|
|
'responses' => { '201' => { 'description' => 'This creates Thing.', 'schema' => { '$ref' => '#/definitions/Something' } }, '422' => { 'description' => 'Unprocessible Entity' } },
|
|
|
|
'tags' => ['thing'],
|
|
|
|
'operationId' => 'postThing'
|
2016-05-11 04:01:13 +08:00
|
|
|
}
|
|
|
|
},
|
2016-05-07 03:00:36 +08:00
|
|
|
'/thing/{id}' => {
|
|
|
|
'get' => {
|
2016-05-23 15:23:16 +08:00
|
|
|
'summary' => 'This gets Thing.',
|
2016-05-07 03:00:36 +08:00
|
|
|
'description' => 'This gets Thing.',
|
|
|
|
'produces' => ['application/json'],
|
|
|
|
'parameters' => [{ 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true }],
|
|
|
|
'responses' => { '200' => { 'description' => 'getting a single thing' }, '401' => { 'description' => 'Unauthorized' } },
|
|
|
|
'tags' => ['thing'],
|
|
|
|
'operationId' => 'getThingId'
|
2016-04-08 09:05:35 +08:00
|
|
|
},
|
2016-05-07 03:00:36 +08:00
|
|
|
'put' => {
|
2016-05-23 15:23:16 +08:00
|
|
|
'summary' => 'This updates Thing.',
|
2016-05-07 03:00:36 +08:00
|
|
|
'description' => 'This updates Thing.',
|
|
|
|
'produces' => ['application/json'],
|
|
|
|
'consumes' => ['application/json'],
|
|
|
|
'parameters' => [
|
|
|
|
{ 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true },
|
|
|
|
{ 'in' => 'formData', 'name' => 'text', 'description' => 'Content of something.', 'type' => 'string', 'required' => false },
|
|
|
|
{ 'in' => 'formData', 'name' => 'links', 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => false }
|
2016-04-08 09:05:35 +08:00
|
|
|
],
|
2016-05-07 03:00:36 +08:00
|
|
|
'responses' => { '200' => { 'description' => 'This updates Thing.', 'schema' => { '$ref' => '#/definitions/Something' } } },
|
|
|
|
'tags' => ['thing'],
|
|
|
|
'operationId' => 'putThingId'
|
2016-04-08 09:05:35 +08:00
|
|
|
},
|
2016-05-07 03:00:36 +08:00
|
|
|
'delete' => {
|
2016-05-23 15:23:16 +08:00
|
|
|
'summary' => 'This deletes Thing.',
|
2016-05-07 03:00:36 +08:00
|
|
|
'description' => 'This deletes Thing.',
|
|
|
|
'produces' => ['application/json'],
|
|
|
|
'parameters' => [{ 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true }],
|
|
|
|
'responses' => { '200' => { 'description' => 'This deletes Thing.', 'schema' => { '$ref' => '#/definitions/Something' } } },
|
|
|
|
'tags' => ['thing'],
|
|
|
|
'operationId' => 'deleteThingId'
|
2016-05-11 04:01:13 +08:00
|
|
|
}
|
|
|
|
},
|
2016-05-07 03:00:36 +08:00
|
|
|
'/thing2' => {
|
|
|
|
'get' => {
|
2016-05-23 15:23:16 +08:00
|
|
|
'summary' => 'This gets Things.',
|
2016-05-07 03:00:36 +08:00
|
|
|
'description' => 'This gets Things.',
|
|
|
|
'produces' => ['application/json'],
|
|
|
|
'responses' => { '200' => { 'description' => 'get Horses', 'schema' => { '$ref' => '#/definitions/Something' } }, '401' => { 'description' => 'HorsesOutError', 'schema' => { '$ref' => '#/definitions/ApiError' } } },
|
|
|
|
'tags' => ['thing2'],
|
|
|
|
'operationId' => 'getThing2'
|
2016-05-11 04:01:13 +08:00
|
|
|
}
|
|
|
|
},
|
2016-05-07 03:00:36 +08:00
|
|
|
'/dummy/{id}' => {
|
|
|
|
'delete' => {
|
2016-05-23 15:23:16 +08:00
|
|
|
'summary' => 'dummy route.',
|
2016-05-07 03:00:36 +08:00
|
|
|
'description' => 'dummy route.',
|
|
|
|
'produces' => ['application/json'],
|
|
|
|
'parameters' => [{ 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true }],
|
|
|
|
'responses' => { '204' => { 'description' => 'dummy route.' }, '401' => { 'description' => 'Unauthorized' } },
|
|
|
|
'tags' => ['dummy'],
|
|
|
|
'operationId' => 'deleteDummyId'
|
2016-05-11 04:01:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-05-07 03:00:36 +08:00
|
|
|
'definitions' => {
|
|
|
|
'QueryInput' => {
|
|
|
|
'type' => 'object',
|
2016-05-12 04:54:01 +08:00
|
|
|
'properties' => {
|
|
|
|
'mock_data' => {
|
|
|
|
'type' => 'string',
|
|
|
|
'description' => "it's a mock"
|
|
|
|
}
|
|
|
|
},
|
2016-05-07 03:00:36 +08:00
|
|
|
'description' => 'nested route inside namespace'
|
2016-05-01 18:31:44 +08:00
|
|
|
},
|
2016-05-07 03:00:36 +08:00
|
|
|
'ApiError' => {
|
|
|
|
'type' => 'object',
|
2016-05-12 04:54:01 +08:00
|
|
|
'properties' => {
|
|
|
|
'mock_data' => {
|
|
|
|
'type' => 'string',
|
|
|
|
'description' => "it's a mock"
|
|
|
|
}
|
|
|
|
},
|
2016-05-07 03:00:36 +08:00
|
|
|
'description' => 'This gets Things.'
|
2016-05-01 18:31:44 +08:00
|
|
|
},
|
2016-05-07 03:00:36 +08:00
|
|
|
'Something' => {
|
|
|
|
'type' => 'object',
|
2016-05-12 04:54:01 +08:00
|
|
|
'properties' => {
|
|
|
|
'mock_data' => {
|
|
|
|
'type' => 'string',
|
|
|
|
'description' => "it's a mock"
|
|
|
|
}
|
|
|
|
},
|
2016-05-07 03:00:36 +08:00
|
|
|
'description' => 'This gets Things.'
|
2016-05-11 04:01:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-01 04:59:11 +08:00
|
|
|
end
|
|
|
|
|
2016-05-07 03:00:36 +08:00
|
|
|
let(:http_verbs) { %w(get post put delete) }
|
2015-10-01 04:59:11 +08:00
|
|
|
end
|
2015-10-03 21:31:30 +08:00
|
|
|
|
|
|
|
def mounted_paths
|
2016-05-07 03:00:36 +08:00
|
|
|
%w( /thing /other_thing /dummy )
|
2015-10-03 21:31:30 +08:00
|
|
|
end
|