From dd3797ba8953800c8856f7d93af636658cfd64ed Mon Sep 17 00:00:00 2001 From: vdayanand Date: Thu, 27 Jun 2024 14:44:49 +0530 Subject: [PATCH 1/4] fix --- src/commontypes.jl | 3 ++- src/val.jl | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/commontypes.jl b/src/commontypes.jl index 6dc32fb..195144a 100644 --- a/src/commontypes.jl +++ b/src/commontypes.jl @@ -6,8 +6,9 @@ abstract type AnyOfAPIModel <: UnionAPIModel end struct OpenAPIException <: Exception reason::String end -struct ValidationException <: Exception +@kwdef struct ValidationException <: Exception reason::String + operation_or_model::String=nothing end struct InvocationException <: Exception reason::String diff --git a/src/val.jl b/src/val.jl index fbe64f6..3c4f3b2 100644 --- a/src/val.jl +++ b/src/val.jl @@ -79,8 +79,8 @@ function validate_param(param, operation_or_model, rule, value, args...) 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)) + msg = string("Invalid value ($value) of parameter ", param, ", ", MSG_INVALID_API_PARAM[rule](args...)) + throw(ValidationException(;reason=msg, operation_or_model)) end validate_property(::Type{T}, name::Symbol, val) where {T<:APIModel} = nothing From b5eeaf21b98b15c2f03f38c92a8ead0afea03b53 Mon Sep 17 00:00:00 2001 From: vdayanand Date: Thu, 27 Jun 2024 15:12:21 +0530 Subject: [PATCH 2/4] feat: validation related parameters to ValidationException --- src/commontypes.jl | 9 +++++++-- src/val.jl | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/commontypes.jl b/src/commontypes.jl index 195144a..f47b282 100644 --- a/src/commontypes.jl +++ b/src/commontypes.jl @@ -8,10 +8,15 @@ struct OpenAPIException <: Exception end @kwdef struct ValidationException <: Exception reason::String - operation_or_model::String=nothing + 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 3c4f3b2..56f1346 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, ", ", MSG_INVALID_API_PARAM[rule](args...)) - throw(ValidationException(;reason=msg, operation_or_model)) + reason = string("Invalid value ($value) of parameter ", parameter, ", ", 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 From 2316db9d34993038bfe1265ccf188bd3a8ee5f9d Mon Sep 17 00:00:00 2001 From: vdayanand Date: Thu, 27 Jun 2024 15:16:01 +0530 Subject: [PATCH 3/4] fix for 1.6 --- src/commontypes.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commontypes.jl b/src/commontypes.jl index f47b282..abaef28 100644 --- a/src/commontypes.jl +++ b/src/commontypes.jl @@ -6,7 +6,7 @@ abstract type AnyOfAPIModel <: UnionAPIModel end struct OpenAPIException <: Exception reason::String end -@kwdef struct ValidationException <: Exception +Base.@kwdef struct ValidationException <: Exception reason::String value=nothing parameter=nothing From 338ff2c3e3583dd945a3745ea75850c6245ff5f8 Mon Sep 17 00:00:00 2001 From: vdayanand Date: Fri, 28 Jun 2024 13:30:16 +0530 Subject: [PATCH 4/4] revert message --- src/val.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/val.jl b/src/val.jl index 56f1346..21f393b 100644 --- a/src/val.jl +++ b/src/val.jl @@ -79,7 +79,7 @@ function validate_param(parameter, operation_or_model, rule, value, args...) VAL_API_PARAM[rule](value, args...) && return - reason = string("Invalid value ($value) of parameter ", parameter, ", ", MSG_INVALID_API_PARAM[rule](args...)) + 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