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,119 @@
|
|
1
|
+
class Apipie::Generator::Swagger::ParamDescription::Composite
|
2
|
+
# @param [Array<Apipie::ParamDescription>] param_descriptions
|
3
|
+
# @param [Apipie::Generator::Swagger::Context] context
|
4
|
+
def initialize(param_descriptions, context)
|
5
|
+
@param_descriptions = param_descriptions
|
6
|
+
@context = context
|
7
|
+
@schema = {
|
8
|
+
type: 'object',
|
9
|
+
properties: {}
|
10
|
+
}
|
11
|
+
@required_params = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_swagger
|
15
|
+
return if @param_descriptions.blank?
|
16
|
+
|
17
|
+
@param_descriptions.each do |param_description|
|
18
|
+
validate(param_description)
|
19
|
+
|
20
|
+
if param_description.required
|
21
|
+
@required_params.push(param_description.name.to_sym)
|
22
|
+
end
|
23
|
+
|
24
|
+
param_type = Apipie::Generator::Swagger::TypeExtractor.
|
25
|
+
new(param_description.validator).
|
26
|
+
extract
|
27
|
+
|
28
|
+
has_nested_params = param_type == 'object' &&
|
29
|
+
param_description.validator.params_ordered.present?
|
30
|
+
|
31
|
+
if has_nested_params
|
32
|
+
schema = Apipie::Generator::Swagger::ParamDescription::Composite.new(
|
33
|
+
param_description.validator.params_ordered,
|
34
|
+
Apipie::Generator::Swagger::Context.new(
|
35
|
+
allow_null: @context.allow_null?,
|
36
|
+
http_method: @context.http_method,
|
37
|
+
controller_method: @context.controller_method
|
38
|
+
)
|
39
|
+
).to_swagger
|
40
|
+
|
41
|
+
return if schema.blank?
|
42
|
+
|
43
|
+
if param_description.additional_properties
|
44
|
+
schema[:additionalProperties] = true
|
45
|
+
end
|
46
|
+
|
47
|
+
if param_description.is_array?
|
48
|
+
schema = for_array(schema)
|
49
|
+
end
|
50
|
+
|
51
|
+
if @context.allow_null?
|
52
|
+
schema = with_null(schema)
|
53
|
+
end
|
54
|
+
|
55
|
+
if schema.present?
|
56
|
+
@schema[:properties][param_description.name.to_sym] = schema
|
57
|
+
end
|
58
|
+
else
|
59
|
+
param_entry = Apipie::Generator::Swagger::ParamDescription::Builder.
|
60
|
+
new(
|
61
|
+
param_description,
|
62
|
+
in_schema: @context.in_schema?,
|
63
|
+
controller_method: @context.controller_method
|
64
|
+
).
|
65
|
+
with_description(language: @context.language).
|
66
|
+
with_type(with_null: @context.allow_null?).
|
67
|
+
with_in(
|
68
|
+
default_in_value: @context.default_in_value,
|
69
|
+
http_method: @context.http_method
|
70
|
+
).
|
71
|
+
to_swagger
|
72
|
+
|
73
|
+
@schema[:properties][param_description.name.to_sym] = param_entry
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
if !Apipie.configuration.generator.swagger.allow_additional_properties_in_response
|
78
|
+
@schema[:additionalProperties] = false
|
79
|
+
end
|
80
|
+
|
81
|
+
if @required_params.length > 0
|
82
|
+
@schema[:required] = @required_params
|
83
|
+
end
|
84
|
+
|
85
|
+
@schema
|
86
|
+
end
|
87
|
+
|
88
|
+
# @param [Symbol, String] param_type
|
89
|
+
#
|
90
|
+
# @return [Apipie::Generator::Swagger::ParamDescription::ReferencedComposite]
|
91
|
+
def referenced(param_type)
|
92
|
+
Apipie::Generator::Swagger::ParamDescription::ReferencedComposite.
|
93
|
+
new(self, param_type)
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def for_array(schema)
|
99
|
+
{
|
100
|
+
type: 'array',
|
101
|
+
items: schema
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
def with_null(schema)
|
106
|
+
# Ideally we would write schema[:type] = ["object", "null"]
|
107
|
+
# but due to a bug in the json-schema gem, we need to use anyOf
|
108
|
+
# see https://github.com/ruby-json-schema/json-schema/issues/404
|
109
|
+
{
|
110
|
+
anyOf: [ schema, { type: 'null' } ]
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
def validate(param_description)
|
115
|
+
if !param_description.respond_to?(:required)
|
116
|
+
raise "Unexpected param_desc format"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Apipie::Generator::Swagger::ParamDescription::Description
|
2
|
+
def initialize(param_description, language:)
|
3
|
+
@param_description = param_description
|
4
|
+
@language = language
|
5
|
+
end
|
6
|
+
|
7
|
+
# @return [Hash]
|
8
|
+
def to_hash
|
9
|
+
description = @param_description.options[:desc]
|
10
|
+
|
11
|
+
return {} if description.blank?
|
12
|
+
|
13
|
+
{ description: Apipie.app.translate(description, @language) }
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Apipie::Generator::Swagger::ParamDescription::In
|
2
|
+
IN_KEYWORD_DEFAULT_VALUES = {
|
3
|
+
form_data: 'formData',
|
4
|
+
query: 'query'
|
5
|
+
}.freeze
|
6
|
+
|
7
|
+
def initialize(param_description, in_schema:, default_in_value:, http_method:)
|
8
|
+
@param_description = param_description
|
9
|
+
@in_schema = in_schema
|
10
|
+
@default_in_value = default_in_value
|
11
|
+
@http_method = http_method
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Hash]
|
15
|
+
def to_hash
|
16
|
+
# The "name" and "in" keys can only be set on root parameters (non-nested)
|
17
|
+
return {} if @in_schema
|
18
|
+
|
19
|
+
{ in: in_value }
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def in_value
|
25
|
+
return @default_in_value if @default_in_value.present?
|
26
|
+
|
27
|
+
if body_allowed_for_current_method?
|
28
|
+
IN_KEYWORD_DEFAULT_VALUES[:form_data]
|
29
|
+
else
|
30
|
+
IN_KEYWORD_DEFAULT_VALUES[:query]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def body_allowed_for_current_method?
|
35
|
+
%w[get head].exclude?(@http_method)
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Apipie::Generator::Swagger::ParamDescription::Name
|
2
|
+
def initialize(param_description, prefixed_by: nil)
|
3
|
+
@param_description = param_description
|
4
|
+
@prefixed_by = prefixed_by
|
5
|
+
end
|
6
|
+
|
7
|
+
# @return [Hash]
|
8
|
+
def to_hash
|
9
|
+
name =
|
10
|
+
if @prefixed_by.present?
|
11
|
+
"#{@prefixed_by}[#{@param_description.name}]"
|
12
|
+
else
|
13
|
+
@param_description.name
|
14
|
+
end
|
15
|
+
|
16
|
+
{ name: name }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class Apipie::Generator::Swagger::ParamDescription::PathParamsComposite
|
2
|
+
# @param [Array<Apipie::ParamDescription>] param_descriptions
|
3
|
+
# @param [Apipie::Generator::Swagger::Context] context
|
4
|
+
def initialize(param_descriptions, context)
|
5
|
+
@param_descriptions = param_descriptions
|
6
|
+
@context = context
|
7
|
+
@result = []
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return [Array]
|
11
|
+
def to_swagger
|
12
|
+
@param_descriptions.each do |desc|
|
13
|
+
context = @context.dup
|
14
|
+
|
15
|
+
type = Apipie::Generator::Swagger::TypeExtractor.new(desc.validator).extract
|
16
|
+
|
17
|
+
if type == 'object' && desc.validator.params_ordered.blank?
|
18
|
+
warn_param_ignored_in_form_data(desc.name)
|
19
|
+
next
|
20
|
+
end
|
21
|
+
|
22
|
+
has_nested_params = type == 'object' &&
|
23
|
+
desc.validator.params_ordered.present?
|
24
|
+
|
25
|
+
if has_nested_params
|
26
|
+
context.add_to_prefix!(desc.name)
|
27
|
+
|
28
|
+
out = Apipie::Generator::Swagger::ParamDescription::PathParamsComposite
|
29
|
+
.new(desc.validator.params_ordered, context)
|
30
|
+
.to_swagger
|
31
|
+
|
32
|
+
@result.concat(out)
|
33
|
+
else
|
34
|
+
param_entry =
|
35
|
+
Apipie::Generator::Swagger::ParamDescription::Builder
|
36
|
+
.new(desc, in_schema: false, controller_method: context.controller_method)
|
37
|
+
.with_description(language: context.language)
|
38
|
+
.with_name(prefix: context.prefix)
|
39
|
+
.with_type(with_null: context.allow_null?)
|
40
|
+
.with_in(
|
41
|
+
http_method: context.http_method,
|
42
|
+
default_in_value: context.default_in_value
|
43
|
+
).to_swagger
|
44
|
+
|
45
|
+
@result << param_entry
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
@result.sort_by { |p| p[:required] ? 0 : 1 }
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def warn_param_ignored_in_form_data(name)
|
55
|
+
Apipie::Generator::Swagger::Warning.for_code(
|
56
|
+
Apipie::Generator::Swagger::Warning::PARAM_IGNORED_IN_FORM_DATA_CODE,
|
57
|
+
@context.controller_method.ruby_name,
|
58
|
+
{ parameter: name }
|
59
|
+
).warn_through_writer
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# A Composite that keeps track when a param description has been added to references
|
2
|
+
# and returns the reference instead of the complete object
|
3
|
+
class Apipie::Generator::Swagger::ParamDescription::ReferencedComposite
|
4
|
+
# @param [Apipie::Generator::Swagger::ParamDescription::Composite] composite
|
5
|
+
# @param [Symbol, String] param_type
|
6
|
+
def initialize(composite, param_type)
|
7
|
+
@composite = composite
|
8
|
+
@param_type = param_type.to_sym
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_swagger
|
12
|
+
return ref_to(:name) if added?(:name)
|
13
|
+
|
14
|
+
schema_obj = @composite.to_swagger
|
15
|
+
|
16
|
+
return nil if schema_obj.nil?
|
17
|
+
|
18
|
+
add(schema_obj)
|
19
|
+
|
20
|
+
{ '$ref' => ref_to(@param_type) }
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def ref_to(name)
|
26
|
+
"#/definitions/#{name}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def add(schema)
|
30
|
+
Apipie::Generator::Swagger::ReferencedDefinitions.instance.add!(@param_type, schema)
|
31
|
+
end
|
32
|
+
|
33
|
+
def added?(name)
|
34
|
+
Apipie::Generator::Swagger::ReferencedDefinitions.instance.added?(name)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
class Apipie::Generator::Swagger::ParamDescription::Type
|
2
|
+
def initialize(param_description, with_null:, controller_method:)
|
3
|
+
@param_description = param_description
|
4
|
+
@with_null = with_null
|
5
|
+
@controller_method = controller_method
|
6
|
+
end
|
7
|
+
|
8
|
+
# @return [Hash]
|
9
|
+
def to_hash
|
10
|
+
type_definition = {}
|
11
|
+
|
12
|
+
case type.to_s
|
13
|
+
when 'array'
|
14
|
+
type_definition.merge!(for_array_type)
|
15
|
+
when 'enum'
|
16
|
+
type_definition.merge!(for_enum_type)
|
17
|
+
when 'object'
|
18
|
+
# We only get here if there is no specification
|
19
|
+
# of properties for this object.
|
20
|
+
type_definition.merge!(for_object_type)
|
21
|
+
warn_hash_without_internal_typespec
|
22
|
+
else
|
23
|
+
type_definition.merge!({ type: type.to_s })
|
24
|
+
end
|
25
|
+
|
26
|
+
if @param_description.is_array?
|
27
|
+
type_definition = {
|
28
|
+
items: type_definition,
|
29
|
+
type: 'array'
|
30
|
+
}
|
31
|
+
|
32
|
+
if @with_null
|
33
|
+
type_definition[:type] = [type_definition[:type], 'null']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if @with_null
|
38
|
+
type_definition[:type] = [type_definition[:type], 'null']
|
39
|
+
end
|
40
|
+
|
41
|
+
type_definition
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def params_in_body_use_reference?
|
47
|
+
Apipie.configuration.generator.swagger.json_input_uses_refs
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Apipie::Generator::Swagger::Type, String]
|
51
|
+
def type
|
52
|
+
@_type ||= Apipie::Generator::Swagger::TypeExtractor.
|
53
|
+
new(validator).
|
54
|
+
extract
|
55
|
+
end
|
56
|
+
|
57
|
+
def for_array_type
|
58
|
+
validator_opts = validator.param_description.options
|
59
|
+
items_type = (validator_opts[:of] || validator_opts[:array_of]).to_s
|
60
|
+
|
61
|
+
if items_type == 'Hash' && params_in_body_use_reference?
|
62
|
+
reference_name = Apipie::Generator::Swagger::OperationId.
|
63
|
+
from(@param_description.method_description, param: @param_description.name).
|
64
|
+
to_s
|
65
|
+
|
66
|
+
items = {
|
67
|
+
'$ref' => reference_name
|
68
|
+
}
|
69
|
+
else
|
70
|
+
items = { type: array_items_type(items_type).to_s }
|
71
|
+
end
|
72
|
+
|
73
|
+
enum = @param_description.options[:in]
|
74
|
+
|
75
|
+
items[:enum] = enum if enum.present?
|
76
|
+
|
77
|
+
{
|
78
|
+
type: 'array',
|
79
|
+
items: items
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
# @param [String] items_type
|
84
|
+
#
|
85
|
+
# @return [Apipie::Generator::Swagger::Type]
|
86
|
+
def array_items_type(items_type)
|
87
|
+
type = Apipie::Generator::Swagger::TypeExtractor::TYPES[items_type.downcase.to_sym]
|
88
|
+
|
89
|
+
if type == 'object' || type.blank?
|
90
|
+
Apipie::Generator::Swagger::TypeExtractor::TYPES[:string]
|
91
|
+
else
|
92
|
+
type
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def for_enum_type
|
97
|
+
{
|
98
|
+
type: 'string',
|
99
|
+
enum: @param_description.validator.values
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
def for_object_type
|
104
|
+
{
|
105
|
+
type: 'object',
|
106
|
+
additionalProperties: true
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
def validator
|
111
|
+
@_validator ||= @param_description.validator
|
112
|
+
end
|
113
|
+
|
114
|
+
def warn_hash_without_internal_typespec
|
115
|
+
method_id =
|
116
|
+
if @param_description.is_a?(Apipie::ResponseDescriptionAdapter::PropDesc)
|
117
|
+
if @controller_method.present?
|
118
|
+
@controller_method.method_name
|
119
|
+
else
|
120
|
+
Apipie::Generator::Swagger::MethodDescription::Decorator.new(nil).ruby_name
|
121
|
+
end
|
122
|
+
else
|
123
|
+
Apipie::Generator::Swagger::MethodDescription::Decorator.new(@param_description.method_description).ruby_name
|
124
|
+
end
|
125
|
+
|
126
|
+
Apipie::Generator::Swagger::Warning.for_code(
|
127
|
+
Apipie::Generator::Swagger::Warning::HASH_WITHOUT_INTERNAL_TYPESPEC_CODE,
|
128
|
+
method_id,
|
129
|
+
{ parameter: @param_description.name }
|
130
|
+
).warn_through_writer
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Apipie::Generator::Swagger::ParamDescription
|
2
|
+
# @param [Apipie::MethodDescription] method_description
|
3
|
+
# @param [String] name
|
4
|
+
#
|
5
|
+
# @return [Apipie::ParamDescription]
|
6
|
+
def self.create_for_missing_param(method_description, name)
|
7
|
+
Apipie::ParamDescription.new(
|
8
|
+
method_description,
|
9
|
+
name,
|
10
|
+
Numeric,
|
11
|
+
{
|
12
|
+
in: "path",
|
13
|
+
required: true,
|
14
|
+
added_from_path: true,
|
15
|
+
}
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Apipie::Generator::Swagger::PathDecorator < SimpleDelegator
|
2
|
+
def param_names
|
3
|
+
@param_names ||= scan(/:(\w+)/).map { |ar| ar[0].to_sym }
|
4
|
+
end
|
5
|
+
|
6
|
+
# @param [Symbol] param_name
|
7
|
+
def param?(param_name)
|
8
|
+
param_names.include?(param_name)
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param [String] controller_method
|
12
|
+
#
|
13
|
+
# @return [Apipie::Generator::Swagger::PathDecorator]
|
14
|
+
def swagger_path(controller_method = nil)
|
15
|
+
current_path = gsub(/:(\w+)/, '{\1}').gsub(%r{/$}, '')
|
16
|
+
|
17
|
+
unless current_path.starts_with?('/')
|
18
|
+
warn_for_missing_slash(controller_method) if controller_method.present?
|
19
|
+
|
20
|
+
current_path = "/#{current_path}"
|
21
|
+
end
|
22
|
+
|
23
|
+
current_path
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# @param [String] controller_method
|
29
|
+
def warn_for_missing_slash(controller_method)
|
30
|
+
Apipie::Generator::Swagger::Warning.for_code(
|
31
|
+
Apipie::Generator::Swagger::Warning::ADDED_MISSING_SLASH_CODE,
|
32
|
+
controller_method,
|
33
|
+
{ path: self }
|
34
|
+
).warn_through_writer
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Apipie::Generator::Swagger::ReferencedDefinitions
|
2
|
+
include Singleton
|
3
|
+
|
4
|
+
attr_reader :definitions
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@definitions = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def add!(param_type, schema)
|
11
|
+
@definitions[param_type] = schema
|
12
|
+
end
|
13
|
+
|
14
|
+
def added?(name)
|
15
|
+
@definitions.key?(name)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Apipie::Generator::Swagger::ResourceDescriptionsCollection
|
2
|
+
# @param [Hash{String->Apipie::ResourceDescription}] resource_descriptions
|
3
|
+
def initialize(resource_descriptions)
|
4
|
+
@resource_descriptions = resource_descriptions
|
5
|
+
end
|
6
|
+
|
7
|
+
# @return [Array<Apipie::ResourceDescription>]
|
8
|
+
def filter(version:, resource_id:, method_name: nil)
|
9
|
+
resources = []
|
10
|
+
|
11
|
+
# If resource_id is blank, take just resources which have some methods because
|
12
|
+
# we dont want to show eg ApplicationController as resource
|
13
|
+
# otherwise, take only the specified resource
|
14
|
+
@resource_descriptions[version].each do |resource_description_id, resource_description|
|
15
|
+
if (resource_id.blank? && resource_description._methods.present?) || resource_description_id == resource_id
|
16
|
+
resources << resource_description
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
if method_name.present?
|
21
|
+
resources = resources.select do |resource_description|
|
22
|
+
resource_description._methods.any? do |method_description_name, _|
|
23
|
+
method_description_name == method_name
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
resources
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class Apipie::Generator::Swagger::ResourceDescriptionComposite
|
2
|
+
# @param [Array<Apipie::ResourceDescription>] resource_descriptions
|
3
|
+
def initialize(resource_descriptions, language:)
|
4
|
+
@resource_descriptions = resource_descriptions
|
5
|
+
@language = language
|
6
|
+
end
|
7
|
+
|
8
|
+
# @return [Hash{Symbol->Array | Hash}]
|
9
|
+
def to_swagger
|
10
|
+
{
|
11
|
+
tags: tags,
|
12
|
+
paths: paths
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Array]
|
17
|
+
def tags
|
18
|
+
results = []
|
19
|
+
|
20
|
+
@resource_descriptions.each do |resource_description|
|
21
|
+
next unless resource_description._full_description
|
22
|
+
|
23
|
+
results << {
|
24
|
+
name: resource_description._id,
|
25
|
+
description: Apipie.app.translate(
|
26
|
+
resource_description._full_description,
|
27
|
+
@language
|
28
|
+
)
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
results
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [Hash]
|
36
|
+
def paths
|
37
|
+
results = {}
|
38
|
+
|
39
|
+
@resource_descriptions.each do |resource_description|
|
40
|
+
resource_description._methods.each_value do |method_description|
|
41
|
+
next unless method_description.show
|
42
|
+
|
43
|
+
result = Apipie::Generator::Swagger::MethodDescription::ApiSchemaService
|
44
|
+
.new(
|
45
|
+
Apipie::Generator::Swagger::MethodDescription::Decorator.new(method_description),
|
46
|
+
language: @language
|
47
|
+
)
|
48
|
+
.call
|
49
|
+
|
50
|
+
results.deep_merge!(result)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
results
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class Apipie::Generator::Swagger::Schema
|
2
|
+
# @param [Array<Apipie::ResourceDescription>] resource_descriptions
|
3
|
+
def initialize(resource_descriptions, version:, language:, clear_warnings:)
|
4
|
+
@resource_descriptions = resource_descriptions
|
5
|
+
@language = language
|
6
|
+
@clear_warnings = clear_warnings
|
7
|
+
@swagger = {
|
8
|
+
swagger: '2.0',
|
9
|
+
info: {
|
10
|
+
title: Apipie.configuration.app_name.to_s,
|
11
|
+
description: "#{Apipie.app_info(version, @language)}#{Apipie.configuration.copyright}",
|
12
|
+
version: version.to_s,
|
13
|
+
'x-copyright': Apipie.configuration.copyright
|
14
|
+
},
|
15
|
+
basePath: Apipie.api_base_url(version),
|
16
|
+
consumes: [],
|
17
|
+
paths: {},
|
18
|
+
definitions: {},
|
19
|
+
schemes: Apipie.configuration.generator.swagger.schemes,
|
20
|
+
tags: [],
|
21
|
+
securityDefinitions: Apipie.configuration.generator.swagger.security_definitions,
|
22
|
+
security: Apipie.configuration.generator.swagger.global_security
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def generate
|
27
|
+
if Apipie.configuration.generator.swagger.api_host.present?
|
28
|
+
@swagger[:host] = Apipie.configuration.generator.swagger.api_host
|
29
|
+
end
|
30
|
+
|
31
|
+
if Apipie.configuration.generator.swagger.content_type_input == :json
|
32
|
+
@swagger[:consumes] = ['application/json']
|
33
|
+
@swagger[:info][:title] += ' (params in:body)'
|
34
|
+
else
|
35
|
+
@swagger[:consumes] = ['application/x-www-form-urlencoded', 'multipart/form-data']
|
36
|
+
@swagger[:info][:title] += ' (params in:formData)'
|
37
|
+
end
|
38
|
+
|
39
|
+
if @clear_warnings
|
40
|
+
Apipie::Generator::Swagger::WarningWriter.instance.clear!
|
41
|
+
end
|
42
|
+
|
43
|
+
@swagger.merge!(tags_and_paths)
|
44
|
+
|
45
|
+
if Apipie.configuration.generator.swagger.generate_x_computed_id_field?
|
46
|
+
@swagger[:info]['x-computed-id'] =
|
47
|
+
Apipie::Generator::Swagger::ComputedInterfaceId.instance.id
|
48
|
+
end
|
49
|
+
|
50
|
+
@swagger[:definitions] =
|
51
|
+
Apipie::Generator::Swagger::ReferencedDefinitions.instance.definitions
|
52
|
+
|
53
|
+
@swagger
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def tags_and_paths
|
59
|
+
Apipie::Generator::Swagger::ResourceDescriptionComposite
|
60
|
+
.new(@resource_descriptions, language: @language)
|
61
|
+
.to_swagger
|
62
|
+
end
|
63
|
+
end
|