Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CI workflow to run on Ubuntu 24.04 #950

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
Expand Down
5 changes: 1 addition & 4 deletions lib/apipie/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,7 @@ def json_schema_for_method_response(version, controller_name, method_name, retur
.json_schema_for_method_response(method, return_code, allow_nulls)
end

def json_schema_for_self_describing_class(cls, allow_nulls)
Apipie::SwaggerGenerator
.json_schema_for_self_describing_class(cls, allow_nulls)
end
delegate :json_schema_for_self_describing_class, to: :'Apipie::SwaggerGenerator'

def to_swagger_json(version, resource_id, method_name, language, clear_warnings = false)
return unless valid_search_args?(version, resource_id, method_name)
Expand Down
84 changes: 41 additions & 43 deletions lib/apipie/dsl_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,63 +230,61 @@ def tags(*args)
def _apipie_define_validators(description)

# [re]define method only if validation is turned on
if description && (Apipie.configuration.validate == true ||
Apipie.configuration.validate == :implicitly ||
Apipie.configuration.validate == :explicitly)

_apipie_save_method_params(description.method, description.params)

unless instance_methods.include?(:apipie_validations)
define_method(:apipie_validations) do
method_params = self.class._apipie_get_method_params(action_name)

if Apipie.configuration.validate_presence?
Validator::BaseValidator.raise_if_missing_params do |missing|
method_params.each_value do |param|
# check if required parameters are present
missing << param if param.required && !params.key?(param.name)
end
end
end
return unless description && [true, :implicitly, :explicitly].include?(Apipie.configuration.validate)

_apipie_save_method_params(description.method, description.params)

if Apipie.configuration.validate_value?
unless instance_methods.include?(:apipie_validations)
define_method(:apipie_validations) do
method_params = self.class._apipie_get_method_params(action_name)

if Apipie.configuration.validate_presence?
Validator::BaseValidator.raise_if_missing_params do |missing|
method_params.each_value do |param|
# params validations
param.validate(params[:"#{param.name}"]) if params.key?(param.name)
# check if required parameters are present
missing << param if param.required && !params.key?(param.name)
end
end
end

# Only allow params passed in that are defined keys in the api
# Auto skip the default params (format, controller, action)
if Apipie.configuration.validate_key?
params.reject{|k,_| %w[format controller action].include?(k.to_s) }.each_pair do |param, _|
# params allowed
if method_params.none? {|_,p| p.name.to_s == param.to_s}
self.class._apipie_handle_validate_key_error params, param
end
end
if Apipie.configuration.validate_value?
method_params.each_value do |param|
# params validations
param.validate(params[:"#{param.name}"]) if params.key?(param.name)
end
end

return unless Apipie.configuration.process_value?
@api_params ||= {}
method_params.each_value do |param|
# params processing
@api_params[param.as] = param.process_value(params[:"#{param.name}"]) if params.key?(param.name)
# Only allow params passed in that are defined keys in the api
# Auto skip the default params (format, controller, action)
if Apipie.configuration.validate_key?
params.reject{|k,_| %w[format controller action].include?(k.to_s) }.each_pair do |param, _|
# params allowed
if method_params.none? {|_,p| p.name.to_s == param.to_s}
self.class._apipie_handle_validate_key_error params, param
end
end
end

return unless Apipie.configuration.process_value?
@api_params ||= {}
method_params.each_value do |param|
# params processing
@api_params[param.as] = param.process_value(params[:"#{param.name}"]) if params.key?(param.name)
end
end
end

if Apipie.configuration.validate == :implicitly || Apipie.configuration.validate == true
old_method = instance_method(description.method)
return unless [:implicitly, true].include?(Apipie.configuration.validate)
old_method = instance_method(description.method)

define_method(description.method) do |*args|
apipie_validations
define_method(description.method) do |*args|
apipie_validations

# run the original method code
old_method.bind(self).call(*args)
end
end
# run the original method code
old_method.bind(self).call(*args)
end


end

def _apipie_handle_validate_key_error params, param
Expand Down
4 changes: 1 addition & 3 deletions lib/apipie/extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def finish
end
end

def logger
Rails.logger
end
delegate :logger, to: :Rails

def call_recorder
Thread.current[:apipie_call_recorder] ||= Recorder.new
Expand Down
2 changes: 1 addition & 1 deletion lib/apipie/param_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def initialize(method_description, name, validator, desc_or_options = nil, optio
action_awareness

if validator
if (validator != Hash) && (validator.is_a? Hash) && (validator[:array_of])
if (validator != Hash) && (validator.is_a? Hash) && validator[:array_of]
@is_array = true
validator = validator[:array_of]
raise "an ':array_of =>' validator is allowed exclusively on response-only fields" unless @response_only
Expand Down
8 changes: 2 additions & 6 deletions lib/apipie/response_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,13 @@ def is_array?
@is_array_of != false
end

def typename
@response_object.typename
end
delegate :typename, to: :@response_object

def param_description
nil
end

def params_ordered
@response_object.params_ordered
end
delegate :params_ordered, to: :@response_object

def additional_properties
!!@response_object.additional_properties
Expand Down
4 changes: 1 addition & 3 deletions lib/apipie/static_dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def match?(path)
end
end

def call(env)
@file_server.call(env)
end
delegate :call, to: :@file_server

def ext
@ext ||= begin
Expand Down
12 changes: 3 additions & 9 deletions lib/apipie/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,7 @@ def description

class DecimalValidator < BaseValidator

def validate(value)
self.class.validate(value)
end
delegate :validate, to: :class

def self.build(param_description, argument, options, block)
if argument == :decimal
Expand All @@ -456,9 +454,7 @@ def self.validate(value)

class NumberValidator < BaseValidator

def validate(value)
self.class.validate(value)
end
delegate :validate, to: :class

def self.build(param_description, argument, options, block)
if argument == :number
Expand Down Expand Up @@ -549,9 +545,7 @@ def description
"Must be an Array of nested elements"
end

def params_ordered
@validator.params_ordered
end
delegate :params_ordered, to: :@validator
end

end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def fail(msg)

match do |unresolved|
actual = resolve_refs(unresolved)
return fail("expected schema to have type 'object' (got '#{actual[:type]}')") if (actual[:type]) != 'object'
return fail("expected schema to have type 'object' (got '#{actual[:type]}')") if actual[:type] != 'object'
return fail("expected schema to include param named '#{name}' (got #{actual[:properties].keys})") if (prop = actual[:properties][name]).nil?
return fail("expected param '#{name}' to have type '#{type}' (got '#{prop[:type]}')") if prop[:type] != type
return fail("expected param '#{name}' to have description '#{opts[:description]}' (got '#{prop[:description]}')") if opts[:description] && prop[:description] != opts[:description]
Expand Down
Loading