diff --git a/src/commontypes.jl b/src/commontypes.jl index 6dc32fb..abaef28 100644 --- a/src/commontypes.jl +++ b/src/commontypes.jl @@ -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") \ No newline at end of file +property_type(::Type{T}, name::Symbol) where {T<:APIModel} = error("invalid type $T") diff --git a/src/val.jl b/src/val.jl index fbe64f6..21f393b 100644 --- a/src/val.jl +++ b/src/val.jl @@ -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