apipierails3 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +17 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +27 -0
- data/APACHE-LICENSE-2.0 +202 -0
- data/CHANGELOG.md +469 -0
- data/Gemfile +1 -0
- data/Gemfile.rails32 +6 -0
- data/Gemfile.rails41 +6 -0
- data/Gemfile.rails42 +11 -0
- data/Gemfile.rails50 +6 -0
- data/Gemfile.rails51 +7 -0
- data/MIT-LICENSE +20 -0
- data/NOTICE +4 -0
- data/PROPOSAL_FOR_RESPONSE_DESCRIPTIONS.md +244 -0
- data/README.rst +1874 -0
- data/Rakefile +13 -0
- data/apipierails3.gemspec +27 -0
- data/app/controllers/apipie/apipies_controller.rb +199 -0
- data/app/helpers/apipie_helper.rb +10 -0
- data/app/public/apipie/javascripts/apipie.js +6 -0
- data/app/public/apipie/javascripts/bundled/bootstrap-collapse.js +138 -0
- data/app/public/apipie/javascripts/bundled/bootstrap.js +1726 -0
- data/app/public/apipie/javascripts/bundled/jquery.js +5 -0
- data/app/public/apipie/javascripts/bundled/prettify.js +28 -0
- data/app/public/apipie/stylesheets/application.css +7 -0
- data/app/public/apipie/stylesheets/bundled/bootstrap-responsive.min.css +12 -0
- data/app/public/apipie/stylesheets/bundled/bootstrap.min.css +689 -0
- data/app/public/apipie/stylesheets/bundled/prettify.css +30 -0
- data/app/views/apipie/apipies/_disqus.html.erb +13 -0
- data/app/views/apipie/apipies/_errors.html.erb +23 -0
- data/app/views/apipie/apipies/_headers.html.erb +26 -0
- data/app/views/apipie/apipies/_languages.erb +6 -0
- data/app/views/apipie/apipies/_metadata.erb +1 -0
- data/app/views/apipie/apipies/_method_detail.erb +61 -0
- data/app/views/apipie/apipies/_params.html.erb +42 -0
- data/app/views/apipie/apipies/_params_plain.html.erb +20 -0
- data/app/views/apipie/apipies/apipie_404.html.erb +17 -0
- data/app/views/apipie/apipies/apipie_checksum.json.erb +1 -0
- data/app/views/apipie/apipies/getting_started.html.erb +6 -0
- data/app/views/apipie/apipies/index.html.erb +56 -0
- data/app/views/apipie/apipies/method.html.erb +41 -0
- data/app/views/apipie/apipies/plain.html.erb +77 -0
- data/app/views/apipie/apipies/resource.html.erb +80 -0
- data/app/views/apipie/apipies/static.html.erb +103 -0
- data/app/views/layouts/apipie/apipie.html.erb +27 -0
- data/config/locales/de.yml +28 -0
- data/config/locales/en.yml +32 -0
- data/config/locales/es.yml +28 -0
- data/config/locales/fr.yml +31 -0
- data/config/locales/it.yml +31 -0
- data/config/locales/ja.yml +31 -0
- data/config/locales/pl.yml +28 -0
- data/config/locales/pt-BR.yml +28 -0
- data/config/locales/ru.yml +28 -0
- data/config/locales/tr.yml +28 -0
- data/config/locales/zh-CN.yml +28 -0
- data/config/locales/zh-TW.yml +28 -0
- data/images/screenshot-1.png +0 -0
- data/images/screenshot-2.png +0 -0
- data/lib/apipie/apipie_module.rb +83 -0
- data/lib/apipie/application.rb +462 -0
- data/lib/apipie/configuration.rb +186 -0
- data/lib/apipie/dsl_definition.rb +607 -0
- data/lib/apipie/error_description.rb +44 -0
- data/lib/apipie/errors.rb +86 -0
- data/lib/apipie/extractor.rb +177 -0
- data/lib/apipie/extractor/collector.rb +117 -0
- data/lib/apipie/extractor/recorder.rb +166 -0
- data/lib/apipie/extractor/writer.rb +454 -0
- data/lib/apipie/helpers.rb +73 -0
- data/lib/apipie/markup.rb +48 -0
- data/lib/apipie/method_description.rb +273 -0
- data/lib/apipie/middleware/checksum_in_headers.rb +35 -0
- data/lib/apipie/param_description.rb +280 -0
- data/lib/apipie/railtie.rb +9 -0
- data/lib/apipie/resource_description.rb +124 -0
- data/lib/apipie/response_description.rb +131 -0
- data/lib/apipie/response_description_adapter.rb +200 -0
- data/lib/apipie/routes_formatter.rb +33 -0
- data/lib/apipie/routing.rb +16 -0
- data/lib/apipie/rspec/response_validation_helper.rb +192 -0
- data/lib/apipie/see_description.rb +39 -0
- data/lib/apipie/static_dispatcher.rb +69 -0
- data/lib/apipie/swagger_generator.rb +707 -0
- data/lib/apipie/tag_list_description.rb +11 -0
- data/lib/apipie/validator.rb +526 -0
- data/lib/apipie/version.rb +3 -0
- data/lib/apipierails3.rb +25 -0
- data/lib/generators/apipie/install/README +6 -0
- data/lib/generators/apipie/install/install_generator.rb +25 -0
- data/lib/generators/apipie/install/templates/initializer.rb.erb +7 -0
- data/lib/generators/apipie/views_generator.rb +11 -0
- data/lib/tasks/apipie.rake +345 -0
- data/rel-eng/packages/.readme +3 -0
- data/rel-eng/packages/rubygem-apipie-rails +1 -0
- data/rel-eng/tito.props +5 -0
- data/spec/controllers/api/v1/architectures_controller_spec.rb +29 -0
- data/spec/controllers/api/v2/architectures_controller_spec.rb +12 -0
- data/spec/controllers/api/v2/nested/resources_controller_spec.rb +11 -0
- data/spec/controllers/apipies_controller_spec.rb +273 -0
- data/spec/controllers/concerns_controller_spec.rb +42 -0
- data/spec/controllers/extended_controller_spec.rb +11 -0
- data/spec/controllers/users_controller_spec.rb +740 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/api/base_controller.rb +4 -0
- data/spec/dummy/app/controllers/api/v1/architectures_controller.rb +43 -0
- data/spec/dummy/app/controllers/api/v1/base_controller.rb +11 -0
- data/spec/dummy/app/controllers/api/v2/architectures_controller.rb +30 -0
- data/spec/dummy/app/controllers/api/v2/base_controller.rb +11 -0
- data/spec/dummy/app/controllers/api/v2/nested/architectures_controller.rb +32 -0
- data/spec/dummy/app/controllers/api/v2/nested/resources_controller.rb +33 -0
- data/spec/dummy/app/controllers/application_controller.rb +18 -0
- data/spec/dummy/app/controllers/concerns/extending_concern.rb +11 -0
- data/spec/dummy/app/controllers/concerns/sample_controller.rb +41 -0
- data/spec/dummy/app/controllers/concerns_controller.rb +8 -0
- data/spec/dummy/app/controllers/extended_controller.rb +14 -0
- data/spec/dummy/app/controllers/files_controller.rb +5 -0
- data/spec/dummy/app/controllers/overridden_concerns_controller.rb +31 -0
- data/spec/dummy/app/controllers/pets_controller.rb +408 -0
- data/spec/dummy/app/controllers/pets_using_auto_views_controller.rb +73 -0
- data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +95 -0
- data/spec/dummy/app/controllers/tagged_cats_controller.rb +32 -0
- data/spec/dummy/app/controllers/tagged_dogs_controller.rb +15 -0
- data/spec/dummy/app/controllers/twitter_example_controller.rb +307 -0
- data/spec/dummy/app/controllers/users_controller.rb +297 -0
- data/spec/dummy/app/views/layouts/application.html.erb +21 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +49 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +21 -0
- data/spec/dummy/config/environment.rb +8 -0
- data/spec/dummy/config/environments/development.rb +28 -0
- data/spec/dummy/config/environments/production.rb +52 -0
- data/spec/dummy/config/environments/test.rb +38 -0
- data/spec/dummy/config/initializers/apipie.rb +110 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +8 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +51 -0
- data/spec/dummy/db/.gitkeep +0 -0
- data/spec/dummy/doc/apipie_examples.json +1 -0
- data/spec/dummy/doc/users/desc_from_file.md +1 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/lib/application_spec.rb +49 -0
- data/spec/lib/extractor/extractor_spec.rb +9 -0
- data/spec/lib/extractor/middleware_spec.rb +44 -0
- data/spec/lib/extractor/writer_spec.rb +110 -0
- data/spec/lib/file_handler_spec.rb +18 -0
- data/spec/lib/method_description_spec.rb +98 -0
- data/spec/lib/param_description_spec.rb +345 -0
- data/spec/lib/param_group_spec.rb +60 -0
- data/spec/lib/rake_spec.rb +71 -0
- data/spec/lib/resource_description_spec.rb +48 -0
- data/spec/lib/swagger/openapi_2_0_schema.json +1607 -0
- data/spec/lib/swagger/rake_swagger_spec.rb +139 -0
- data/spec/lib/swagger/response_validation_spec.rb +104 -0
- data/spec/lib/swagger/swagger_dsl_spec.rb +658 -0
- data/spec/lib/validator_spec.rb +113 -0
- data/spec/lib/validators/array_validator_spec.rb +85 -0
- data/spec/spec_helper.rb +109 -0
- data/spec/support/rake.rb +21 -0
- metadata +415 -0
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
require 'rake'
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Api
|
2
|
+
module V1
|
3
|
+
class ArchitecturesController < V1::BaseController
|
4
|
+
resource_description { name 'Architectures' }
|
5
|
+
api :GET, "/architectures/", "List all architectures."
|
6
|
+
def index
|
7
|
+
end
|
8
|
+
|
9
|
+
api :GET, "/architectures/:id/", "Show an architecture."
|
10
|
+
def show
|
11
|
+
end
|
12
|
+
|
13
|
+
def_param_group :timestamps do
|
14
|
+
param :created_at, String
|
15
|
+
param :updated_at, String
|
16
|
+
end
|
17
|
+
|
18
|
+
def_param_group :arch do
|
19
|
+
param :architecture, Hash, :required => true do
|
20
|
+
param :name, String, :required => true
|
21
|
+
param :description, String, :required => true
|
22
|
+
param_group :timestamps
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
api :POST, "/architectures/", "Create an architecture."
|
27
|
+
param_group :arch
|
28
|
+
def create
|
29
|
+
end
|
30
|
+
|
31
|
+
api :PUT, "/architectures/:id/", "Update an architecture."
|
32
|
+
param :architecture, Hash, :required => true do
|
33
|
+
param :name, String
|
34
|
+
end
|
35
|
+
def update
|
36
|
+
end
|
37
|
+
|
38
|
+
api :DELETE, "/architecturess/:id/", "Delete an architecture."
|
39
|
+
def destroy
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Api
|
2
|
+
module V2
|
3
|
+
class ArchitecturesController < V2::BaseController
|
4
|
+
resource_description { name 'Architectures' }
|
5
|
+
api :GET, "/architectures/", "List all architectures."
|
6
|
+
def index
|
7
|
+
end
|
8
|
+
|
9
|
+
api :GET, "/architectures/:id/", "Show an architecture."
|
10
|
+
def show
|
11
|
+
end
|
12
|
+
|
13
|
+
api :POST, "/architectures/", "Create an architecture."
|
14
|
+
param_group :arch, Api::V1::ArchitecturesController
|
15
|
+
def create
|
16
|
+
end
|
17
|
+
|
18
|
+
api :PUT, "/architectures/:id/", "Update an architecture."
|
19
|
+
param :architecture, Hash, :required => true do
|
20
|
+
param :name, String
|
21
|
+
end
|
22
|
+
def update
|
23
|
+
end
|
24
|
+
|
25
|
+
api :DELETE, "/architecturess/:id/", "Delete an architecture."
|
26
|
+
def destroy
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Api
|
2
|
+
module V2
|
3
|
+
module Nested
|
4
|
+
class ArchitecturesController < V2::BaseController
|
5
|
+
resource_description { name 'Architectures' }
|
6
|
+
api :GET, "/nested/architectures/", "List all nested architectures."
|
7
|
+
def index
|
8
|
+
end
|
9
|
+
|
10
|
+
api :GET, "/nested/architectures/:id/", "Show a nested architecture."
|
11
|
+
def show
|
12
|
+
end
|
13
|
+
|
14
|
+
api :POST, "/nested/architectures/", "Create a nested architecture."
|
15
|
+
param_group :arch, Api::V1::ArchitecturesController
|
16
|
+
def create
|
17
|
+
end
|
18
|
+
|
19
|
+
api :PUT, "/nested/architectures/:id/", "Update a nested architecture."
|
20
|
+
param :architecture, Hash, :required => true do
|
21
|
+
param :name, String
|
22
|
+
end
|
23
|
+
def update
|
24
|
+
end
|
25
|
+
|
26
|
+
api :DELETE, "/architecturess/:id/", "Delete a nested architecture."
|
27
|
+
def destroy
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Api
|
2
|
+
module V2
|
3
|
+
class Nested::ResourcesController < V2::BaseController
|
4
|
+
resource_description do
|
5
|
+
name 'Resources'
|
6
|
+
resource_id "resource"
|
7
|
+
end
|
8
|
+
api :GET, "/nested/resources/", "List all nested resources."
|
9
|
+
def index
|
10
|
+
end
|
11
|
+
|
12
|
+
api :GET, "/nested/resources/:id/", "Show a nested resource."
|
13
|
+
def show
|
14
|
+
end
|
15
|
+
|
16
|
+
api :POST, "/nested/resources/", "Create a nested resource."
|
17
|
+
param_group :arch, Api::V1::ArchitecturesController
|
18
|
+
def create
|
19
|
+
end
|
20
|
+
|
21
|
+
api :PUT, "/nested/resources/:id/", "Update a nested resource."
|
22
|
+
param :architecture, Hash, :required => true do
|
23
|
+
param :name, String
|
24
|
+
end
|
25
|
+
def update
|
26
|
+
end
|
27
|
+
|
28
|
+
api :DELETE, "/resources/:id/", "Delete a nested resource."
|
29
|
+
def destroy
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
before_filter :run_validations
|
3
|
+
|
4
|
+
resource_description do
|
5
|
+
param :oauth, String, :desc => "Authorization", :required => false
|
6
|
+
|
7
|
+
returns :code => 401 do
|
8
|
+
property :reason, String, "Why authorization was denied"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def run_validations
|
13
|
+
if Apipie.configuration.validate == :explicitly
|
14
|
+
apipie_validations
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Concerns
|
2
|
+
module SampleController
|
3
|
+
extend Apipie::DSL::Concern
|
4
|
+
|
5
|
+
api!
|
6
|
+
def index
|
7
|
+
render :plain => "OK #{params.inspect}"
|
8
|
+
end
|
9
|
+
|
10
|
+
api :GET, '/:resource_id/:id'
|
11
|
+
param :id, String
|
12
|
+
def show
|
13
|
+
render :plain => "OK #{params.inspect}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def_param_group :concern do
|
17
|
+
param :concern, Hash, :required => true, :action_aware => true do
|
18
|
+
param :name, String, "Name of a :concern"
|
19
|
+
param :concern_type, String
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
api :POST, '/:resource_id', "Create a :concern"
|
24
|
+
param_group :concern
|
25
|
+
def create
|
26
|
+
render :plain => "OK #{params.inspect}"
|
27
|
+
end
|
28
|
+
|
29
|
+
api :PUT, '/:resource_id/:id'
|
30
|
+
param :id, String
|
31
|
+
param_group :concern
|
32
|
+
def update
|
33
|
+
render :plain => "OK #{params.inspect}"
|
34
|
+
end
|
35
|
+
|
36
|
+
api :GET, '/:resource_id/:custom_subst'
|
37
|
+
def custom
|
38
|
+
render :plain => "OK #{params.inspect}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class OverriddenConcernsController < ApplicationController
|
2
|
+
|
3
|
+
resource_description { resource_id 'overridden_concern_resources' }
|
4
|
+
|
5
|
+
apipie_concern_subst(:concern => 'user')
|
6
|
+
include ::Concerns::SampleController
|
7
|
+
|
8
|
+
def_param_group :concern do
|
9
|
+
param :concern, String
|
10
|
+
end
|
11
|
+
|
12
|
+
api :PUT, '/:resource_id/:id'
|
13
|
+
param :custom_parameter, String, "New parameter added by the overriding method"
|
14
|
+
param_group :concern, ::Concerns::SampleController
|
15
|
+
def update
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
api :POST, '/:resource_id', "Create a :concern"
|
20
|
+
param_group :concern
|
21
|
+
def create
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
api :GET, '/:resource_id/custom'
|
26
|
+
param :concern, String
|
27
|
+
def custom
|
28
|
+
render :text => "OK #{params.inspect}"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,408 @@
|
|
1
|
+
#
|
2
|
+
# The PetsController defined here provides examples for different ways
|
3
|
+
# in which the 'returns' DSL directive can be used with the existing
|
4
|
+
# Apipie DSL elements 'param' and 'param_group'
|
5
|
+
#
|
6
|
+
|
7
|
+
class PetsController < ApplicationController
|
8
|
+
resource_description do
|
9
|
+
description 'A controller to test "returns"'
|
10
|
+
short 'Pets'
|
11
|
+
path '/pets'
|
12
|
+
|
13
|
+
param :common_param, Integer, :desc => "A param that can optionally be passed to all Pet methods", :required => false
|
14
|
+
|
15
|
+
returns :code => 404 do
|
16
|
+
property :error_message, String, "description of the error"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
#-----------------------------------------------------------
|
22
|
+
# simple 'returns' example: a method that returns a pet record
|
23
|
+
#-----------------------------------------------------------
|
24
|
+
api :GET, "/pets/:id/as_properties", "Get a pet record"
|
25
|
+
returns :code => 200 do
|
26
|
+
property :pet_name, String, :desc => "Name of pet", :required => false
|
27
|
+
property :animal_type, ['dog','cat','iguana','kangaroo'], :desc => "Type of pet" # required by default, because this is a 'property'
|
28
|
+
end
|
29
|
+
returns :code => 404 do
|
30
|
+
property :another_error_message, String, :desc => "Overriding the response description from the Pets resource"
|
31
|
+
end
|
32
|
+
def show_as_properties
|
33
|
+
render :plain => "showing pet properties"
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
#-----------------------------------------------------------
|
38
|
+
# same example as above, but this time the properties are defined
|
39
|
+
# in a param group
|
40
|
+
#-----------------------------------------------------------
|
41
|
+
def_param_group :pet do
|
42
|
+
property :pet_name, String, :desc => "Name of pet", :required => false
|
43
|
+
property :animal_type, ['dog','cat','iguana','kangaroo'], :desc => "Type of pet" # required by default, because this is a 'property'
|
44
|
+
end
|
45
|
+
|
46
|
+
api :GET, "/pets/:id/as_param_group_of_properties", "Get a pet record"
|
47
|
+
returns :pet, :code => 200, :desc => "The pet"
|
48
|
+
def show_as_param_group_of_properties
|
49
|
+
render :plain => "showing pet properties defined as param groups"
|
50
|
+
end
|
51
|
+
|
52
|
+
#-----------------------------------------------------------
|
53
|
+
# Method returning an array of the :pet param_group
|
54
|
+
#-----------------------------------------------------------
|
55
|
+
api :GET, "/pets", "Get all pets"
|
56
|
+
returns :array_of => :pet, :desc => "list of pets"
|
57
|
+
def index
|
58
|
+
render :plain => "all pets"
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
#-----------------------------------------------------------
|
63
|
+
# mixing request/response and response-only parameters
|
64
|
+
#
|
65
|
+
# the param_group :pet_with_id has several parameters which are
|
66
|
+
# not expectd in the request, but would show up in the response
|
67
|
+
# and vice versa
|
68
|
+
#-----------------------------------------------------------
|
69
|
+
def_param_group :pet_with_id do
|
70
|
+
param :pet_id, Integer, :desc => "id of pet", :required => true
|
71
|
+
param :pet_name, String, :desc => "Name of pet", :required => false, :only_in => :response
|
72
|
+
param :partial_match_allowed, [true, false], :desc => "Partial match allowed?", :required => false, :only_in => :request
|
73
|
+
property :animal_type, ['dog','cat','iguana','kangaroo'], :desc => "Type of pet" # this is implicitly :only_in => :response
|
74
|
+
end
|
75
|
+
|
76
|
+
api :GET, "/pets/pet_by_id", "Get a pet record with the pet id in the body of the request"
|
77
|
+
param_group :pet_with_id # only the pet_id is expected to be in here
|
78
|
+
returns :param_group => :pet_with_id, :code => 200
|
79
|
+
def show_pet_by_id
|
80
|
+
render :plain => "returning a record with 3 fields"
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
#-----------------------------------------------------------
|
86
|
+
# example with multiple param groups
|
87
|
+
#-----------------------------------------------------------
|
88
|
+
def_param_group :owner do # a param group that can be used to describe inputs as well as outputs
|
89
|
+
param :owner_name, String
|
90
|
+
end
|
91
|
+
def_param_group :user_response do # a param group that can be used to describe outputs only
|
92
|
+
property :vote, [true,false]
|
93
|
+
end
|
94
|
+
|
95
|
+
api :GET, "/pets/by_owner_name/did_vote", "did any of the pets owned by the given user vote?"
|
96
|
+
param_group :owner, :desc => "look up the user by name"
|
97
|
+
returns :code => 200 do
|
98
|
+
param_group :owner
|
99
|
+
param_group :user_response
|
100
|
+
end
|
101
|
+
returns :code => 404 # no body
|
102
|
+
def get_vote_by_owner_name
|
103
|
+
render :plain => "no pets have voted"
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
#-----------------------------------------------------------
|
108
|
+
# a method returning multiple codes,
|
109
|
+
# some of which have a complex data structure
|
110
|
+
#-----------------------------------------------------------
|
111
|
+
def_param_group :pet_measurements do
|
112
|
+
property :pet_measurements, Hash do
|
113
|
+
property :weight, Integer, :desc => "Weight in pounds"
|
114
|
+
property :height, Integer, :desc => "Height in inches"
|
115
|
+
property :num_legs, Integer, :desc => "Number of legs", :required => false
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def_param_group :pet_history do
|
120
|
+
property :did_visit_vet, [true,false], :desc => "Did the pet visit the veterinarian"
|
121
|
+
property :avg_meals_per_day, Float, :desc => "Average number of meals per day"
|
122
|
+
end
|
123
|
+
|
124
|
+
api :GET, "/pets/:id/extra_info", "Get extra information about a pet"
|
125
|
+
returns :code => 201, :desc => "Found a pet" do
|
126
|
+
param_group :pet
|
127
|
+
end
|
128
|
+
returns :code => 202 do
|
129
|
+
param_group :pet
|
130
|
+
param_group :pet_measurements
|
131
|
+
end
|
132
|
+
returns :code => 203 do
|
133
|
+
param_group :pet
|
134
|
+
param_group :pet_measurements
|
135
|
+
property 'pet_history', Hash do # the pet_history param_group does not contain a wrapping object,
|
136
|
+
# so create one manually
|
137
|
+
param_group :pet_history
|
138
|
+
end
|
139
|
+
property 'additional_histories', :array_of => Hash do
|
140
|
+
param_group :pet_history
|
141
|
+
end
|
142
|
+
end
|
143
|
+
returns :code => 204 do
|
144
|
+
property :int_array, :array_of => Integer
|
145
|
+
property :enum_array, :array_of => ['v1','v2','v3']
|
146
|
+
end
|
147
|
+
returns :code => :unprocessable_entity, :desc => "Fleas were discovered on the pet" do
|
148
|
+
param_group :pet
|
149
|
+
property :num_fleas, Integer, :desc => "Number of fleas on this pet"
|
150
|
+
end
|
151
|
+
def show_extra_info
|
152
|
+
render :plain => "please disinfect your pet"
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
#=======================================================================
|
157
|
+
# Methods for testing response validation
|
158
|
+
#=======================================================================
|
159
|
+
|
160
|
+
|
161
|
+
#-----------------------------------------------------------
|
162
|
+
# A method which returns the response as described
|
163
|
+
#-----------------------------------------------------------
|
164
|
+
api!
|
165
|
+
returns :code => 200 do
|
166
|
+
property :a_number, Integer
|
167
|
+
property :an_optional_number, Integer, :required=>false
|
168
|
+
end
|
169
|
+
def return_and_validate_expected_response
|
170
|
+
result = {
|
171
|
+
a_number: 3
|
172
|
+
}
|
173
|
+
render :json => result
|
174
|
+
end
|
175
|
+
|
176
|
+
#-----------------------------------------------------------
|
177
|
+
# A method which returns a null value in the response
|
178
|
+
#-----------------------------------------------------------
|
179
|
+
api!
|
180
|
+
returns :code => 200 do
|
181
|
+
property :a_number, Integer
|
182
|
+
property :an_optional_number, Integer, :required=>false
|
183
|
+
end
|
184
|
+
def return_and_validate_expected_response_with_null
|
185
|
+
result = {
|
186
|
+
a_number: nil
|
187
|
+
}
|
188
|
+
render :json => result
|
189
|
+
end
|
190
|
+
|
191
|
+
#-----------------------------------------------------------
|
192
|
+
# A method which returns a null value in the response instead of an object
|
193
|
+
#-----------------------------------------------------------
|
194
|
+
api!
|
195
|
+
returns :code => 200 do
|
196
|
+
property :an_object, Hash do
|
197
|
+
property :an_optional_number, Integer, :required=>false
|
198
|
+
end
|
199
|
+
end
|
200
|
+
def return_and_validate_expected_response_with_null_object
|
201
|
+
result = {
|
202
|
+
an_object: nil
|
203
|
+
}
|
204
|
+
render :json => result
|
205
|
+
end
|
206
|
+
|
207
|
+
#-----------------------------------------------------------
|
208
|
+
# A method which returns an array response as described
|
209
|
+
#-----------------------------------------------------------
|
210
|
+
def_param_group :two_numbers do
|
211
|
+
property :a_number, Integer
|
212
|
+
property :an_optional_number, Integer, :required=>false
|
213
|
+
end
|
214
|
+
|
215
|
+
api!
|
216
|
+
returns :code => 200, :array_of => :two_numbers
|
217
|
+
def return_and_validate_expected_array_response
|
218
|
+
result = [{
|
219
|
+
a_number: 3
|
220
|
+
}]
|
221
|
+
render :json => result
|
222
|
+
end
|
223
|
+
|
224
|
+
#-----------------------------------------------------------
|
225
|
+
# A method which returns an array response when it is expected to return an object
|
226
|
+
# (note that response code is set here to 201)
|
227
|
+
#-----------------------------------------------------------
|
228
|
+
api!
|
229
|
+
returns :two_numbers, :code => 201
|
230
|
+
def return_and_validate_unexpected_array_response
|
231
|
+
result = [{
|
232
|
+
a_number: 3
|
233
|
+
}]
|
234
|
+
render :status => 201, :json => result
|
235
|
+
end
|
236
|
+
|
237
|
+
#-----------------------------------------------------------
|
238
|
+
# A method which has a response that does not match the output type
|
239
|
+
#-----------------------------------------------------------
|
240
|
+
api!
|
241
|
+
returns :code => 200 do
|
242
|
+
property :a_number, String
|
243
|
+
end
|
244
|
+
def return_and_validate_type_mismatch
|
245
|
+
result = {
|
246
|
+
a_number: 3
|
247
|
+
}
|
248
|
+
render :json => result
|
249
|
+
end
|
250
|
+
|
251
|
+
#-----------------------------------------------------------
|
252
|
+
# A method with no documentation
|
253
|
+
#-----------------------------------------------------------
|
254
|
+
def undocumented_method
|
255
|
+
render :json => {:result => "ok"}
|
256
|
+
end
|
257
|
+
|
258
|
+
#-----------------------------------------------------------
|
259
|
+
# A method which has a response with a missing field
|
260
|
+
#-----------------------------------------------------------
|
261
|
+
api!
|
262
|
+
returns :code => 200 do
|
263
|
+
property :a_number, Integer
|
264
|
+
property :another_number, Integer
|
265
|
+
end
|
266
|
+
def return_and_validate_missing_field
|
267
|
+
result = {
|
268
|
+
a_number: 3
|
269
|
+
}
|
270
|
+
render :json => result
|
271
|
+
end
|
272
|
+
|
273
|
+
|
274
|
+
#-----------------------------------------------------------
|
275
|
+
# A method which has a response with an extra property
|
276
|
+
# (should raise a validation error by default)
|
277
|
+
#-----------------------------------------------------------
|
278
|
+
api!
|
279
|
+
returns :code => 200 do
|
280
|
+
property :a_number, Integer
|
281
|
+
end
|
282
|
+
def return_and_validate_extra_property
|
283
|
+
result = {
|
284
|
+
a_number: 3,
|
285
|
+
another_number: 4
|
286
|
+
}
|
287
|
+
render :json => result
|
288
|
+
end
|
289
|
+
|
290
|
+
|
291
|
+
#-----------------------------------------------------------
|
292
|
+
# A method which has a response with an extra property, but 'additional_properties' is specified
|
293
|
+
# (should not raise a validation error by default)
|
294
|
+
#-----------------------------------------------------------
|
295
|
+
api!
|
296
|
+
returns :code => 200, :additional_properties => true do
|
297
|
+
property :a_number, Integer
|
298
|
+
end
|
299
|
+
def return_and_validate_allowed_extra_property
|
300
|
+
result = {
|
301
|
+
a_number: 3,
|
302
|
+
another_number: 4
|
303
|
+
}
|
304
|
+
render :json => result
|
305
|
+
end
|
306
|
+
|
307
|
+
#-----------------------------------------------------------
|
308
|
+
# Sub-object in response has an extra property. 'additional_properties' is specified on the response, but not on the object
|
309
|
+
# (should raise a validation error by default)
|
310
|
+
#-----------------------------------------------------------
|
311
|
+
api!
|
312
|
+
returns :code => 200, :additional_properties => true do
|
313
|
+
property :an_object, Hash do
|
314
|
+
property :a_number, Integer
|
315
|
+
end
|
316
|
+
end
|
317
|
+
def sub_object_invalid_extra_property
|
318
|
+
result = {
|
319
|
+
an_object: {
|
320
|
+
a_number: 2,
|
321
|
+
an_extra_number: 3
|
322
|
+
}
|
323
|
+
}
|
324
|
+
render :json => result
|
325
|
+
end
|
326
|
+
|
327
|
+
|
328
|
+
#-----------------------------------------------------------
|
329
|
+
# Sub-object in response has an extra property. 'additional_properties' is specified on the object, but not on the response
|
330
|
+
# (should not raise a validation error by default)
|
331
|
+
#-----------------------------------------------------------
|
332
|
+
api!
|
333
|
+
returns :code => 200, :additional_properties => false do
|
334
|
+
property :an_object, Hash, :additional_properties => true do
|
335
|
+
property :a_number, Integer
|
336
|
+
end
|
337
|
+
end
|
338
|
+
def sub_object_allowed_extra_property
|
339
|
+
result = {
|
340
|
+
an_object: {
|
341
|
+
a_number: 2,
|
342
|
+
an_extra_number: 3
|
343
|
+
}
|
344
|
+
}
|
345
|
+
render :json => result
|
346
|
+
end
|
347
|
+
|
348
|
+
#=======================================================================
|
349
|
+
# Methods for testing array field responses
|
350
|
+
#=======================================================================
|
351
|
+
|
352
|
+
#-----------------------------------------------------------
|
353
|
+
# A method which returns the response as described (one field is an array of objects)
|
354
|
+
#-----------------------------------------------------------
|
355
|
+
api!
|
356
|
+
returns :code => 200 do
|
357
|
+
property :a_number, Integer
|
358
|
+
property :array_of_objects, :array_of => Hash do
|
359
|
+
property :number1, Integer, :required=>true
|
360
|
+
property :number2, Integer, :required=>true
|
361
|
+
end
|
362
|
+
end
|
363
|
+
def returns_response_with_valid_array
|
364
|
+
result = {
|
365
|
+
a_number: 3,
|
366
|
+
array_of_objects: [
|
367
|
+
{number1: 1, number2: 2},
|
368
|
+
{number1: 10, number2: 20}
|
369
|
+
]
|
370
|
+
}
|
371
|
+
render :json => result
|
372
|
+
end
|
373
|
+
|
374
|
+
|
375
|
+
#-----------------------------------------------------------
|
376
|
+
# A method which returns an incorrect response (wrong field type inside array)
|
377
|
+
#-----------------------------------------------------------
|
378
|
+
api!
|
379
|
+
returns :code => 200 do
|
380
|
+
property :a_number, Integer
|
381
|
+
property :array_of_objects, :array_of => Hash do
|
382
|
+
property :number1, Integer, :required=>true
|
383
|
+
property :number2, Integer, :required=>true
|
384
|
+
end
|
385
|
+
end
|
386
|
+
def returns_response_with_invalid_array
|
387
|
+
result = {
|
388
|
+
a_number: 3,
|
389
|
+
array_of_objects: [
|
390
|
+
{number1: 1, number2: 2},
|
391
|
+
{number1: 10, number2: "this should have been a number"}
|
392
|
+
]
|
393
|
+
}
|
394
|
+
render :json => result
|
395
|
+
end
|
396
|
+
|
397
|
+
|
398
|
+
#-----------------------------------------------------------
|
399
|
+
# A method with simple tags.
|
400
|
+
#-----------------------------------------------------------
|
401
|
+
api!
|
402
|
+
tags(%w[Dogs Cats LivingBeings])
|
403
|
+
def show_plain_response_with_tags
|
404
|
+
render :plain => "showing pet properties"
|
405
|
+
end
|
406
|
+
|
407
|
+
end
|
408
|
+
|