class Apipie::Generator::Swagger::MethodDescription::ParametersService
Public Class Methods
new(method_description, path:, http_method:)
click to toggle source
@param [Apipie::Generator::Swagger::MethodDescription::Decorator] method_description @param [Apipie::Generator::Swagger::PathDecorator] path @param [Symbol] http_method
# File lib/apipie/generator/swagger/method_description/parameters_service.rb, line 5 def initialize(method_description, path:, http_method:) @method_description = method_description @path = path @http_method = http_method end
Public Instance Methods
call()
click to toggle source
@return [Array]
# File lib/apipie/generator/swagger/method_description/parameters_service.rb, line 12 def call path_params_schema + body_params_schema + header_params_schema end
Private Instance Methods
all_params()
click to toggle source
# File lib/apipie/generator/swagger/method_description/parameters_service.rb, line 71 def all_params @all_params ||= begin param_names_from_method = @method_description.params.keys missing = @path.param_names - param_names_from_method result = @method_description.params missing.each do |name| warn_path_parameter_not_described(name, @path) result[name.to_sym] = Apipie::Generator::Swagger::ParamDescription .create_for_missing_param(@method_description, name) end result end end
body_allowed_for_current_method?()
click to toggle source
# File lib/apipie/generator/swagger/method_description/parameters_service.rb, line 128 def body_allowed_for_current_method? %w[get head].exclude?(@http_method) end
body_param_descriptions()
click to toggle source
# File lib/apipie/generator/swagger/method_description/parameters_service.rb, line 90 def body_param_descriptions @body_param_descriptions ||= all_params .reject { |k, _| @path.param?(k) } .values end
body_params_schema()
click to toggle source
# File lib/apipie/generator/swagger/method_description/parameters_service.rb, line 30 def body_params_schema if params_in_body? && body_allowed_for_current_method? composite = Apipie::Generator::Swagger::ParamDescription::Composite.new( body_param_descriptions, Apipie::Generator::Swagger::Context.new( allow_null: false, http_method: @http_method, controller_method: @method_description ) ) if Apipie.configuration.generator.swagger.json_input_uses_refs? composite = composite .referenced("#{@method_description.operation_id}_input") end swagger_schema_for_body = composite.to_swagger swagger_body_param = { name: 'body', in: 'body', schema: swagger_schema_for_body } if swagger_schema_for_body.present? [swagger_body_param] else [] end else Apipie::Generator::Swagger::ParamDescription::PathParamsComposite.new( body_param_descriptions, Apipie::Generator::Swagger::Context.new( allow_null: false, http_method: @http_method, controller_method: @method_description ) ).to_swagger end end
header_params_schema()
click to toggle source
@return [Array]
# File lib/apipie/generator/swagger/method_description/parameters_service.rb, line 104 def header_params_schema return [] if @method_description.headers.blank? @method_description.headers.map do |header| header_hash = { name: header[:name], in: 'header', required: header[:options][:required], description: header[:description], type: header[:options][:type] || 'string' } if header[:options][:default] header_hash[:default] = header[:options][:default] end header_hash end end
params_in_body?()
click to toggle source
# File lib/apipie/generator/swagger/method_description/parameters_service.rb, line 124 def params_in_body? Apipie.configuration.generator.swagger.content_type_input == :json end
path_param_descriptions()
click to toggle source
# File lib/apipie/generator/swagger/method_description/parameters_service.rb, line 96 def path_param_descriptions @path_param_descriptions ||= all_params .select { |k, _| @path.param?(k) } .each { |_, desc| desc.required = true } .values end
path_params_schema()
click to toggle source
# File lib/apipie/generator/swagger/method_description/parameters_service.rb, line 18 def path_params_schema Apipie::Generator::Swagger::ParamDescription::PathParamsComposite.new( path_param_descriptions, Apipie::Generator::Swagger::Context.new( allow_null: false, default_in_value: 'path', http_method: @http_method, controller_method: @method_description ) ).to_swagger end
warn_path_parameter_not_described(name, path)
click to toggle source
# File lib/apipie/generator/swagger/method_description/parameters_service.rb, line 132 def warn_path_parameter_not_described(name, path) Apipie::Generator::Swagger::Warning.for_code( Apipie::Generator::Swagger::Warning::PATH_PARAM_NOT_DESCRIBED_CODE, @method_description.ruby_name, { name: name, path: path } ).warn_through_writer end