Skip to content

Commit

Permalink
handle Any types that can hold vectors also (#63)
Browse files Browse the repository at this point in the history
handle case where a property is declared as `object` but response contains a vector.
  • Loading branch information
tanmaykm authored Oct 4, 2023
1 parent a63766e commit 9b6bf34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ keywords = ["Swagger", "OpenAPI", "REST"]
license = "MIT"
desc = "OpenAPI server and client helper for Julia"
authors = ["JuliaHub Inc."]
version = "0.1.19"
version = "0.1.20"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
6 changes: 6 additions & 0 deletions src/json.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ end
function from_json(o::T, name::Symbol, v::Vector) where {T <: APIModel}
# in Julia we can not support JSON null unless the element type is explicitly set to support it
ftype = property_type(T, name)

if ftype === Any
setfield!(o, name, v)
return o
end

vtype = isa(ftype, Union) ? ((ftype.a === Nothing) ? ftype.b : ftype.a) : (ftype <: Vector) ? ftype : Union{}
veltype = eltype(vtype)
(Nothing <: veltype) || filter!(x->x!==nothing, v)
Expand Down

2 comments on commit 9b6bf34

@tanmaykm
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/92714

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.20 -m "<description of version>" 9b6bf348b93a0681f02bcc413a8e8e10b5287c49
git push origin v0.1.20

Please sign in to comment.