apipie-rails-jq 1.4.3.pre.beta.pre.jq.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/build.yml +32 -0
- data/.github/workflows/rubocop-challenger.yml +26 -0
- data/.github/workflows/rubocop.yml +18 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.rubocop.yml +132 -0
- data/.rubocop_todo.yml +1967 -0
- data/.vscode/settings.json +3 -0
- data/APACHE-LICENSE-2.0 +202 -0
- data/CHANGELOG.md +693 -0
- data/Gemfile +19 -0
- data/MIT-LICENSE +20 -0
- data/NOTICE +4 -0
- data/PROPOSAL_FOR_RESPONSE_DESCRIPTIONS.md +244 -0
- data/README.md +2088 -0
- data/Rakefile +8 -0
- data/apipie-rails.gemspec +44 -0
- data/app/controllers/apipie/apipies_controller.rb +184 -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 +167 -0
- data/app/public/apipie/javascripts/bundled/bootstrap.js +2280 -0
- data/app/public/apipie/javascripts/bundled/jquery.js +2 -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 +9 -0
- data/app/public/apipie/stylesheets/bundled/bootstrap.min.css +9 -0
- data/app/public/apipie/stylesheets/bundled/prettify.css +30 -0
- data/app/views/apipie/apipies/_deprecation.html.erb +16 -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 +63 -0
- data/app/views/apipie/apipies/_params.html.erb +49 -0
- data/app/views/apipie/apipies/_params_plain.html.erb +21 -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 +41 -0
- data/config/locales/es.yml +28 -0
- data/config/locales/fr.yml +31 -0
- data/config/locales/it.yml +41 -0
- data/config/locales/ja.yml +31 -0
- data/config/locales/ko.yml +32 -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/gemfiles/Gemfile.tools +9 -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 +499 -0
- data/lib/apipie/configuration.rb +196 -0
- data/lib/apipie/core_ext/route.rb +9 -0
- data/lib/apipie/dsl_definition.rb +630 -0
- data/lib/apipie/error_description.rb +46 -0
- data/lib/apipie/errors.rb +86 -0
- data/lib/apipie/extractor/collector.rb +116 -0
- data/lib/apipie/extractor/recorder.rb +193 -0
- data/lib/apipie/extractor/writer.rb +454 -0
- data/lib/apipie/extractor.rb +181 -0
- data/lib/apipie/generator/config.rb +12 -0
- data/lib/apipie/generator/generator.rb +2 -0
- data/lib/apipie/generator/swagger/computed_interface_id.rb +23 -0
- data/lib/apipie/generator/swagger/config.rb +80 -0
- data/lib/apipie/generator/swagger/context.rb +38 -0
- data/lib/apipie/generator/swagger/method_description/api_decorator.rb +20 -0
- data/lib/apipie/generator/swagger/method_description/api_schema_service.rb +89 -0
- data/lib/apipie/generator/swagger/method_description/decorator.rb +22 -0
- data/lib/apipie/generator/swagger/method_description/parameters_service.rb +139 -0
- data/lib/apipie/generator/swagger/method_description/response_schema_service.rb +46 -0
- data/lib/apipie/generator/swagger/method_description/response_service.rb +71 -0
- data/lib/apipie/generator/swagger/method_description.rb +2 -0
- data/lib/apipie/generator/swagger/operation_id.rb +51 -0
- data/lib/apipie/generator/swagger/param_description/builder.rb +114 -0
- data/lib/apipie/generator/swagger/param_description/composite.rb +119 -0
- data/lib/apipie/generator/swagger/param_description/description.rb +15 -0
- data/lib/apipie/generator/swagger/param_description/in.rb +37 -0
- data/lib/apipie/generator/swagger/param_description/name.rb +18 -0
- data/lib/apipie/generator/swagger/param_description/path_params_composite.rb +61 -0
- data/lib/apipie/generator/swagger/param_description/referenced_composite.rb +36 -0
- data/lib/apipie/generator/swagger/param_description/type.rb +132 -0
- data/lib/apipie/generator/swagger/param_description.rb +18 -0
- data/lib/apipie/generator/swagger/path_decorator.rb +36 -0
- data/lib/apipie/generator/swagger/referenced_definitions.rb +17 -0
- data/lib/apipie/generator/swagger/resource_description_collection.rb +30 -0
- data/lib/apipie/generator/swagger/resource_description_composite.rb +56 -0
- data/lib/apipie/generator/swagger/schema.rb +63 -0
- data/lib/apipie/generator/swagger/swagger.rb +2 -0
- data/lib/apipie/generator/swagger/type.rb +16 -0
- data/lib/apipie/generator/swagger/type_extractor.rb +51 -0
- data/lib/apipie/generator/swagger/warning.rb +74 -0
- data/lib/apipie/generator/swagger/warning_writer.rb +54 -0
- data/lib/apipie/helpers.rb +73 -0
- data/lib/apipie/markup.rb +52 -0
- data/lib/apipie/method_description/api.rb +12 -0
- data/lib/apipie/method_description/apis_service.rb +82 -0
- data/lib/apipie/method_description.rb +230 -0
- data/lib/apipie/middleware/checksum_in_headers.rb +35 -0
- data/lib/apipie/param_description/deprecation.rb +24 -0
- data/lib/apipie/param_description.rb +313 -0
- data/lib/apipie/railtie.rb +9 -0
- data/lib/apipie/resource_description.rb +152 -0
- data/lib/apipie/response_description.rb +157 -0
- data/lib/apipie/response_description_adapter.rb +202 -0
- data/lib/apipie/routes_formatter.rb +33 -0
- data/lib/apipie/routing.rb +16 -0
- data/lib/apipie/rspec/response_validation_helper.rb +194 -0
- data/lib/apipie/see_description.rb +39 -0
- data/lib/apipie/static_dispatcher.rb +75 -0
- data/lib/apipie/swagger_generator.rb +45 -0
- data/lib/apipie/tag_list_description.rb +11 -0
- data/lib/apipie/validator.rb +552 -0
- data/lib/apipie/version.rb +3 -0
- data/lib/apipie-rails.rb +60 -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 +355 -0
- data/rel-eng/gem_release.ipynb +398 -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 +19 -0
- data/spec/controllers/api/v2/empty_middle_controller_spec.rb +23 -0
- data/spec/controllers/api/v2/nested/resources_controller_spec.rb +27 -0
- data/spec/controllers/api/v2/sub/footguns_controller_spec.rb +19 -0
- data/spec/controllers/concerns_controller_spec.rb +42 -0
- data/spec/controllers/extended_controller_spec.rb +14 -0
- data/spec/controllers/included_param_group_controller_spec.rb +13 -0
- data/spec/controllers/pets_controller_spec.rb +98 -0
- data/spec/controllers/users_controller_spec.rb +794 -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 +31 -0
- data/spec/dummy/app/controllers/api/v2/base_controller.rb +17 -0
- data/spec/dummy/app/controllers/api/v2/empty_middle_controller.rb +14 -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/api/v2/sub/footguns_controller.rb +30 -0
- data/spec/dummy/app/controllers/application_controller.rb +18 -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/extending_concern.rb +10 -0
- data/spec/dummy/app/controllers/files_controller.rb +5 -0
- data/spec/dummy/app/controllers/included_param_group_controller.rb +19 -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/sample_controller.rb +39 -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 +310 -0
- data/spec/dummy/app/helpers/random_param_group.rb +8 -0
- data/spec/dummy/app/views/layouts/application.html.erb +21 -0
- data/spec/dummy/components/test_engine/Gemfile +6 -0
- data/spec/dummy/components/test_engine/app/controllers/test_engine/application_controller.rb +4 -0
- data/spec/dummy/components/test_engine/app/controllers/test_engine/memes_controller.rb +37 -0
- data/spec/dummy/components/test_engine/config/routes.rb +3 -0
- data/spec/dummy/components/test_engine/db/.gitkeep +0 -0
- data/spec/dummy/components/test_engine/lib/test_engine.rb +7 -0
- data/spec/dummy/components/test_engine/test_engine.gemspec +11 -0
- data/spec/dummy/config/application.rb +47 -0
- data/spec/dummy/config/boot.rb +12 -0
- data/spec/dummy/config/database.yml +21 -0
- data/spec/dummy/config/environment.rb +8 -0
- data/spec/dummy/config/environments/development.rb +25 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +33 -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 +61 -0
- data/spec/dummy/config.ru +4 -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/apipie/apipies_controller_spec.rb +345 -0
- data/spec/lib/apipie/application_spec.rb +62 -0
- data/spec/lib/apipie/configuration_spec.rb +38 -0
- data/spec/lib/apipie/extractor/collector_spec.rb +57 -0
- data/spec/lib/apipie/extractor/recorder/middleware_spec.rb +44 -0
- data/spec/lib/apipie/extractor/recorder_spec.rb +77 -0
- data/spec/lib/apipie/extractor/writer_spec.rb +112 -0
- data/spec/lib/apipie/extractor_spec.rb +9 -0
- data/spec/lib/apipie/file_handler_spec.rb +25 -0
- data/spec/lib/apipie/generator/swagger/config_spec.rb +19 -0
- data/spec/lib/apipie/generator/swagger/context_spec.rb +56 -0
- data/spec/lib/apipie/generator/swagger/method_description/api_schema_service_spec.rb +119 -0
- data/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb +105 -0
- data/spec/lib/apipie/generator/swagger/method_description/response_service_spec.rb +62 -0
- data/spec/lib/apipie/generator/swagger/operation_id_spec.rb +63 -0
- data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +245 -0
- data/spec/lib/apipie/generator/swagger/param_description/composite_spec.rb +95 -0
- data/spec/lib/apipie/generator/swagger/param_description/description_spec.rb +79 -0
- data/spec/lib/apipie/generator/swagger/param_description/in_spec.rb +86 -0
- data/spec/lib/apipie/generator/swagger/param_description/name_spec.rb +81 -0
- data/spec/lib/apipie/generator/swagger/param_description/type_spec.rb +210 -0
- data/spec/lib/apipie/generator/swagger/param_description_spec.rb +28 -0
- data/spec/lib/apipie/generator/swagger/path_decorator_spec.rb +57 -0
- data/spec/lib/apipie/generator/swagger/referenced_definitions_spec.rb +35 -0
- data/spec/lib/apipie/generator/swagger/resource_description_composite_spec.rb +37 -0
- data/spec/lib/apipie/generator/swagger/resource_descriptions_collection_spec.rb +57 -0
- data/spec/lib/apipie/generator/swagger/schema_spec.rb +89 -0
- data/spec/lib/apipie/generator/swagger/type_extractor_spec.rb +38 -0
- data/spec/lib/apipie/generator/swagger/warning_spec.rb +51 -0
- data/spec/lib/apipie/generator/swagger/warning_writer_spec.rb +71 -0
- data/spec/lib/apipie/method_description/apis_service_spec.rb +60 -0
- data/spec/lib/apipie/method_description_spec.rb +133 -0
- data/spec/lib/apipie/no_documented_method_spec.rb +17 -0
- data/spec/lib/apipie/param_description/deprecation_spec.rb +31 -0
- data/spec/lib/apipie/param_description_spec.rb +671 -0
- data/spec/lib/apipie/param_group_spec.rb +61 -0
- data/spec/lib/apipie/resource_description_spec.rb +91 -0
- data/spec/lib/apipie/response_description/response_object_spec.rb +22 -0
- data/spec/lib/apipie/response_description_spec.rb +56 -0
- data/spec/lib/apipie/response_does_not_match_swagger_schema_spec.rb +35 -0
- data/spec/lib/apipie/swagger_generator_spec.rb +94 -0
- data/spec/lib/apipie/validator_spec.rb +149 -0
- data/spec/lib/rake_spec.rb +69 -0
- data/spec/lib/swagger/openapi_2_0_schema.json +1614 -0
- data/spec/lib/swagger/rake_swagger_spec.rb +159 -0
- data/spec/lib/swagger/swagger_dsl_spec.rb +664 -0
- data/spec/lib/validators/array_validator_spec.rb +85 -0
- data/spec/spec_helper.rb +92 -0
- data/spec/support/custom_bool_validator.rb +17 -0
- data/spec/support/rake.rb +21 -0
- data/spec/test_engine/memes_controller_spec.rb +10 -0
- metadata +499 -0
@@ -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, :example => 'mypet'
|
27
|
+
property :animal_type, %w[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, %w[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 expected 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, %w[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 => %w[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
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#
|
2
|
+
# demonstration of how the 'describe_own_properties' method can be used
|
3
|
+
# to integrate Apipie response descriptions with view generation packages
|
4
|
+
# such as, for example, Grape::Entity
|
5
|
+
#
|
6
|
+
|
7
|
+
# Consider a hypothetical SelfDocumentingView class (a stand-in for Grape::Entity
|
8
|
+
# for demonstrational purposes). This is an abstract class, supporting the implementation
|
9
|
+
# of actual views as subclasses of SelfDocumentingView.
|
10
|
+
#
|
11
|
+
# A user of SelfDocumentingView would implement a subclass for each desired view. Each such
|
12
|
+
# view definition would include, for each field that should be returned in the JSON response,
|
13
|
+
# an instance method called v_<name>__<type>.
|
14
|
+
#
|
15
|
+
# SelfDocumentingView would then scan the subclass for such fields and:
|
16
|
+
# 1. Given an id: fetch the matching model and generated a view from it using the field definitions
|
17
|
+
# 2. Describe the structure of such views to Apipie using self.describe_own_properties
|
18
|
+
#
|
19
|
+
# (see the controller implementation below for how such a class might be used)
|
20
|
+
|
21
|
+
class SelfDocumentingView
|
22
|
+
# self.describe_own_properties (a class method) generates the meta-data
|
23
|
+
# (i.e., the type description) for the subclass.
|
24
|
+
def self.describe_own_properties
|
25
|
+
(self.instance_methods - self.class.instance_methods).map do |m|
|
26
|
+
if matchdata = /^v_(\w+)__(\w+)$/.match(m)
|
27
|
+
Apipie::prop(matchdata[1], matchdata[2])
|
28
|
+
end
|
29
|
+
end.compact
|
30
|
+
end
|
31
|
+
|
32
|
+
# to_json (an instance method) generates the actual view
|
33
|
+
def to_json
|
34
|
+
{ note: "in an actual implementation of SelfDocumentingView, this method
|
35
|
+
would call each v_<name>__<type> method and include its output
|
36
|
+
in the response as a (<name>: <value>) pair"
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def initialize(id)
|
41
|
+
load_from_model(id)
|
42
|
+
end
|
43
|
+
|
44
|
+
def load_from_model(id)
|
45
|
+
# in a real implementation of SelfDocumentingView, this
|
46
|
+
# method would load the fields to be displayed from the model
|
47
|
+
# instance identified by 'id'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
#
|
53
|
+
# ViewOfPet extends SelfDocumentingView to include specific fields
|
54
|
+
#
|
55
|
+
class ViewOfPet < SelfDocumentingView
|
56
|
+
attr_accessor :v_pet_name__string
|
57
|
+
attr_accessor :v_animal_type__string
|
58
|
+
attr_accessor :v_age__number
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
class PetsUsingAutoViewsController < ApplicationController
|
63
|
+
#-----------------------------------------------------------
|
64
|
+
# Method returning an array of AutomatedViewOfPet (where
|
65
|
+
# AutomatedViewOfPet is an auto-generated self-describing class)
|
66
|
+
# -----------------------------------------------------------
|
67
|
+
api :GET, "/pet_described_using_automated_view/:id", "Get the measurements of a single pet"
|
68
|
+
param :id, String
|
69
|
+
returns ViewOfPet, :desc => "like Pet, but different"
|
70
|
+
def pet_described_using_automated_view
|
71
|
+
render :plain => ViewOfPet.new(params.id).to_json
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
#----------------------------------------------------------------------------------------------------
|
2
|
+
# A "self-describing class" is a class that respond_to? :describe_own_properties
|
3
|
+
# and returns an array of Property Descriptions.
|
4
|
+
# (The simple way to create Property Description objects is using the Apipie::prop helper function,
|
5
|
+
# which is a factory for Apipie::ResponseDescriptionAdapter::PropDesc instances)
|
6
|
+
#
|
7
|
+
#----------------------------------------------------------------------------------------------------
|
8
|
+
|
9
|
+
|
10
|
+
# in this example, Pet is a self-describing class with only two properties.
|
11
|
+
# In a real implementation, the Pet class would actually do something with these properties.
|
12
|
+
# Here, the class is defined to only include the describe_own_properties method.
|
13
|
+
class Pet
|
14
|
+
def self.describe_own_properties
|
15
|
+
[
|
16
|
+
Apipie::prop(:pet_name, 'string', {:description => 'Name of pet', :required => false}),
|
17
|
+
Apipie::prop(:animal_type, 'string', {:description => 'Type of pet', :values => %w[dog cat iguana kangaroo]}),
|
18
|
+
Apipie::additional_properties(false)
|
19
|
+
]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# PetWithMeasurements is a self-describing class with an embedded object
|
25
|
+
#
|
26
|
+
class PetWithMeasurements
|
27
|
+
def self.describe_own_properties
|
28
|
+
[
|
29
|
+
Apipie::prop(:pet_name, 'string', {:description => 'Name of pet', :required => false}),
|
30
|
+
Apipie::prop('animal_type', 'string', {:description => 'Type of pet', :values => %w[dog cat iguana kangaroo]}),
|
31
|
+
Apipie::prop(:pet_measurements, 'object', {}, [
|
32
|
+
Apipie::prop(:weight, 'number', {:description => "Weight in pounds" }),
|
33
|
+
Apipie::prop(:height, 'number', {:description => "Height in inches" }),
|
34
|
+
Apipie::prop(:num_legs, 'number', {:description => "Number of legs", :required => false }),
|
35
|
+
Apipie::additional_properties(false)
|
36
|
+
])
|
37
|
+
]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# PetWithManyMeasurements is a self-describing class with an embedded object
|
43
|
+
#
|
44
|
+
class PetWithManyMeasurements
|
45
|
+
def self.describe_own_properties
|
46
|
+
[
|
47
|
+
Apipie::prop(:pet_name, 'string', {:description => 'Name of pet', :required => false}),
|
48
|
+
Apipie::prop(:many_pet_measurements, 'object', {is_array: true}, [
|
49
|
+
Apipie::prop(:weight, 'number', {:description => "Weight in pounds" }),
|
50
|
+
Apipie::prop(:height, 'number', {:description => "Height in inches" }),
|
51
|
+
])
|
52
|
+
]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
class PetsUsingSelfDescribingClassesController < ApplicationController
|
59
|
+
resource_description do
|
60
|
+
description 'A controller to test "returns" using self-describing classes'
|
61
|
+
short 'Pets'
|
62
|
+
path '/pets2'
|
63
|
+
end
|
64
|
+
|
65
|
+
#-----------------------------------------------------------
|
66
|
+
# Method returning an array of Pet (a self-describing class)
|
67
|
+
# -----------------------------------------------------------
|
68
|
+
api :GET, "/pets_described_as_class", "Get all pets"
|
69
|
+
returns :array_of => Pet, :desc => "list of pets"
|
70
|
+
def pets_described_as_class
|
71
|
+
render :plain => "all pets"
|
72
|
+
end
|
73
|
+
|
74
|
+
#-----------------------------------------------------------
|
75
|
+
# Method returning an array of PetWithMeasurements (a self-describing class)
|
76
|
+
# -----------------------------------------------------------
|
77
|
+
api :GET, "/pets_with_measurements_described_as_class/:id", "Get the measurements of a single pet"
|
78
|
+
param :id, String
|
79
|
+
returns PetWithMeasurements, :desc => "measurements of the pet"
|
80
|
+
def pets_with_measurements_described_as_class
|
81
|
+
render :plain => "all pets"
|
82
|
+
end
|
83
|
+
|
84
|
+
#-----------------------------------------------------------
|
85
|
+
# Method returning an array of PetWithManyMeasurements (a self-describing class with array field)
|
86
|
+
# -----------------------------------------------------------
|
87
|
+
api :GET, "/pets_with_many_measurements_as_class/:id", "Get the measurements of a single pet"
|
88
|
+
param :id, String
|
89
|
+
returns PetWithManyMeasurements, :desc => "measurements of the pet"
|
90
|
+
def pets_with_many_measurements_as_class
|
91
|
+
render :plain => "all pets"
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module SampleController
|
2
|
+
extend Apipie::DSL::Concern
|
3
|
+
|
4
|
+
api!
|
5
|
+
def index
|
6
|
+
render :plain => "OK #{params.inspect}"
|
7
|
+
end
|
8
|
+
|
9
|
+
api :GET, '/:resource_id/:id'
|
10
|
+
param :id, String
|
11
|
+
def show
|
12
|
+
render :plain => "OK #{params.inspect}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def_param_group :concern do
|
16
|
+
param :concern, Hash, :required => true, :action_aware => true do
|
17
|
+
param :name, String, "Name of a :concern"
|
18
|
+
param :concern_type, String
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
api :POST, '/:resource_id', "Create a :concern"
|
23
|
+
param_group :concern
|
24
|
+
def create
|
25
|
+
render :plain => "OK #{params.inspect}"
|
26
|
+
end
|
27
|
+
|
28
|
+
api :PUT, '/:resource_id/:id'
|
29
|
+
param :id, String
|
30
|
+
param_group :concern
|
31
|
+
def update
|
32
|
+
render :plain => "OK #{params.inspect}"
|
33
|
+
end
|
34
|
+
|
35
|
+
api :GET, '/:resource_id/:custom_subst'
|
36
|
+
def custom
|
37
|
+
render :plain => "OK #{params.inspect}"
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
# The TagsController defined here provides an example of a resource_description
|
3
|
+
# defining a set of tags for the contained methods to include.
|
4
|
+
#
|
5
|
+
|
6
|
+
class TaggedCatsController < ActionController::Base
|
7
|
+
resource_description do
|
8
|
+
description 'A controller to test "returns"'
|
9
|
+
short 'Pets'
|
10
|
+
path '/pets'
|
11
|
+
|
12
|
+
tags(%w[Dogs Pets])
|
13
|
+
end
|
14
|
+
|
15
|
+
#-----------------------------------------------------------
|
16
|
+
# simple 'returns' example: a method that returns a cat record
|
17
|
+
#-----------------------------------------------------------
|
18
|
+
api :GET, "/pets/:id/as_properties", "Get a cat record"
|
19
|
+
tags(%w[Animals])
|
20
|
+
def show_as_properties
|
21
|
+
render :plain => "showing pet properties"
|
22
|
+
end
|
23
|
+
|
24
|
+
#-----------------------------------------------------------
|
25
|
+
# simple 'returns' example: a method that returns another cat record
|
26
|
+
#-----------------------------------------------------------
|
27
|
+
api :GET, "/pets/:id/as_same_properties", "Get a cat record"
|
28
|
+
tags("Puma", "Animals")
|
29
|
+
def show_as_same_properties
|
30
|
+
render :plain => "showing pet properties"
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#
|
2
|
+
# The TagsController defined here provides an example of a
|
3
|
+
# tags call without a resource description.
|
4
|
+
#
|
5
|
+
|
6
|
+
class TaggedDogsController < ActionController::Base
|
7
|
+
#-----------------------------------------------------------
|
8
|
+
# simple 'returns' example: a method that returns a cat record
|
9
|
+
#-----------------------------------------------------------
|
10
|
+
api :GET, "/pets/:id/as_properties", "Get a dog record"
|
11
|
+
tags(%w[Dogs Wolves])
|
12
|
+
def show_as_properties
|
13
|
+
render :plain => "showing pet properties"
|
14
|
+
end
|
15
|
+
end
|