Skip to content
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
10 changes: 8 additions & 2 deletions src/commontypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ abstract type AnyOfAPIModel <: UnionAPIModel end
struct OpenAPIException <: Exception
reason::String
end
struct ValidationException <: Exception
Base.@kwdef struct ValidationException <: Exception
reason::String
value=nothing
parameter=nothing
rule=nothing
args=nothing
operation_or_model=nothing
end
ValidationException(reason) = ValidationException(;reason)
struct InvocationException <: Exception
reason::String
end

property_type(::Type{T}, name::Symbol) where {T<:APIModel} = error("invalid type $T")
property_type(::Type{T}, name::Symbol) where {T<:APIModel} = error("invalid type $T")
6 changes: 3 additions & 3 deletions src/val.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ const VAL_API_PARAM = Dict{Symbol,Function}([
:multipleOf => val_multiple_of,
])

function validate_param(param, operation_or_model, rule, value, args...)
function validate_param(parameter, operation_or_model, rule, value, args...)
# do not validate missing values
(value === nothing) && return

VAL_API_PARAM[rule](value, args...) && return

msg = string("Invalid value ($value) of parameter ", param, " for ", operation_or_model, ", ", MSG_INVALID_API_PARAM[rule](args...))
throw(ValidationException(msg))
reason = string("Invalid value ($value) of parameter ", parameter, " for ", operation_or_model, ", ", MSG_INVALID_API_PARAM[rule](args...))
throw(ValidationException(;reason, operation_or_model, value, parameter, rule, args))
end

validate_property(::Type{T}, name::Symbol, val) where {T<:APIModel} = nothing