Skip to content

Commit dfd64eb

Browse files
authored
Merge pull request #10 from JuliaComputing/tan/misc
helper methods, validations, handle object types
2 parents c9235c8 + 8d07ef8 commit dfd64eb

File tree

6 files changed

+38
-5
lines changed

6 files changed

+38
-5
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ uuid = "d5e62ea6-ddf3-4d43-8e4c-ad5e6c8bfd7d"
33
keywords = ["Swagger", "OpenAPI", "REST"]
44
license = "MIT"
55
desc = "OpenAPI server and client helper for Julia"
6-
authors = ["Tanmay Mohapatra <[email protected]>"]
7-
version = "0.1.3"
6+
authors = ["Tanmay Mohapatra <[email protected]>", "JuliaHub"]
7+
version = "0.1.4"
88

99
[deps]
1010
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

src/client.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ summary(model::T) where {T<:APIModel} = print(io, T)
514514
"""
515515
is_longpoll_timeout(ex::Exception)
516516
517-
Examine the supplied exception and returns true if the reason is timeout
517+
Examine the supplied exception and return true if the reason is timeout
518518
of a long polling request. If the exception is a nested exception of type
519519
CompositeException or TaskFailedException, then navigates through the nested
520520
exception values to examine the leaves.
@@ -526,4 +526,17 @@ function is_longpoll_timeout(ex::ApiException)
526526
ex.status == 200 && match(r"Operation timed out after \d+ milliseconds with \d+ bytes received", ex.reason) !== nothing
527527
end
528528

529+
"""
530+
is_request_interrupted(ex::Exception)
531+
532+
Examine the supplied exception and return true if the reason is that the
533+
request was interrupted. If the exception is a nested exception of type
534+
CompositeException or TaskFailedException, then navigates through the nested
535+
exception values to examine the leaves.
536+
"""
537+
is_request_interrupted(ex) = false
538+
is_request_interrupted(ex::TaskFailedException) = is_request_interrupted(ex.task.exception)
539+
is_request_interrupted(ex::CompositeException) = any(is_request_interrupted, ex.exceptions)
540+
is_request_interrupted(ex::InvocationException) = ex.reason == "request was interrupted"
541+
529542
end # module Clients

src/json.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ end
5555

5656
function from_json(o::T, name::Symbol, v) where {T <: APIModel}
5757
ftype = property_type(T, name)
58-
if ZonedDateTime <: ftype
58+
if ftype === Any
59+
setfield!(o, name, v)
60+
elseif ZonedDateTime <: ftype
5961
setfield!(o, name, str2zoneddatetime(v))
6062
elseif DateTime <: ftype
6163
setfield!(o, name, str2datetime(v))

src/val.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function val_pattern(val::AbstractString, pattern::Regex)
2323
return !isnothing(match(pattern, val))
2424
end
2525
val_format(val, format) = true # accept any unhandled format
26-
val_format(val::Union{AbstractString,Integer,AbstractFloat}, format::AbstractString) = val_format(val, Val(Symbol(format)))
26+
val_format(val, format::AbstractString) = val_format(val, Val(Symbol(format)))
2727
val_format(val::AbstractString, ::Val{:date}) = str2date(val) isa Date
2828
val_format(val::AbstractString, ::Val{Symbol("date-time")}) = str2datetime(val) isa DateTime
2929
val_format(val::AbstractString, ::Val{:byte}) = try

test/client/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function runtests()
1212
@testset "Client" begin
1313
@testset "Utils" begin
1414
test_longpoll_exception_check()
15+
test_request_interrupted_exception_check()
1516
end
1617
@testset "Validations" begin
1718
test_validations()

test/client/utilstests.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ function test_longpoll_exception_check()
3131
@test OpenAPI.Clients.is_longpoll_timeout(CompositeException([openapiex1, as_taskfailedexception(openapiex1)])) == false
3232
end
3333

34+
function test_request_interrupted_exception_check()
35+
ex1 = OpenAPI.InvocationException("request was interrupted")
36+
ex2 = ArgumentError("request interrupted")
37+
ex3 = OpenAPI.InvocationException("not request interrupted")
38+
39+
@test OpenAPI.Clients.is_request_interrupted(ex1)
40+
@test !OpenAPI.Clients.is_request_interrupted(ex2)
41+
@test !OpenAPI.Clients.is_request_interrupted(ex3)
42+
43+
@test OpenAPI.Clients.is_request_interrupted(as_taskfailedexception(ex1))
44+
@test !OpenAPI.Clients.is_request_interrupted(as_taskfailedexception(ex2))
45+
@test !OpenAPI.Clients.is_request_interrupted(as_taskfailedexception(ex3))
46+
47+
@test OpenAPI.Clients.is_request_interrupted(CompositeException([ex1, ex2]))
48+
@test !OpenAPI.Clients.is_request_interrupted(CompositeException([ex2, ex3]))
49+
end
50+
3451
function OpenAPI.val_format(val::AbstractString, ::Val{:testformat})
3552
return val == "testvalue"
3653
end

0 commit comments

Comments
 (0)