Skip to content

Commit a0bb4b8

Browse files
authored
Fix conversions errors (#34)
* Fix invalid attempt to convert vector elements to date * Add missing convert methods for OneOf and AnyOf
1 parent 7960b1c commit a0bb4b8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/client.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using TimeZones
99
using LibCURL
1010

1111
import Base: convert, show, summary, getproperty, setproperty!, iterate
12-
import ..OpenAPI: APIModel, UnionAPIModel, APIClientImpl, OpenAPIException, InvocationException, to_json, from_json, validate_property, property_type
12+
import ..OpenAPI: APIModel, UnionAPIModel, OneOfAPIModel, AnyOfAPIModel, APIClientImpl, OpenAPIException, InvocationException, to_json, from_json, validate_property, property_type
1313
import ..OpenAPI: str2zoneddatetime, str2datetime, str2date
1414

1515
# collection formats (OpenAPI v2)
@@ -523,6 +523,12 @@ Base.hasproperty(o::T, name::Symbol) where {T<:APIModel} = ((name in propertynam
523523

524524
convert(::Type{T}, json::Dict{String,Any}) where {T<:APIModel} = from_json(T, json)
525525
convert(::Type{T}, v::Nothing) where {T<:APIModel} = T()
526+
convert(::Type{T}, v::T) where {T<:OneOfAPIModel} = v
527+
convert(::Type{T}, json::Dict{String,Any}) where {T<:OneOfAPIModel} = from_json(T, json)
528+
convert(::Type{T}, v) where {T<:OneOfAPIModel} = T(v)
529+
convert(::Type{T}, v::T) where {T<:AnyOfAPIModel} = v
530+
convert(::Type{T}, json::Dict{String,Any}) where {T<:AnyOfAPIModel} = from_json(T, json)
531+
convert(::Type{T}, v) where {T<:AnyOfAPIModel} = T(v)
526532

527533
show(io::IO, model::T) where {T<:UnionAPIModel} = print(io, JSON.json(model.value, 2))
528534
show(io::IO, model::T) where {T<:APIModel} = print(io, JSON.json(model, 2))

src/json.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ function from_json(o::T, name::Symbol, v::Vector) where {T <: APIModel}
7979
veltype = eltype(vtype)
8080
(Nothing <: veltype) || filter!(x->x!==nothing, v)
8181

82-
if ZonedDateTime <: veltype
82+
if veltype === Any
83+
setfield!(o, name, convert(ftype, v))
84+
elseif ZonedDateTime <: veltype
8385
setfield!(o, name, map(str2zoneddatetime, v))
8486
elseif DateTime <: veltype
8587
setfield!(o, name, map(str2datetime, v))

0 commit comments

Comments
 (0)