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,664 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rack/utils'
|
3
|
+
require 'rspec/expectations'
|
4
|
+
|
5
|
+
describe "Swagger Responses" do
|
6
|
+
let(:desc) { Apipie.get_resource_description(controller_class, Apipie.configuration.default_version) }
|
7
|
+
|
8
|
+
let(:swagger) do
|
9
|
+
Apipie.configuration.generator.swagger.suppress_warnings = true
|
10
|
+
Apipie.to_swagger_json(Apipie.configuration.default_version, controller_class.to_s.underscore.sub("_controller", ""))
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:controller_class ) { described_class }
|
14
|
+
|
15
|
+
def get_ref(ref)
|
16
|
+
name = ref.split('#/definitions/')[1].to_sym
|
17
|
+
swagger[:definitions][name]
|
18
|
+
end
|
19
|
+
|
20
|
+
def resolve_refs(schema)
|
21
|
+
if schema['$ref']
|
22
|
+
return get_ref(schema['$ref'])
|
23
|
+
end
|
24
|
+
schema
|
25
|
+
end
|
26
|
+
|
27
|
+
def swagger_response_for(path, code = 200, method = 'get')
|
28
|
+
response = swagger[:paths][path][method][:responses][code]
|
29
|
+
response[:schema] = resolve_refs(response[:schema])
|
30
|
+
response
|
31
|
+
end
|
32
|
+
|
33
|
+
def swagger_params_for(path, method = 'get')
|
34
|
+
swagger[:paths][path][method][:parameters]
|
35
|
+
end
|
36
|
+
|
37
|
+
def swagger_param_by_name(param_name, path, method = 'get')
|
38
|
+
params = swagger_params_for(path, method)
|
39
|
+
matching = params.select{|p| p[:name] == param_name }
|
40
|
+
raise "multiple params named [#{param_name}] in swagger definition for [#{method} #{path}]" if matching.length > 1
|
41
|
+
|
42
|
+
nil if matching.length == 0
|
43
|
+
|
44
|
+
matching[0]
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
#
|
51
|
+
# Matcher to validate the hierarchy of fields described in an internal 'returns' object (without checking their type)
|
52
|
+
#
|
53
|
+
# For example, code such as:
|
54
|
+
# returns_obj = Apipie.get_resource_description(...)._methods.returns.detect{|e| e.code=200})
|
55
|
+
# expect(returns_obj).to match_param_structure([:pet_name, :animal_type, :pet_measurements => [:weight, :height]])
|
56
|
+
#
|
57
|
+
# will verify that the payload structure described for the response of return code 200 is:
|
58
|
+
# {
|
59
|
+
# "pet_name": <any>,
|
60
|
+
# "animal_type": <any>,
|
61
|
+
# "pet_measurements": {
|
62
|
+
# "weight": <any>,
|
63
|
+
# "height": <any>
|
64
|
+
# }
|
65
|
+
# }
|
66
|
+
#
|
67
|
+
#
|
68
|
+
RSpec::Matchers.define :match_field_structure do |expected|
|
69
|
+
@last_message = nil
|
70
|
+
|
71
|
+
match do |actual|
|
72
|
+
deep_match?(actual, expected)
|
73
|
+
end
|
74
|
+
|
75
|
+
def deep_match?(actual, expected, breadcrumb = [])
|
76
|
+
pending_params = actual.params_ordered.dup
|
77
|
+
expected.each do |expected_param|
|
78
|
+
expected_param_name = expected_param.is_a?(Hash) ? expected_param.keys.first : expected_param
|
79
|
+
actual_param = pending_params.find { |param| param.name.to_s == expected_param_name.to_s }
|
80
|
+
unless actual_param
|
81
|
+
@fail_message = "Couldn't find #{expected_param_name.inspect} among #{pending_params.map(&:name)} in #{breadcrumb.join('.')}"
|
82
|
+
return false
|
83
|
+
else
|
84
|
+
pending_params.delete_if { |p| p.object_id == actual_param.object_id }
|
85
|
+
end
|
86
|
+
|
87
|
+
return false unless fields_match?(actual_param, expected_param_name, breadcrumb)
|
88
|
+
if expected_param.is_a? Hash
|
89
|
+
return false unless deep_match?(actual_param.validator, expected_param.values[0], breadcrumb + [expected_param.keys.first])
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
unless pending_params.empty?
|
94
|
+
@fail_message = "Unexpected properties #{pending_params.map(&:name)} in #{breadcrumb.join('.')}"
|
95
|
+
return false
|
96
|
+
end
|
97
|
+
true
|
98
|
+
end
|
99
|
+
|
100
|
+
def fields_match?(param, expected_name, breadcrumb)
|
101
|
+
return false unless have_field?(param, expected_name, breadcrumb)
|
102
|
+
@fail_message = "expected #{(breadcrumb + [param.name]).join('.')} to eq #{(breadcrumb + [expected_name]).join('.')}"
|
103
|
+
param.name.to_s == expected_name.to_s
|
104
|
+
end
|
105
|
+
|
106
|
+
def have_field?(field, expected_name, breadcrumb)
|
107
|
+
@fail_message = "expected property #{(breadcrumb+[expected_name]).join('.')}"
|
108
|
+
!field.nil?
|
109
|
+
end
|
110
|
+
|
111
|
+
failure_message do |actual|
|
112
|
+
@fail_message
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
describe PetsController do
|
118
|
+
|
119
|
+
|
120
|
+
describe "PetsController#index" do
|
121
|
+
subject do
|
122
|
+
desc._methods[:index]
|
123
|
+
end
|
124
|
+
|
125
|
+
it "returns code 200 with array of entries of the format {'pet_name', 'animal_type'}" do
|
126
|
+
returns_obj = subject.returns.detect{|e| e.code == 200 }
|
127
|
+
|
128
|
+
puts returns_obj.to_json
|
129
|
+
expect(returns_obj.code).to eq(200)
|
130
|
+
expect(returns_obj.is_array?).to eq(true)
|
131
|
+
|
132
|
+
expect(returns_obj).to match_field_structure([:pet_name, :animal_type])
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'has the response described in the swagger' do
|
136
|
+
response = swagger_response_for('/pets')
|
137
|
+
expect(response[:description]).to eq("list of pets")
|
138
|
+
|
139
|
+
schema = response[:schema]
|
140
|
+
expect(schema[:type]).to eq("array")
|
141
|
+
|
142
|
+
a_schema = resolve_refs(schema[:items])
|
143
|
+
expect(a_schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
|
144
|
+
expect(a_schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
it "returns code 401 with a String description field" do
|
149
|
+
returns_obj = subject.returns.detect{|e| e.code == 404 }
|
150
|
+
|
151
|
+
expect(returns_obj.code).to eq(404)
|
152
|
+
expect(returns_obj.is_array?).to eq(false)
|
153
|
+
|
154
|
+
expect(returns_obj).to match_field_structure([:error_message])
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
it "returns code 401 with a :reason field (defined in the superclass)" do
|
159
|
+
returns_obj = subject.returns.detect{|e| e.code == 401 }
|
160
|
+
|
161
|
+
expect(returns_obj.code).to eq(401)
|
162
|
+
expect(returns_obj.is_array?).to eq(false)
|
163
|
+
|
164
|
+
expect(returns_obj).to match_field_structure([:reason])
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'has the 404 response described in the swagger' do
|
168
|
+
response = swagger_response_for('/pets', 404)
|
169
|
+
expect(response[:description]).to eq("Not Found")
|
170
|
+
|
171
|
+
schema = response[:schema]
|
172
|
+
expect(schema[:type]).to eq("object")
|
173
|
+
|
174
|
+
expect(schema).to have_field(:error_message, 'string', {:description => 'description of the error', :required => true})
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "PetsController#show_plain_response_with_tags" do
|
180
|
+
subject do
|
181
|
+
desc._methods[:show_plain_response_with_tags]
|
182
|
+
end
|
183
|
+
|
184
|
+
it "returns tags with 'Dogs', 'Cats', and 'LivingBeings'" do
|
185
|
+
returns_obj = subject.tag_list
|
186
|
+
puts returns_obj.inspect
|
187
|
+
|
188
|
+
expect(returns_obj.tags).to eq(%w[Dogs Cats LivingBeings])
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe "PetsController#show_as_properties" do
|
193
|
+
subject do
|
194
|
+
desc._methods[:show_as_properties]
|
195
|
+
end
|
196
|
+
|
197
|
+
it "returns code 200 with 'pet_name' and 'animal_type'" do
|
198
|
+
returns_obj = subject.returns.detect{|e| e.code == 200 }
|
199
|
+
|
200
|
+
puts returns_obj.to_json
|
201
|
+
expect(returns_obj.code).to eq(200)
|
202
|
+
expect(returns_obj.is_array?).to eq(false)
|
203
|
+
|
204
|
+
expect(returns_obj).to match_field_structure([:pet_name, :animal_type])
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'has the response described in the swagger' do
|
208
|
+
response = swagger_response_for('/pets/{id}/as_properties')
|
209
|
+
expect(response[:description]).to eq("OK")
|
210
|
+
|
211
|
+
schema = response[:schema]
|
212
|
+
expect(schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
|
213
|
+
expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'has the 404 response description overridden' do
|
217
|
+
returns_obj = subject.returns.detect{|e| e.code == 404 }
|
218
|
+
|
219
|
+
# puts returns_obj.to_json
|
220
|
+
expect(returns_obj.code).to eq(404)
|
221
|
+
expect(returns_obj.is_array?).to eq(false)
|
222
|
+
|
223
|
+
expect(returns_obj).to match_field_structure([:another_error_message])
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe "PetsController#show_as_param_group_of_properties" do
|
228
|
+
subject do
|
229
|
+
desc._methods[:show_as_param_group_of_properties]
|
230
|
+
end
|
231
|
+
|
232
|
+
it "returns code 200 with 'pet_name' and 'animal_type'" do
|
233
|
+
returns_obj = subject.returns.detect{|e| e.code == 200 }
|
234
|
+
|
235
|
+
puts returns_obj.to_json
|
236
|
+
expect(returns_obj.code).to eq(200)
|
237
|
+
expect(returns_obj.is_array?).to eq(false)
|
238
|
+
|
239
|
+
expect(returns_obj).to match_field_structure([:pet_name, :animal_type])
|
240
|
+
expect(returns_obj.params_ordered[0].is_required?).to be_falsey
|
241
|
+
expect(returns_obj.params_ordered[1].is_required?).to be_truthy
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'has the response described in the swagger' do
|
245
|
+
response = swagger_response_for('/pets/{id}/as_param_group_of_properties')
|
246
|
+
expect(response[:description]).to eq("The pet")
|
247
|
+
|
248
|
+
schema = response[:schema]
|
249
|
+
expect(schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
|
250
|
+
expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe "PetsController#show_pet_by_id" do
|
255
|
+
subject do
|
256
|
+
desc._methods[:show_pet_by_id]
|
257
|
+
end
|
258
|
+
|
259
|
+
it "has only oauth (from ApplicationController), common_param (from resource) and pet_id as an input parameters" do
|
260
|
+
params_obj = subject.params_ordered
|
261
|
+
|
262
|
+
expect(params_obj[0].name).to eq(:oauth)
|
263
|
+
expect(params_obj[1].name).to eq(:common_param)
|
264
|
+
expect(params_obj[2].name).to eq(:pet_id)
|
265
|
+
end
|
266
|
+
|
267
|
+
it "returns code 200 with 'pet_id', pet_name' and 'animal_type'" do
|
268
|
+
returns_obj = subject.returns.detect{|e| e.code == 200 }
|
269
|
+
|
270
|
+
puts returns_obj.to_json
|
271
|
+
expect(returns_obj.code).to eq(200)
|
272
|
+
expect(returns_obj.is_array?).to eq(false)
|
273
|
+
|
274
|
+
# note that the response is expected NOT to return the parameters marked ':only_in => :request'
|
275
|
+
expect(returns_obj).to match_field_structure([:pet_id, :pet_name, :animal_type])
|
276
|
+
end
|
277
|
+
|
278
|
+
it 'has the response described in the swagger' do
|
279
|
+
response = swagger_response_for('/pets/pet_by_id')
|
280
|
+
expect(response[:description]).to eq("OK")
|
281
|
+
|
282
|
+
schema = response[:schema]
|
283
|
+
expect(schema).to have_field(:pet_id, 'number', {:description => 'id of pet'})
|
284
|
+
expect(schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
|
285
|
+
expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
|
286
|
+
expect(schema).not_to have_field(:partial_match_allowed, 'boolean', {:required => false})
|
287
|
+
end
|
288
|
+
|
289
|
+
it "creates a swagger definition with all input parameters" do
|
290
|
+
# a parameter defined for this method
|
291
|
+
expect(swagger_param_by_name(:pet_id, '/pets/pet_by_id')[:type]).to eq('number')
|
292
|
+
|
293
|
+
# a parameter defined for the resource
|
294
|
+
expect(swagger_param_by_name(:common_param, '/pets/pet_by_id')[:type]).to eq('number')
|
295
|
+
|
296
|
+
# a parameter defined in the controller's superclass
|
297
|
+
expect(swagger_param_by_name(:oauth, '/pets/pet_by_id')[:type]).to eq('string')
|
298
|
+
end
|
299
|
+
|
300
|
+
end
|
301
|
+
|
302
|
+
describe "PetsController#get_vote_by_owner_name" do
|
303
|
+
subject do
|
304
|
+
desc._methods[:get_vote_by_owner_name]
|
305
|
+
end
|
306
|
+
|
307
|
+
it "returns code 200 with 'owner_name' and 'vote'" do
|
308
|
+
returns_obj = subject.returns.detect{|e| e.code == 200 }
|
309
|
+
|
310
|
+
puts returns_obj.to_json
|
311
|
+
expect(returns_obj.code).to eq(200)
|
312
|
+
expect(returns_obj.is_array?).to eq(false)
|
313
|
+
|
314
|
+
expect(returns_obj).to match_field_structure([:owner_name, :vote])
|
315
|
+
end
|
316
|
+
|
317
|
+
it 'has the response described in the swagger' do
|
318
|
+
response = swagger_response_for('/pets/by_owner_name/did_vote')
|
319
|
+
expect(response[:description]).to eq("OK")
|
320
|
+
|
321
|
+
schema = response[:schema]
|
322
|
+
expect(schema).to have_field(:owner_name, 'string', {:required => false}) # optional because defined using 'param', not 'property'
|
323
|
+
expect(schema).to have_field(:vote, 'boolean')
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
describe "PetsController#show_extra_info" do
|
328
|
+
subject do
|
329
|
+
desc._methods[:show_extra_info]
|
330
|
+
end
|
331
|
+
|
332
|
+
it "returns code 201 with 'pet_name' and 'animal_type'" do
|
333
|
+
returns_obj = subject.returns.detect{|e| e.code == 201 }
|
334
|
+
|
335
|
+
puts returns_obj.to_json
|
336
|
+
expect(returns_obj.code).to eq(201)
|
337
|
+
expect(returns_obj.is_array?).to eq(false)
|
338
|
+
|
339
|
+
expect(returns_obj).to match_field_structure([:pet_name, :animal_type])
|
340
|
+
end
|
341
|
+
|
342
|
+
it 'has the 201 response described in the swagger' do
|
343
|
+
response = swagger_response_for('/pets/{id}/extra_info', 201)
|
344
|
+
expect(response[:description]).to eq("Found a pet")
|
345
|
+
|
346
|
+
schema = response[:schema]
|
347
|
+
expect(schema).to have_field(:pet_name, 'string', {:required => false})
|
348
|
+
expect(schema).to have_field(:animal_type, 'string')
|
349
|
+
end
|
350
|
+
|
351
|
+
it "returns code 202 with spread out 'pet' and encapsulated 'pet_measurements'" do
|
352
|
+
returns_obj = subject.returns.detect{|e| e.code == 202 }
|
353
|
+
|
354
|
+
puts returns_obj.to_json
|
355
|
+
expect(returns_obj.code).to eq(202)
|
356
|
+
expect(returns_obj.is_array?).to eq(false)
|
357
|
+
|
358
|
+
expect(returns_obj).to match_field_structure([:pet_name,
|
359
|
+
:animal_type,
|
360
|
+
{:pet_measurements => [:weight, :height, :num_legs]}
|
361
|
+
])
|
362
|
+
end
|
363
|
+
|
364
|
+
it 'has the 202 response described in the swagger' do
|
365
|
+
response = swagger_response_for('/pets/{id}/extra_info', 202)
|
366
|
+
expect(response[:description]).to eq('Accepted')
|
367
|
+
|
368
|
+
schema = response[:schema]
|
369
|
+
expect(schema).to have_field(:pet_name, 'string', {:required => false})
|
370
|
+
expect(schema).to have_field(:animal_type, 'string')
|
371
|
+
expect(schema).to have_field(:pet_measurements, 'object')
|
372
|
+
|
373
|
+
pm_schema = schema[:properties][:pet_measurements]
|
374
|
+
expect(pm_schema).to have_field(:weight, 'number', {:description => "Weight in pounds"})
|
375
|
+
expect(pm_schema).to have_field(:height, 'number', {:description => "Height in inches"})
|
376
|
+
expect(pm_schema).to have_field(:num_legs, 'number', {:description => "Number of legs", :required => false})
|
377
|
+
end
|
378
|
+
|
379
|
+
it "returns code 203 with spread out 'pet', encapsulated 'pet_measurements' and encapsulated 'pet_history'" do
|
380
|
+
returns_obj = subject.returns.detect{|e| e.code == 203 }
|
381
|
+
|
382
|
+
puts returns_obj.to_json
|
383
|
+
expect(returns_obj.code).to eq(203)
|
384
|
+
expect(returns_obj.is_array?).to eq(false)
|
385
|
+
|
386
|
+
expect(returns_obj).to match_field_structure([:pet_name,
|
387
|
+
:animal_type,
|
388
|
+
{:pet_measurements => [:weight, :height,:num_legs]},
|
389
|
+
{:pet_history => [:did_visit_vet, :avg_meals_per_day]},
|
390
|
+
{:additional_histories => [:did_visit_vet, :avg_meals_per_day]}
|
391
|
+
])
|
392
|
+
end
|
393
|
+
|
394
|
+
it 'has the 203 response described in the swagger' do
|
395
|
+
response = swagger_response_for('/pets/{id}/extra_info', 203)
|
396
|
+
expect(response[:description]).to eq('Non-Authoritative Information')
|
397
|
+
|
398
|
+
schema = response[:schema]
|
399
|
+
expect(schema).to have_field(:pet_name, 'string', {:required => false})
|
400
|
+
expect(schema).to have_field(:animal_type, 'string')
|
401
|
+
expect(schema).to have_field(:pet_measurements, 'object')
|
402
|
+
expect(schema).to have_field(:pet_history, 'object')
|
403
|
+
expect(schema).to have_field(:additional_histories, 'array')
|
404
|
+
|
405
|
+
pm_schema = schema[:properties][:pet_measurements]
|
406
|
+
expect(pm_schema).to have_field(:weight, 'number', {:description => "Weight in pounds"})
|
407
|
+
expect(pm_schema).to have_field(:height, 'number', {:description => "Height in inches"})
|
408
|
+
expect(pm_schema).to have_field(:num_legs, 'number', {:description => "Number of legs", :required => false})
|
409
|
+
|
410
|
+
ph_schema = schema[:properties][:pet_history]
|
411
|
+
expect(ph_schema).to have_field(:did_visit_vet, 'boolean')
|
412
|
+
expect(ph_schema).to have_field(:avg_meals_per_day, 'number')
|
413
|
+
|
414
|
+
pa_schema = schema[:properties][:additional_histories]
|
415
|
+
expect(pa_schema[:type]).to eq('array')
|
416
|
+
pai_schema = schema[:properties][:additional_histories][:items]
|
417
|
+
expect(pai_schema).to have_field(:did_visit_vet, 'boolean')
|
418
|
+
expect(pai_schema).to have_field(:avg_meals_per_day, 'number')
|
419
|
+
end
|
420
|
+
|
421
|
+
it "returns code 204 with array of integer" do
|
422
|
+
returns_obj = subject.returns.detect{|e| e.code == 204 }
|
423
|
+
|
424
|
+
puts returns_obj.to_json
|
425
|
+
expect(returns_obj.code).to eq(204)
|
426
|
+
expect(returns_obj.is_array?).to eq(false)
|
427
|
+
|
428
|
+
expect(returns_obj).to match_field_structure([:int_array, :enum_array])
|
429
|
+
end
|
430
|
+
|
431
|
+
it 'has the 204 response described in the swagger' do
|
432
|
+
response = swagger_response_for('/pets/{id}/extra_info', 204)
|
433
|
+
|
434
|
+
schema = response[:schema]
|
435
|
+
expect(schema).to have_field(:int_array, 'array', {items: {type: 'number'}})
|
436
|
+
expect(schema).to have_field(:enum_array, 'array', {items: {type: 'string', enum: %w[v1 v2 v3]}})
|
437
|
+
end
|
438
|
+
|
439
|
+
|
440
|
+
it "returns code matching :unprocessable_entity (422) with spread out 'pet' and 'num_fleas'" do
|
441
|
+
returns_obj = subject.returns.detect{|e| e.code == 422 }
|
442
|
+
|
443
|
+
puts returns_obj.to_json
|
444
|
+
expect(returns_obj.code).to eq(422)
|
445
|
+
|
446
|
+
expect(returns_obj).to match_field_structure([:pet_name,
|
447
|
+
:animal_type,
|
448
|
+
:num_fleas
|
449
|
+
])
|
450
|
+
end
|
451
|
+
|
452
|
+
it 'has the 422 response described in the swagger' do
|
453
|
+
response = swagger_response_for('/pets/{id}/extra_info', 422)
|
454
|
+
expect(response[:description]).to eq('Fleas were discovered on the pet')
|
455
|
+
|
456
|
+
schema = response[:schema]
|
457
|
+
expect(schema).to have_field(:pet_name, 'string', {:required => false})
|
458
|
+
expect(schema).to have_field(:animal_type, 'string')
|
459
|
+
expect(schema).to have_field(:num_fleas, 'number')
|
460
|
+
end
|
461
|
+
|
462
|
+
end
|
463
|
+
|
464
|
+
end
|
465
|
+
|
466
|
+
#==============================================================================
|
467
|
+
# TaggedDogsController is a demonstration of how tags may be defined in a simple
|
468
|
+
# controller class without defining either the controller resource-description
|
469
|
+
# block or the controller's superclass's resource-description block.
|
470
|
+
#==============================================================================
|
471
|
+
|
472
|
+
describe TaggedDogsController do
|
473
|
+
describe "TaggedDogsController#show_as_properties" do
|
474
|
+
subject do
|
475
|
+
desc._methods[:show_as_properties]
|
476
|
+
end
|
477
|
+
|
478
|
+
it "returns tags with 'Dogs', and 'Wolves'" do
|
479
|
+
returns_obj = subject.tag_list
|
480
|
+
puts returns_obj.inspect
|
481
|
+
|
482
|
+
expect(returns_obj.tags).to eq(%w[Dogs Wolves])
|
483
|
+
end
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
#==============================================================================
|
488
|
+
# TaggedCatsController is a demonstration of how tags may be defined in the
|
489
|
+
# controller's resource description so that they may be automatically prefixed
|
490
|
+
# to a particular operation's tags.
|
491
|
+
#==============================================================================
|
492
|
+
|
493
|
+
describe TaggedCatsController do
|
494
|
+
describe "TaggedCatsController#show_as_properties" do
|
495
|
+
subject do
|
496
|
+
desc._methods[:show_as_properties]
|
497
|
+
end
|
498
|
+
|
499
|
+
it "returns tags with 'Dogs', 'Pets', and 'Animals'" do
|
500
|
+
returns_obj = subject.tag_list
|
501
|
+
puts returns_obj.inspect
|
502
|
+
|
503
|
+
expect(returns_obj.tags).to eq(%w[Dogs Pets Animals])
|
504
|
+
end
|
505
|
+
end
|
506
|
+
|
507
|
+
describe "TaggedCatsController#show_as_same_properties" do
|
508
|
+
subject do
|
509
|
+
desc._methods[:show_as_same_properties]
|
510
|
+
end
|
511
|
+
|
512
|
+
it "returns tags with 'Dogs', 'Pets', 'Puma', and 'Animals'" do
|
513
|
+
returns_obj = subject.tag_list
|
514
|
+
puts returns_obj.inspect
|
515
|
+
|
516
|
+
expect(returns_obj.tags).to eq(%w[Dogs Pets Puma Animals])
|
517
|
+
end
|
518
|
+
end
|
519
|
+
end
|
520
|
+
|
521
|
+
#==============================================================================
|
522
|
+
# PetsUsingSelfDescribingClassesController is a demonstration of how
|
523
|
+
# responses can be described using manual generation of a property description
|
524
|
+
# array
|
525
|
+
#==============================================================================
|
526
|
+
|
527
|
+
|
528
|
+
describe PetsUsingSelfDescribingClassesController do
|
529
|
+
|
530
|
+
describe "PetsController#pets_described_as_class" do
|
531
|
+
subject do
|
532
|
+
desc._methods[:pets_described_as_class]
|
533
|
+
end
|
534
|
+
|
535
|
+
it "returns code 200 with array of entries of the format {'pet_name', 'animal_type'}" do
|
536
|
+
returns_obj = subject.returns.detect{|e| e.code == 200 }
|
537
|
+
|
538
|
+
puts returns_obj.to_json
|
539
|
+
expect(returns_obj.code).to eq(200)
|
540
|
+
expect(returns_obj.is_array?).to eq(true)
|
541
|
+
|
542
|
+
expect(returns_obj).to match_field_structure([:pet_name, :animal_type])
|
543
|
+
end
|
544
|
+
|
545
|
+
it 'has the response described in the swagger' do
|
546
|
+
response = swagger_response_for('/pets_described_as_class')
|
547
|
+
expect(response[:description]).to eq("list of pets")
|
548
|
+
|
549
|
+
schema = response[:schema]
|
550
|
+
expect(schema[:type]).to eq("array")
|
551
|
+
|
552
|
+
a_schema = schema[:items]
|
553
|
+
expect(a_schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
|
554
|
+
expect(a_schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
|
555
|
+
end
|
556
|
+
end
|
557
|
+
|
558
|
+
|
559
|
+
describe "PetsController#pets_with_measurements_described_as_class" do
|
560
|
+
subject do
|
561
|
+
desc._methods[:pets_with_measurements_described_as_class]
|
562
|
+
end
|
563
|
+
|
564
|
+
it "returns code 200 with spread out 'pet' and encapsulated 'pet_measurements'" do
|
565
|
+
returns_obj = subject.returns.detect{|e| e.code == 200 }
|
566
|
+
|
567
|
+
puts returns_obj.to_json
|
568
|
+
expect(returns_obj.code).to eq(200)
|
569
|
+
expect(returns_obj.is_array?).to eq(false)
|
570
|
+
|
571
|
+
expect(returns_obj).to match_field_structure([:pet_name,
|
572
|
+
:animal_type,
|
573
|
+
{:pet_measurements => [:weight, :height, :num_legs]}
|
574
|
+
])
|
575
|
+
end
|
576
|
+
|
577
|
+
it 'has the 200 response described in the swagger' do
|
578
|
+
response = swagger_response_for('/pets_with_measurements_described_as_class/{id}', 200)
|
579
|
+
expect(response[:description]).to eq('measurements of the pet')
|
580
|
+
|
581
|
+
schema = response[:schema]
|
582
|
+
expect(schema).to have_field(:pet_name, 'string', {:required => false})
|
583
|
+
expect(schema).to have_field(:animal_type, 'string')
|
584
|
+
expect(schema).to have_field(:pet_measurements, 'object')
|
585
|
+
|
586
|
+
pm_schema = schema[:properties][:pet_measurements]
|
587
|
+
expect(pm_schema).to have_field(:weight, 'number', {:description => "Weight in pounds"})
|
588
|
+
expect(pm_schema).to have_field(:height, 'number', {:description => "Height in inches"})
|
589
|
+
expect(pm_schema).to have_field(:num_legs, 'number', {:description => "Number of legs", :required => false})
|
590
|
+
end
|
591
|
+
end
|
592
|
+
|
593
|
+
describe "PetsController#pets_with_many_measurements_as_class" do
|
594
|
+
subject do
|
595
|
+
desc._methods[:pets_with_many_measurements_as_class]
|
596
|
+
end
|
597
|
+
|
598
|
+
it "returns code 200 with pet_name (string) and many_pet_measurements (array of objects)" do
|
599
|
+
returns_obj = subject.returns.detect{|e| e.code == 200 }
|
600
|
+
|
601
|
+
puts returns_obj.to_json
|
602
|
+
expect(returns_obj.code).to eq(200)
|
603
|
+
expect(returns_obj.is_array?).to eq(false)
|
604
|
+
|
605
|
+
expect(returns_obj).to match_field_structure([:pet_name,
|
606
|
+
{:many_pet_measurements => [:weight, :height]}
|
607
|
+
])
|
608
|
+
end
|
609
|
+
|
610
|
+
|
611
|
+
it 'has the 200 response described in the swagger' do
|
612
|
+
response = swagger_response_for('/pets_with_many_measurements_as_class/{id}', 200)
|
613
|
+
expect(response[:description]).to eq('measurements of the pet')
|
614
|
+
|
615
|
+
schema = response[:schema]
|
616
|
+
expect(schema).to have_field(:pet_name, 'string', {:required => false})
|
617
|
+
expect(schema).to have_field(:many_pet_measurements, 'array')
|
618
|
+
|
619
|
+
pm_schema = schema[:properties][:many_pet_measurements][:items]
|
620
|
+
expect(pm_schema).to have_field(:weight, 'number', {:description => "Weight in pounds"})
|
621
|
+
expect(pm_schema).to have_field(:height, 'number', {:description => "Height in inches"})
|
622
|
+
end
|
623
|
+
end
|
624
|
+
|
625
|
+
end
|
626
|
+
|
627
|
+
|
628
|
+
#=========================================================
|
629
|
+
# PetsUsingAutoViewsController is a demonstration of how
|
630
|
+
# responses can be described using logic
|
631
|
+
#=========================================================
|
632
|
+
|
633
|
+
describe PetsUsingAutoViewsController do
|
634
|
+
|
635
|
+
describe "PetsController#pet_described_using_automated_view" do
|
636
|
+
subject do
|
637
|
+
desc._methods[:pet_described_using_automated_view]
|
638
|
+
end
|
639
|
+
|
640
|
+
it "returns code 200 with array of entries of the format {'pet_name', 'animal_type'}" do
|
641
|
+
returns_obj = subject.returns.detect{|e| e.code == 200 }
|
642
|
+
|
643
|
+
expect(returns_obj.code).to eq(200)
|
644
|
+
expect(returns_obj.is_array?).to eq(false)
|
645
|
+
|
646
|
+
expect(returns_obj).to match_field_structure([:pet_name, :animal_type, :age])
|
647
|
+
end
|
648
|
+
|
649
|
+
it 'has the response described in the swagger' do
|
650
|
+
response = swagger_response_for('/pet_described_using_automated_view/{id}')
|
651
|
+
expect(response[:description]).to eq("like Pet, but different")
|
652
|
+
|
653
|
+
schema = response[:schema]
|
654
|
+
expect(schema[:type]).to eq("object")
|
655
|
+
|
656
|
+
expect(schema).to have_field(:pet_name, 'string', {:required => true})
|
657
|
+
expect(schema).to have_field(:animal_type, 'string', {:required => true})
|
658
|
+
expect(schema).to have_field(:age, 'number', {:required => true})
|
659
|
+
end
|
660
|
+
end
|
661
|
+
end
|
662
|
+
|
663
|
+
|
664
|
+
end
|