Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/runtime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ _decode(::Type{Nothing}, ::Nothing) = nothing
_decode(::Type{Nothing}, value) = throw(DecodeError("expected null, got $(typeof(value))"))
_decode(::Type{String}, value::AbstractString) = String(value)
_decode(::Type{Bool}, value::Bool) = value
_decode(::Type{Bool}, value) = throw(DecodeError("expected a boolean, got $(typeof(value))"))
_decode(::Type{Bool}, value::Integer) = throw(DecodeError("expected a boolean, got $(typeof(value))"))
_decode(::Type{T}, value::Integer) where {T<:Integer} = try
value isa Bool && throw(DecodeError("expected an integer, got Bool"))
convert(T, value)
Expand Down
15 changes: 15 additions & 0 deletions test/models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"ClosedRecord",
"ConditionalRecord",
"NumericChoice",
"NanChoice",
)
id = lowercase(name)
paths["/" * id] = OpenAPI.obj(
Expand Down Expand Up @@ -62,6 +63,13 @@
"NumericChoice" => OpenAPI.obj(
"type" => ["integer", "number"],
),
"NanChoice" => OpenAPI.obj(
"oneOf" => Any[
OpenAPI.obj("const" => "NaN"),
OpenAPI.obj("type" => "number"),
OpenAPI.obj("type" => "boolean"),
],
),
"Record" => OpenAPI.obj(
"type" => "object",
"required" => ["fixed"],
Expand Down Expand Up @@ -157,6 +165,13 @@
@test call(:_decode, C.NumericChoice, 3) === Int64(3)
@test call(:_decode, C.NumericChoice, 3.5) === 3.5

for (input, expected) in (1.0 => 1.0, 1 => 1.0, true => true, "NaN" => "NaN")
for validate in (true, false)
decoded = call(:_decode, C.NanChoice, input, validate).value
@test decoded === expected
end
end

record = call(
:_decode,
C.Record,
Expand Down
Loading