Skip to content

Commit 1f5c4f2

Browse files
authored
fix and update tests, readme (#15)
* fix tests, add more tests * bump patch version and update README
1 parent 892b4b6 commit 1f5c4f2

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ keywords = ["Swagger", "OpenAPI", "REST"]
44
license = "MIT"
55
desc = "OpenAPI server and client helper for Julia"
66
authors = ["Tanmay Mohapatra <[email protected]>", "JuliaHub"]
7-
version = "0.1.4"
7+
version = "0.1.5"
88

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

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ The goal of OpenAPI is to define a standard, language-agnostic interface to REST
99

1010
Check out [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) for additional information about the OpenAPI project, including additional libraries with support for other languages and more.
1111

12+
> Note: This package supercedes the [Swagger.jl](https://github.com/JuliaComputing/Swagger.jl) package. OpenAPI.jl and the associated generator can address both OpenAPI 2.x (Swagger) and OpenAPI 3.x specifications. Code dependent on Swagger.jl would not directly work with OpenAPI.jl, but migration should not be too difficult.
13+
1214
## Code Generation
1315

1416
Use [instructions](https://openapi-generator.tech/docs/generators) provided for the Julia OpenAPI code generator plugin to generate Julia code.

test/client/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function runtests()
1414
test_longpoll_exception_check()
1515
test_request_interrupted_exception_check()
1616
test_date()
17+
test_misc()
1718
end
1819
@testset "Validations" begin
1920
test_validations()

test/client/utilstests.jl

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@ using OpenAPI.Clients
33
using Test
44
using Dates
55
using TimeZones
6+
using Base64
67

78
function test_date()
8-
dt_string = string(ZonedDateTime(now(), localzone()))
9-
dt = OpenAPI.str2zoneddatetime(dt_string)
9+
dt_now = now()
10+
dt_string = string(ZonedDateTime(dt_now, localzone()))
11+
dt = OpenAPI.str2zoneddatetime(convert(Vector{UInt8}, codeunits(dt_string)))
12+
@test dt == OpenAPI.str2zoneddatetime(dt_now)
1013
@test dt_string == string(dt)
1114

12-
dt_string = string(DateTime(now()))
13-
dt = OpenAPI.str2datetime(dt_string)
15+
dt_string = string(dt_now)
16+
dt = OpenAPI.str2datetime(convert(Vector{UInt8}, codeunits(dt_string)))
17+
@test dt == OpenAPI.str2datetime(dt_now)
1418
@test dt_string == string(dt)
1519

16-
dt_string = string(Date(now()))
17-
dt = OpenAPI.str2date(dt_string)
20+
dt_string = string(Date(dt_now))
21+
dt = OpenAPI.str2date(convert(Vector{UInt8}, codeunits(dt_string)))
22+
@test dt == OpenAPI.str2date(Date(dt_now))
1823
@test dt_string == string(dt)
1924
end
2025

@@ -90,11 +95,15 @@ function test_custom_format_validations()
9095
return nothing
9196
end
9297

93-
function test_numeric_format_validations()
94-
@test OpenAPI.val_format(typemax(Float32), ":float")
95-
@test OpenAPI.val_format(typemax(Float64), ":double")
98+
function test_format_validations()
99+
@test OpenAPI.val_format(typemax(Float32), "float")
100+
@test OpenAPI.val_format(typemax(Float64), "double")
96101
@test OpenAPI.val_multiple_of(10.0, 5.0)
97102
@test !OpenAPI.val_multiple_of(10.0, 3.0)
103+
104+
b64str = String(base64encode("test string"))
105+
@test OpenAPI.val_format(b64str, "byte")
106+
@test !OpenAPI.val_format("not base64", "byte")
98107
end
99108

100109
function test_validations()
@@ -144,7 +153,26 @@ function test_validations()
144153
@test_throws OpenAPI.ValidationException OpenAPI.validate_param("test_param", "test_model", :enum, [:a, :b, :c, :d], [:a, :b, :c])
145154

146155
# custom format Validations
156+
test_format_validations()
147157
test_custom_format_validations()
148-
test_numeric_format_validations()
158+
149159
return nothing
160+
end
161+
162+
struct InvalidModel <: OpenAPI.APIModel
163+
test::Any
164+
165+
function InvalidModel(; test=nothing)
166+
return new(test)
167+
end
168+
end
169+
170+
function test_misc()
171+
@test isa(OpenAPI.OpenAPIException("test"), Exception)
172+
@test_throws Exception OpenAPI.property_type(InvalidModel(), :test)
173+
174+
json = Dict{String,Any}()
175+
@test OpenAPI.from_json(Any, json) === json
176+
@test OpenAPI.from_json(String, json) == "{}"
177+
@test isa(OpenAPI.from_json(Dict{Any,Any}, json), Dict{Any,Any})
150178
end

0 commit comments

Comments
 (0)