Skip to content

Commit fb0cc87

Browse files
authored
feat: add validation related parameters to ValidationException (#76)
* fix * feat: validation related parameters to ValidationException * fix for 1.6 * revert message
1 parent 35834a6 commit fb0cc87

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/commontypes.jl

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ abstract type AnyOfAPIModel <: UnionAPIModel end
66
struct OpenAPIException <: Exception
77
reason::String
88
end
9-
struct ValidationException <: Exception
9+
Base.@kwdef struct ValidationException <: Exception
1010
reason::String
11+
value=nothing
12+
parameter=nothing
13+
rule=nothing
14+
args=nothing
15+
operation_or_model=nothing
1116
end
17+
ValidationException(reason) = ValidationException(;reason)
1218
struct InvocationException <: Exception
1319
reason::String
1420
end
1521

16-
property_type(::Type{T}, name::Symbol) where {T<:APIModel} = error("invalid type $T")
22+
property_type(::Type{T}, name::Symbol) where {T<:APIModel} = error("invalid type $T")

src/val.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ const VAL_API_PARAM = Dict{Symbol,Function}([
7373
:multipleOf => val_multiple_of,
7474
])
7575

76-
function validate_param(param, operation_or_model, rule, value, args...)
76+
function validate_param(parameter, operation_or_model, rule, value, args...)
7777
# do not validate missing values
7878
(value === nothing) && return
7979

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

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

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

0 commit comments

Comments
 (0)