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,51 @@
|
|
1
|
+
class Apipie::Generator::Swagger::TypeExtractor
|
2
|
+
TYPES = {
|
3
|
+
numeric: 'number',
|
4
|
+
hash: 'object',
|
5
|
+
array: 'array',
|
6
|
+
enum: 'enum',
|
7
|
+
|
8
|
+
# see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types
|
9
|
+
integer: Apipie::Generator::Swagger::Type.new('integer', 'int32'),
|
10
|
+
long: Apipie::Generator::Swagger::Type.new('integer', 'int64'),
|
11
|
+
number: Apipie::Generator::Swagger::Type.new('number'),
|
12
|
+
float: Apipie::Generator::Swagger::Type.new('number', 'float'),
|
13
|
+
double: Apipie::Generator::Swagger::Type.new('number', 'double'),
|
14
|
+
string: Apipie::Generator::Swagger::Type.new('string'),
|
15
|
+
byte: Apipie::Generator::Swagger::Type.new('string', 'byte'),
|
16
|
+
binary: Apipie::Generator::Swagger::Type.new('string', 'binary'),
|
17
|
+
boolean: Apipie::Generator::Swagger::Type.new('boolean'),
|
18
|
+
date: Apipie::Generator::Swagger::Type.new('string', 'date'),
|
19
|
+
dateTime: Apipie::Generator::Swagger::Type.new('string', 'date-time'),
|
20
|
+
password: Apipie::Generator::Swagger::Type.new('string', 'password')
|
21
|
+
}.freeze
|
22
|
+
|
23
|
+
# @param [Apipie::Validator::BaseValidator, ResponseDescriptionAdapter::PropDesc::Validator, nil] validator
|
24
|
+
def initialize(validator)
|
25
|
+
@validator = validator
|
26
|
+
end
|
27
|
+
|
28
|
+
def extract
|
29
|
+
expected_type =
|
30
|
+
if string?
|
31
|
+
:string
|
32
|
+
elsif enum?
|
33
|
+
:enum
|
34
|
+
else
|
35
|
+
@validator.expected_type.to_sym
|
36
|
+
end
|
37
|
+
|
38
|
+
TYPES[expected_type] || @validator.expected_type
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def string?
|
44
|
+
@validator.blank?
|
45
|
+
end
|
46
|
+
|
47
|
+
def enum?
|
48
|
+
@validator.is_a?(Apipie::Validator::EnumValidator) ||
|
49
|
+
(@validator.respond_to?(:is_enum?) && @validator.is_enum?)
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
class Apipie::Generator::Swagger::Warning
|
2
|
+
MISSING_METHOD_SUMMARY_CODE = 100
|
3
|
+
ADDED_MISSING_SLASH_CODE = 101
|
4
|
+
NO_RETURN_CODES_SPECIFIED_CODE = 102
|
5
|
+
HASH_WITHOUT_INTERNAL_TYPESPEC_CODE = 103
|
6
|
+
OPTIONAL_PARAM_IN_PATH_CODE = 104
|
7
|
+
OPTIONAL_WITHOUT_DEFAULT_VALUE_CODE = 105
|
8
|
+
PARAM_IGNORED_IN_FORM_DATA_CODE = 106
|
9
|
+
PATH_PARAM_NOT_DESCRIBED_CODE = 107
|
10
|
+
|
11
|
+
CODES = {
|
12
|
+
missing_method_summary: MISSING_METHOD_SUMMARY_CODE,
|
13
|
+
added_missing_slash: ADDED_MISSING_SLASH_CODE,
|
14
|
+
no_return_codes_specified: NO_RETURN_CODES_SPECIFIED_CODE,
|
15
|
+
hash_without_internal_typespec: HASH_WITHOUT_INTERNAL_TYPESPEC_CODE,
|
16
|
+
optional_param_in_path: OPTIONAL_PARAM_IN_PATH_CODE,
|
17
|
+
optional_without_default_value: OPTIONAL_WITHOUT_DEFAULT_VALUE_CODE,
|
18
|
+
param_ignored_in_form_data: PARAM_IGNORED_IN_FORM_DATA_CODE,
|
19
|
+
path_param_not_described_code: PATH_PARAM_NOT_DESCRIBED_CODE
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
MESSAGES = {
|
23
|
+
MISSING_METHOD_SUMMARY_CODE => "Missing short description for method",
|
24
|
+
ADDED_MISSING_SLASH_CODE => "Added missing / at beginning of path: %{path}",
|
25
|
+
HASH_WITHOUT_INTERNAL_TYPESPEC_CODE => "The parameter :%{parameter} is a generic Hash without an internal type specification",
|
26
|
+
NO_RETURN_CODES_SPECIFIED_CODE => "No return codes ('errors') specified",
|
27
|
+
OPTIONAL_PARAM_IN_PATH_CODE => "The parameter :%{parameter} is 'in-path'. Ignoring 'not required' in DSL",
|
28
|
+
OPTIONAL_WITHOUT_DEFAULT_VALUE_CODE => "The parameter :%{parameter} is optional but default value is not specified (use :default_value => ...)",
|
29
|
+
PARAM_IGNORED_IN_FORM_DATA_CODE => "Ignoring param :%{parameter} -- cannot include Hash without fields in a formData specification",
|
30
|
+
PATH_PARAM_NOT_DESCRIBED_CODE => "The parameter :%{name} appears in the path %{path} but is not described"
|
31
|
+
}.freeze
|
32
|
+
|
33
|
+
attr_reader :code
|
34
|
+
|
35
|
+
def initialize(code, info_message, method_id)
|
36
|
+
@code = code
|
37
|
+
@info_message = info_message
|
38
|
+
@method_id = method_id
|
39
|
+
end
|
40
|
+
|
41
|
+
def id
|
42
|
+
"#{@method_id}#{@code}#{@info_message}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def warning_message
|
46
|
+
"WARNING (#{@code}): [#{@method_id}] -- #{@info_message}\n"
|
47
|
+
end
|
48
|
+
|
49
|
+
def warn
|
50
|
+
Warning.warn(warning_message)
|
51
|
+
end
|
52
|
+
|
53
|
+
def warn_through_writer
|
54
|
+
Apipie::Generator::Swagger::WarningWriter.instance.warn(self)
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param [Integer] code
|
58
|
+
# @param [Hash] message_attributes
|
59
|
+
#
|
60
|
+
# @return [Apipie::Generator::Swagger::Warning]
|
61
|
+
def self.for_code(code, method_id, message_attributes = {})
|
62
|
+
if !CODES.value?(code)
|
63
|
+
raise ArgumentError, 'Unknown warning code'
|
64
|
+
end
|
65
|
+
|
66
|
+
info_message = if message_attributes.present?
|
67
|
+
self::MESSAGES[code] % message_attributes
|
68
|
+
else
|
69
|
+
self::MESSAGES[code]
|
70
|
+
end
|
71
|
+
|
72
|
+
Apipie::Generator::Swagger::Warning.new(code, info_message, method_id)
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class Apipie::Generator::Swagger::WarningWriter
|
2
|
+
include Singleton
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@issued_warnings = []
|
6
|
+
end
|
7
|
+
|
8
|
+
# @param [Apipie::Generator::Swagger::Warning] warning
|
9
|
+
def warn(warning)
|
10
|
+
return if muted_warning?(warning)
|
11
|
+
|
12
|
+
warning.warn
|
13
|
+
|
14
|
+
@issued_warnings << warning.id
|
15
|
+
end
|
16
|
+
|
17
|
+
def issued_warnings?
|
18
|
+
@issued_warnings.count > 0
|
19
|
+
end
|
20
|
+
|
21
|
+
def clear!
|
22
|
+
@issued_warnings = []
|
23
|
+
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# @param [Apipie::Generator::Swagger::Warning] warning
|
30
|
+
#
|
31
|
+
# @return [TrueClass, FalseClass]
|
32
|
+
def muted_warning?(warning)
|
33
|
+
@issued_warnings.include?(warning.id) ||
|
34
|
+
suppressed_warning?(warning.code) ||
|
35
|
+
suppress_warnings?
|
36
|
+
end
|
37
|
+
|
38
|
+
# @param [Integer] warning_number
|
39
|
+
#
|
40
|
+
# @return [TrueClass, FalseClass]
|
41
|
+
def suppressed_warning?(warning_number)
|
42
|
+
suppress_warnings_config.is_a?(Array) && suppress_warnings_config.include?(warning_number)
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [TrueClass, FalseClass]
|
46
|
+
def suppress_warnings?
|
47
|
+
suppress_warnings_config == true
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [FalseClass, TrueClass, Array]
|
51
|
+
def suppress_warnings_config
|
52
|
+
Apipie.configuration.generator.swagger.suppress_warnings
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Apipie
|
2
|
+
module Helpers
|
3
|
+
def markup_to_html(text)
|
4
|
+
return "" if text.nil?
|
5
|
+
if Apipie.configuration.markup.respond_to? :to_html
|
6
|
+
Apipie.configuration.markup.to_html(text.strip_heredoc)
|
7
|
+
else
|
8
|
+
text.strip_heredoc
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_accessor :url_prefix
|
13
|
+
|
14
|
+
def request_script_name
|
15
|
+
Thread.current[:apipie_req_script_name] || ""
|
16
|
+
end
|
17
|
+
|
18
|
+
def request_script_name=(script_name)
|
19
|
+
Thread.current[:apipie_req_script_name] = script_name
|
20
|
+
end
|
21
|
+
|
22
|
+
def full_url(path)
|
23
|
+
unless @url_prefix
|
24
|
+
@url_prefix = ""
|
25
|
+
@url_prefix << request_script_name
|
26
|
+
@url_prefix << Apipie.configuration.doc_base_url
|
27
|
+
end
|
28
|
+
path = path.sub(%r{^/},"")
|
29
|
+
ret = "#{@url_prefix}/#{path}"
|
30
|
+
ret.insert(0,"/") unless %r{\A[./]}.match?(ret)
|
31
|
+
ret.sub!(%r{/*\Z},"")
|
32
|
+
ret
|
33
|
+
end
|
34
|
+
|
35
|
+
def include_javascripts
|
36
|
+
%w[ bundled/jquery.js
|
37
|
+
bundled/bootstrap-collapse.js
|
38
|
+
bundled/prettify.js
|
39
|
+
apipie.js ].map do |file|
|
40
|
+
"<script type='text/javascript' src='#{Apipie.full_url("javascripts/#{file}")}'></script>"
|
41
|
+
end.join("\n").html_safe
|
42
|
+
end
|
43
|
+
|
44
|
+
def include_stylesheets
|
45
|
+
%w[ bundled/bootstrap.min.css
|
46
|
+
bundled/prettify.css
|
47
|
+
bundled/bootstrap-responsive.min.css ].map do |file|
|
48
|
+
"<link type='text/css' rel='stylesheet' href='#{Apipie.full_url("stylesheets/#{file}")}'/>"
|
49
|
+
end.join("\n").html_safe
|
50
|
+
end
|
51
|
+
|
52
|
+
def label_class_for_error(err)
|
53
|
+
case err[:code]
|
54
|
+
when 200
|
55
|
+
'label label-info'
|
56
|
+
when 201
|
57
|
+
'label label-success'
|
58
|
+
when 204
|
59
|
+
'label label-info2'
|
60
|
+
when 401
|
61
|
+
'label label-warning'
|
62
|
+
when 403
|
63
|
+
'label label-warning2'
|
64
|
+
when 422
|
65
|
+
'label label-important'
|
66
|
+
when 404
|
67
|
+
'label label-inverse'
|
68
|
+
else
|
69
|
+
'label'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Apipie
|
2
|
+
|
3
|
+
module Markup
|
4
|
+
|
5
|
+
class RDoc
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
require 'rdoc'
|
9
|
+
require 'rdoc/markup/to_html'
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_html(text)
|
13
|
+
rdoc.convert(text)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def rdoc
|
19
|
+
if Gem::Version.new(::RDoc::VERSION) < Gem::Version.new('4.0.0')
|
20
|
+
::RDoc::Markup::ToHtml.new()
|
21
|
+
else
|
22
|
+
::RDoc::Markup::ToHtml.new(::RDoc::Options.new)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Markdown
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
require 'maruku'
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_html(text)
|
34
|
+
Maruku.new(text).to_html
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
class Textile
|
40
|
+
|
41
|
+
def initialize
|
42
|
+
require 'RedCloth'
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_html(text)
|
46
|
+
RedCloth.new(text).to_html
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Apipie::MethodDescription::Api
|
2
|
+
attr_accessor :short_description, :path, :http_method, :from_routes,
|
3
|
+
:options, :returns
|
4
|
+
|
5
|
+
def initialize(method, path, desc, options)
|
6
|
+
@http_method = method.to_s
|
7
|
+
@path = path
|
8
|
+
@short_description = desc
|
9
|
+
@from_routes = options[:from_routes]
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# Service that builds the appropriate Apipie::MethodDescription::Api
|
2
|
+
# required by Apipie::MethodDescription
|
3
|
+
#
|
4
|
+
class Apipie::MethodDescription::ApisService
|
5
|
+
# @param [Apipie::ResourceDescription] resource
|
6
|
+
# @param [Symbol] controller_action
|
7
|
+
# @param [Hash] dsl
|
8
|
+
def initialize(resource, controller_action, dsl)
|
9
|
+
@resource = resource
|
10
|
+
@controller_action = controller_action
|
11
|
+
@dsl = dsl
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Array<Apipie::MethodDescription::Api>]
|
15
|
+
def call
|
16
|
+
api_args.map do |http_method, path, desc, opts|
|
17
|
+
Apipie::MethodDescription::Api.new(
|
18
|
+
http_method,
|
19
|
+
concern_subst(path),
|
20
|
+
concern_subst(desc),
|
21
|
+
opts
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def concern_subst(path)
|
29
|
+
return if path.blank?
|
30
|
+
|
31
|
+
if from_concern?
|
32
|
+
@resource.controller._apipie_perform_concern_subst(path)
|
33
|
+
else
|
34
|
+
path
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [Array<Array>]
|
39
|
+
def api_args
|
40
|
+
return @dsl[:api_args] if !api_from_routes?
|
41
|
+
|
42
|
+
api_args = @dsl[:api_args].dup
|
43
|
+
|
44
|
+
api_args_from_routes = routes.map do |route_info|
|
45
|
+
[
|
46
|
+
route_info[:verb],
|
47
|
+
route_info[:path],
|
48
|
+
route_info[:desc],
|
49
|
+
(route_info[:options] || {}).merge(from_routes: true)
|
50
|
+
]
|
51
|
+
end
|
52
|
+
|
53
|
+
api_args.concat(api_args_from_routes)
|
54
|
+
end
|
55
|
+
|
56
|
+
def api_from_routes?
|
57
|
+
@dsl[:api_from_routes].present?
|
58
|
+
end
|
59
|
+
|
60
|
+
def from_concern?
|
61
|
+
@dsl[:from_concern] == true
|
62
|
+
end
|
63
|
+
|
64
|
+
def description
|
65
|
+
@dsl[:api_from_routes][:desc]
|
66
|
+
end
|
67
|
+
|
68
|
+
def options
|
69
|
+
@dsl[:api_from_routes][:options]
|
70
|
+
end
|
71
|
+
|
72
|
+
# @return [Array<Hash>]
|
73
|
+
def routes
|
74
|
+
Apipie.routes_for_action(
|
75
|
+
@resource.controller,
|
76
|
+
@controller_action,
|
77
|
+
{ desc: description, options: options }
|
78
|
+
)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
@@ -0,0 +1,230 @@
|
|
1
|
+
module Apipie
|
2
|
+
class MethodDescription
|
3
|
+
attr_reader :full_description, :method, :resource, :apis, :examples, :see, :formats, :headers, :show
|
4
|
+
attr_accessor :metadata
|
5
|
+
|
6
|
+
def initialize(method, resource, dsl_data)
|
7
|
+
@method = method.to_s
|
8
|
+
@resource = resource
|
9
|
+
@from_concern = dsl_data[:from_concern]
|
10
|
+
@apis = ApisService.new(resource, method, dsl_data).call
|
11
|
+
|
12
|
+
@full_description = dsl_data[:description] || ''
|
13
|
+
|
14
|
+
@errors = dsl_data[:errors].map do |args|
|
15
|
+
Apipie::ErrorDescription.from_dsl_data(args)
|
16
|
+
end
|
17
|
+
|
18
|
+
@tag_list = dsl_data[:tag_list]
|
19
|
+
|
20
|
+
@returns = dsl_data[:returns].map do |code,args|
|
21
|
+
Apipie::ResponseDescription.from_dsl_data(self, code, args)
|
22
|
+
end
|
23
|
+
|
24
|
+
@see = dsl_data[:see].map do |args|
|
25
|
+
Apipie::SeeDescription.new(args)
|
26
|
+
end
|
27
|
+
|
28
|
+
@formats = dsl_data[:formats]
|
29
|
+
@examples = dsl_data[:examples]
|
30
|
+
@examples += load_recorded_examples
|
31
|
+
|
32
|
+
@metadata = dsl_data[:meta]
|
33
|
+
|
34
|
+
@params_ordered = dsl_data[:params].map do |args|
|
35
|
+
Apipie::ParamDescription.from_dsl_data(self, args)
|
36
|
+
end.reject(&:response_only?)
|
37
|
+
|
38
|
+
@params_ordered = ParamDescription.unify(@params_ordered)
|
39
|
+
@headers = dsl_data[:headers]
|
40
|
+
|
41
|
+
@show = if dsl_data.key? :show
|
42
|
+
dsl_data[:show]
|
43
|
+
else
|
44
|
+
true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def id
|
49
|
+
"#{resource._id}##{method}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def params
|
53
|
+
params_ordered.reduce(ActiveSupport::OrderedHash.new) { |h,p| h[p.name] = p; h }
|
54
|
+
end
|
55
|
+
|
56
|
+
def params_ordered_self
|
57
|
+
@params_ordered
|
58
|
+
end
|
59
|
+
|
60
|
+
def params_ordered
|
61
|
+
all_params = []
|
62
|
+
parent = Apipie.get_resource_description(@resource.controller.superclass)
|
63
|
+
|
64
|
+
# get params from parent resource description
|
65
|
+
[parent, @resource].compact.each do |resource|
|
66
|
+
resource_params = resource._params_args.map do |args|
|
67
|
+
Apipie::ParamDescription.from_dsl_data(self, args)
|
68
|
+
end
|
69
|
+
merge_params(all_params, resource_params)
|
70
|
+
end
|
71
|
+
|
72
|
+
merge_params(all_params, @params_ordered)
|
73
|
+
all_params.find_all(&:validator)
|
74
|
+
end
|
75
|
+
|
76
|
+
def returns_self
|
77
|
+
@returns
|
78
|
+
end
|
79
|
+
|
80
|
+
def tag_list
|
81
|
+
all_tag_list = []
|
82
|
+
parent = Apipie.get_resource_description(@resource.controller.superclass)
|
83
|
+
|
84
|
+
# get tags from parent resource description
|
85
|
+
parent_tags = [parent, @resource].compact.flat_map(&:_tag_list_arg)
|
86
|
+
Apipie::TagListDescription.new((parent_tags + @tag_list).uniq.compact)
|
87
|
+
end
|
88
|
+
|
89
|
+
def returns
|
90
|
+
all_returns = []
|
91
|
+
parent = Apipie.get_resource_description(@resource.controller.superclass)
|
92
|
+
|
93
|
+
# get response descriptions from parent resource description
|
94
|
+
[parent, @resource].compact.each do |resource|
|
95
|
+
resource_returns = resource._returns_args.map do |code, args|
|
96
|
+
Apipie::ResponseDescription.from_dsl_data(self, code, args)
|
97
|
+
end
|
98
|
+
merge_returns(all_returns, resource_returns)
|
99
|
+
end
|
100
|
+
|
101
|
+
merge_returns(all_returns, @returns)
|
102
|
+
end
|
103
|
+
|
104
|
+
def errors
|
105
|
+
return @merged_errors if @merged_errors
|
106
|
+
@merged_errors = []
|
107
|
+
if @resource
|
108
|
+
resource_errors = @resource._errors_args.map do |args|
|
109
|
+
Apipie::ErrorDescription.from_dsl_data(args)
|
110
|
+
end
|
111
|
+
|
112
|
+
# exclude overwritten parent errors
|
113
|
+
@merged_errors = resource_errors.find_all do |err|
|
114
|
+
!@errors.any? { |e| e.code == err.code }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
@merged_errors.concat(@errors)
|
118
|
+
return @merged_errors
|
119
|
+
end
|
120
|
+
|
121
|
+
def version
|
122
|
+
resource._version
|
123
|
+
end
|
124
|
+
|
125
|
+
def doc_url
|
126
|
+
crumbs = []
|
127
|
+
crumbs << @resource._version if Apipie.configuration.version_in_url
|
128
|
+
crumbs << @resource._id
|
129
|
+
crumbs << @method
|
130
|
+
Apipie.full_url crumbs.join('/')
|
131
|
+
end
|
132
|
+
|
133
|
+
def create_api_url(api)
|
134
|
+
path = api.path
|
135
|
+
unless api.from_routes
|
136
|
+
path = "#{@resource._api_base_url}#{path}"
|
137
|
+
end
|
138
|
+
path = path[0..-2] if path[-1..-1] == '/'
|
139
|
+
return path
|
140
|
+
end
|
141
|
+
|
142
|
+
def method_apis_to_json(lang = nil)
|
143
|
+
@apis.each.collect do |api|
|
144
|
+
{
|
145
|
+
:api_url => create_api_url(api),
|
146
|
+
:http_method => api.http_method.to_s,
|
147
|
+
:short_description => Apipie.app.translate(api.short_description, lang),
|
148
|
+
:deprecated => resource._deprecated || api.options[:deprecated]
|
149
|
+
}
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def see
|
154
|
+
@see
|
155
|
+
end
|
156
|
+
|
157
|
+
def formats
|
158
|
+
@formats || @resource._formats
|
159
|
+
end
|
160
|
+
|
161
|
+
def to_json(lang = nil)
|
162
|
+
{
|
163
|
+
:doc_url => doc_url,
|
164
|
+
:name => @method,
|
165
|
+
:apis => method_apis_to_json(lang),
|
166
|
+
:formats => formats,
|
167
|
+
:full_description => Apipie.markup_to_html(Apipie.app.translate(@full_description, lang)),
|
168
|
+
:errors => errors.map{ |error| error.to_json(lang) }.flatten,
|
169
|
+
:params => params_ordered.map{ |param| param.to_json(lang) }.flatten,
|
170
|
+
:returns => @returns.map{ |return_item| return_item.to_json(lang) }.flatten,
|
171
|
+
:examples => @examples,
|
172
|
+
:metadata => @metadata,
|
173
|
+
:see => see.map(&:to_json),
|
174
|
+
:headers => headers,
|
175
|
+
:show => @show
|
176
|
+
}
|
177
|
+
end
|
178
|
+
|
179
|
+
# was the description defines in a module instead of directly in controller?
|
180
|
+
def from_concern?
|
181
|
+
@from_concern
|
182
|
+
end
|
183
|
+
|
184
|
+
def method_name
|
185
|
+
@method
|
186
|
+
end
|
187
|
+
|
188
|
+
private
|
189
|
+
|
190
|
+
def merge_params(params, new_params)
|
191
|
+
new_param_names = Set.new(new_params.map(&:name))
|
192
|
+
params.delete_if { |p| new_param_names.include?(p.name) }
|
193
|
+
params.concat(new_params)
|
194
|
+
end
|
195
|
+
|
196
|
+
def merge_returns(returns, new_returns)
|
197
|
+
new_return_codes = Set.new(new_returns.map(&:code))
|
198
|
+
returns.delete_if { |p| new_return_codes.include?(p.code) }
|
199
|
+
returns.concat(new_returns)
|
200
|
+
end
|
201
|
+
|
202
|
+
def load_recorded_examples
|
203
|
+
(Apipie.recorded_examples[id] || []).
|
204
|
+
find_all { |ex| ex["show_in_doc"].to_i > 0 }.
|
205
|
+
find_all { |ex| ex["versions"].nil? || ex["versions"].include?(self.version) }.
|
206
|
+
sort_by { |ex| ex["show_in_doc"] }.
|
207
|
+
map { |ex| format_example(ex.symbolize_keys) }
|
208
|
+
end
|
209
|
+
|
210
|
+
def format_example_data(data)
|
211
|
+
case data
|
212
|
+
when Array, Hash
|
213
|
+
JSON.pretty_generate(data).gsub(/: \[\s*\]/,": []").gsub(/\{\s*\}/,"{}")
|
214
|
+
else
|
215
|
+
data
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def format_example(ex)
|
220
|
+
example = ""
|
221
|
+
example << "// #{ex[:title]}\n" if ex[:title].present?
|
222
|
+
example << "#{ex[:verb]} #{ex[:path]}"
|
223
|
+
example << "?#{ex[:query]}" unless ex[:query].blank?
|
224
|
+
example << "\n" << format_example_data(ex[:request_data]).to_s if ex[:request_data]
|
225
|
+
example << "\n" << ex[:code].to_s
|
226
|
+
example << "\n" << format_example_data(ex[:response_data]).to_s if ex[:response_data]
|
227
|
+
example
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Middleware for rails app that adds checksum of JSON in the response headers
|
2
|
+
# which can help client to realize when JSON has changed
|
3
|
+
#
|
4
|
+
# Add the following to your application.rb
|
5
|
+
# require 'apipie/middleware/checksum_in_headers'
|
6
|
+
# # Add JSON checksum in headers for smarter caching
|
7
|
+
# config.middleware.use "Apipie::Middleware::ChecksumInHeaders"
|
8
|
+
#
|
9
|
+
# And in your apipie initializer allow checksum calculation
|
10
|
+
# Apipie.configuration.update_checksum = true
|
11
|
+
# and reload documentation
|
12
|
+
# Apipie.reload_documentation
|
13
|
+
#
|
14
|
+
# By default the header is added to requests on /api and /apipie only
|
15
|
+
# It can be changed with
|
16
|
+
# Apipie.configuration.checksum_path = ['/prefix/api']
|
17
|
+
# If set to nil the header is added always
|
18
|
+
|
19
|
+
module Apipie
|
20
|
+
module Middleware
|
21
|
+
class ChecksumInHeaders
|
22
|
+
def initialize(app)
|
23
|
+
@app = app
|
24
|
+
end
|
25
|
+
|
26
|
+
def call(env)
|
27
|
+
status, headers, body = @app.call(env)
|
28
|
+
if !Apipie.configuration.checksum_path || env['PATH_INFO'].start_with?(*Apipie.configuration.checksum_path)
|
29
|
+
headers.merge!( 'Apipie-Checksum' => Apipie.checksum )
|
30
|
+
end
|
31
|
+
return [status, headers, body]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Apipie
|
4
|
+
class ParamDescription
|
5
|
+
# Data transfer object, used when param description is deprecated
|
6
|
+
class Deprecation
|
7
|
+
attr_reader :info, :deprecated_in, :sunset_at
|
8
|
+
|
9
|
+
def initialize(info: nil, deprecated_in: nil, sunset_at: nil)
|
10
|
+
@info = info
|
11
|
+
@deprecated_in = deprecated_in
|
12
|
+
@sunset_at = sunset_at
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_json(*_args)
|
16
|
+
{
|
17
|
+
info: @info,
|
18
|
+
deprecated_in: @deprecated_in,
|
19
|
+
sunset_at: @sunset_at
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|