foreman/config/initializers/apipie.rb @ 3625dad6
981a9508 | Martin Bačovský | Apipie.configure do |config|
|
|
86fb12c1 | Ohad Levy | config.app_name = "Foreman"
|
|
config.app_info = "The Foreman is aimed to be a single address for all machines life cycle management."
|
|||
config.copyright = ""
|
|||
config.api_base_url = "/api"
|
|||
config.api_controllers_matcher = "#{Rails.root}/app/controllers/api/v1/*.rb"
|
|||
config.ignored_by_recorder = %w[]
|
|||
config.doc_base_url = "/apidoc"
|
|||
3625dad6 | Ohad Levy | config.use_cache = Rails.env.production?
|
|
86fb12c1 | Ohad Levy | config.validate = false
|
|
3625dad6 | Ohad Levy | config.force_dsl = true
|
|
config.reload_controllers = Rails.env.development?
|
|||
config.markup = Apipie::Markup::Markdown.new if Rails.env.development?
|
|||
86fb12c1 | Ohad Levy | end
|
|
# special type of validator: we say that it's not specified
|
|||
981a9508 | Martin Bačovský | class UndefValidator < Apipie::Validator::BaseValidator
|
|
86fb12c1 | Ohad Levy | ||
def validate(value)
|
|||
true
|
|||
end
|
|||
def self.build(param_description, argument, options, block)
|
|||
if argument == :undef
|
|||
self.new(param_description)
|
|||
end
|
|||
end
|
|||
def description
|
|||
nil
|
|||
end
|
|||
end
|
|||
981a9508 | Martin Bačovský | class Apipie::Validator::TypeValidator
|
|
86fb12c1 | Ohad Levy | def description
|
|
@type.name
|
|||
end
|
|||
end
|
|||
981a9508 | Martin Bačovský | class Apipie::Validator::HashValidator
|
|
86fb12c1 | Ohad Levy | def description
|
|
"Hash"
|
|||
end
|
|||
end
|
|||
981a9508 | Martin Bačovský | class NumberValidator < Apipie::Validator::BaseValidator
|
|
86fb12c1 | Ohad Levy | ||
def validate(value)
|
|||
value.to_s =~ /^(0|[1-9]\d*)$/
|
|||
end
|
|||
def self.build(param_description, argument, options, block)
|
|||
if argument == :number
|
|||
self.new(param_description)
|
|||
end
|
|||
end
|
|||
def error
|
|||
"Parameter #{param_name} expecting to be a number, got: #{@error_value}"
|
|||
end
|
|||
def description
|
|||
"number."
|
|||
end
|
|||
end
|
|||
981a9508 | Martin Bačovský | class IdentifierValidator < Apipie::Validator::BaseValidator
|
|
86fb12c1 | Ohad Levy | ||
def validate(value)
|
|||
value = value.to_s
|
|||
value =~ /\A[\w| |_|-]*\Z/ && value.strip == value && (2..128).include?(value.length)
|
|||
end
|
|||
def self.build(param_description, argument, options, block)
|
|||
if argument == :identifier
|
|||
self.new(param_description)
|
|||
end
|
|||
end
|
|||
def error
|
|||
"Parameter #{param_name} expecting to be an identifier, got: #{@error_value}"
|
|||
end
|
|||
def description
|
|||
"string from 2 to 128 characters containting only alphanumeric characters, space, '_', '-' with no leading or trailing space.."
|
|||
end
|
|||
end
|
|||
981a9508 | Martin Bačovský | class BooleanValidator < Apipie::Validator::BaseValidator
|
|
86fb12c1 | Ohad Levy | ||
def validate(value)
|
|||
%w[true false].include?(value.to_s)
|
|||
end
|
|||
def self.build(param_description, argument, options, block)
|
|||
if argument == :bool
|
|||
self.new(param_description)
|
|||
end
|
|||
end
|
|||
def error
|
|||
"Parameter #{param_name} expecting to be a boolean value, got: #{@error_value}"
|
|||
end
|
|||
def description
|
|||
"boolean"
|
|||
end
|
|||
end
|