Skip to content

Commit

Permalink
feat: add validation related parameters to ValidationException (#76)
Browse files Browse the repository at this point in the history
* fix

* feat: validation related parameters to ValidationException

* fix for 1.6

* revert message
  • Loading branch information
vdayanand authored Jun 28, 2024
1 parent 35834a6 commit fb0cc87
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
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

0 comments on commit fb0cc87

Please sign in to comment.