From 02f72b83500344cb11ad6508b51cbec3b69e2ca4 Mon Sep 17 00:00:00 2001 From: vdayanand Date: Wed, 10 Jul 2024 17:28:54 +0530 Subject: [PATCH] query param support deepObject --- src/client.jl | 30 +++++- src/json.jl | 74 ++++++++++---- src/server.jl | 87 ++++++++++++---- test/client/param_serialize.jl | 45 +++++++++ test/client/runtests.jl | 5 +- .../DeepClient/.openapi-generator-ignore | 23 +++++ .../DeepClient/.openapi-generator/FILES | 9 ++ .../DeepClient/.openapi-generator/VERSION | 1 + test/deep_object/DeepClient/Project.toml | 17 ++++ test/deep_object/DeepClient/README.md | 40 ++++++++ .../docs/FindPetsByStatus200Response.md | 12 +++ .../docs/FindPetsByStatus200ResponseResult.md | 13 +++ .../docs/FindPetsByStatusStatusParameter.md | 13 +++ ...etsByStatusStatusParameterStatusesInner.md | 12 +++ ...StatusStatusParameterStatusesInnerInner.md | 12 +++ test/deep_object/DeepClient/docs/PetApi.md | 39 ++++++++ test/deep_object/DeepClient/src/DeepClient.jl | 16 +++ .../DeepClient/src/apis/api_PetApi.jl | 46 +++++++++ test/deep_object/DeepClient/src/deep.jl | 16 +++ .../DeepClient/src/modelincludes.jl | 5 + .../model_FindPetsByStatus200Response.jl | 30 ++++++ ...model_FindPetsByStatus200ResponseResult.jl | 34 +++++++ .../model_FindPetsByStatusStatusParameter.jl | 34 +++++++ ...etsByStatusStatusParameterStatusesInner.jl | 30 ++++++ ...StatusStatusParameterStatusesInnerInner.jl | 30 ++++++ .../DeepServer/.openapi-generator-ignore | 23 +++++ .../DeepServer/.openapi-generator/FILES | 9 ++ .../DeepServer/.openapi-generator/VERSION | 1 + test/deep_object/DeepServer/Project.toml | 17 ++++ test/deep_object/DeepServer/README.md | 58 +++++++++++ .../docs/FindPetsByStatus200Response.md | 12 +++ .../docs/FindPetsByStatus200ResponseResult.md | 13 +++ .../docs/FindPetsByStatusStatusParameter.md | 13 +++ ...etsByStatusStatusParameterStatusesInner.md | 12 +++ ...StatusStatusParameterStatusesInnerInner.md | 12 +++ test/deep_object/DeepServer/docs/PetApi.md | 38 +++++++ test/deep_object/DeepServer/src/DeepServer.jl | 54 ++++++++++ .../DeepServer/src/apis/api_PetApi.jl | 37 +++++++ test/deep_object/DeepServer/src/deep.jl | 54 ++++++++++ .../DeepServer/src/modelincludes.jl | 5 + .../model_FindPetsByStatus200Response.jl | 29 ++++++ ...model_FindPetsByStatus200ResponseResult.jl | 33 +++++++ .../model_FindPetsByStatusStatusParameter.jl | 33 +++++++ ...etsByStatusStatusParameterStatusesInner.jl | 29 ++++++ ...StatusStatusParameterStatusesInnerInner.jl | 29 ++++++ test/deep_object/deep.yaml | 62 ++++++++++++ test/deep_object/deep_client.jl | 24 +++++ test/deep_object/deep_server.jl | 38 +++++++ test/param_deserialize.jl | 99 +++++++++++++++++++ test/runtests.jl | 37 +++++-- .../petstore/src/apis/api_PetApi.jl | 16 +-- test/testutils.jl | 1 - 52 files changed, 1404 insertions(+), 57 deletions(-) create mode 100644 test/client/param_serialize.jl create mode 100644 test/deep_object/DeepClient/.openapi-generator-ignore create mode 100644 test/deep_object/DeepClient/.openapi-generator/FILES create mode 100644 test/deep_object/DeepClient/.openapi-generator/VERSION create mode 100644 test/deep_object/DeepClient/Project.toml create mode 100644 test/deep_object/DeepClient/README.md create mode 100644 test/deep_object/DeepClient/docs/FindPetsByStatus200Response.md create mode 100644 test/deep_object/DeepClient/docs/FindPetsByStatus200ResponseResult.md create mode 100644 test/deep_object/DeepClient/docs/FindPetsByStatusStatusParameter.md create mode 100644 test/deep_object/DeepClient/docs/FindPetsByStatusStatusParameterStatusesInner.md create mode 100644 test/deep_object/DeepClient/docs/FindPetsByStatusStatusParameterStatusesInnerInner.md create mode 100644 test/deep_object/DeepClient/docs/PetApi.md create mode 100644 test/deep_object/DeepClient/src/DeepClient.jl create mode 100644 test/deep_object/DeepClient/src/apis/api_PetApi.jl create mode 100644 test/deep_object/DeepClient/src/deep.jl create mode 100644 test/deep_object/DeepClient/src/modelincludes.jl create mode 100644 test/deep_object/DeepClient/src/models/model_FindPetsByStatus200Response.jl create mode 100644 test/deep_object/DeepClient/src/models/model_FindPetsByStatus200ResponseResult.jl create mode 100644 test/deep_object/DeepClient/src/models/model_FindPetsByStatusStatusParameter.jl create mode 100644 test/deep_object/DeepClient/src/models/model_FindPetsByStatusStatusParameterStatusesInner.jl create mode 100644 test/deep_object/DeepClient/src/models/model_FindPetsByStatusStatusParameterStatusesInnerInner.jl create mode 100644 test/deep_object/DeepServer/.openapi-generator-ignore create mode 100644 test/deep_object/DeepServer/.openapi-generator/FILES create mode 100644 test/deep_object/DeepServer/.openapi-generator/VERSION create mode 100644 test/deep_object/DeepServer/Project.toml create mode 100644 test/deep_object/DeepServer/README.md create mode 100644 test/deep_object/DeepServer/docs/FindPetsByStatus200Response.md create mode 100644 test/deep_object/DeepServer/docs/FindPetsByStatus200ResponseResult.md create mode 100644 test/deep_object/DeepServer/docs/FindPetsByStatusStatusParameter.md create mode 100644 test/deep_object/DeepServer/docs/FindPetsByStatusStatusParameterStatusesInner.md create mode 100644 test/deep_object/DeepServer/docs/FindPetsByStatusStatusParameterStatusesInnerInner.md create mode 100644 test/deep_object/DeepServer/docs/PetApi.md create mode 100644 test/deep_object/DeepServer/src/DeepServer.jl create mode 100644 test/deep_object/DeepServer/src/apis/api_PetApi.jl create mode 100644 test/deep_object/DeepServer/src/deep.jl create mode 100644 test/deep_object/DeepServer/src/modelincludes.jl create mode 100644 test/deep_object/DeepServer/src/models/model_FindPetsByStatus200Response.jl create mode 100644 test/deep_object/DeepServer/src/models/model_FindPetsByStatus200ResponseResult.jl create mode 100644 test/deep_object/DeepServer/src/models/model_FindPetsByStatusStatusParameter.jl create mode 100644 test/deep_object/DeepServer/src/models/model_FindPetsByStatusStatusParameterStatusesInner.jl create mode 100644 test/deep_object/DeepServer/src/models/model_FindPetsByStatusStatusParameterStatusesInnerInner.jl create mode 100644 test/deep_object/deep.yaml create mode 100644 test/deep_object/deep_client.jl create mode 100644 test/deep_object/deep_server.jl create mode 100644 test/param_deserialize.jl diff --git a/src/client.jl b/src/client.jl index 0e5afaa..1a755f8 100644 --- a/src/client.jl +++ b/src/client.jl @@ -77,7 +77,7 @@ end function get_api_return_type(return_types::Dict{Regex,Type}, ::Nothing, response_data::String) # this is the async case, where we do not have the response code yet - # in such cases we look for the 200 response code + # in such cases we look for the 200 response code return get_api_return_type(return_types, 200, response_data) end function get_api_return_type(return_types::Dict{Regex,Type}, response_code::Integer, response_data::String) @@ -191,7 +191,7 @@ set_user_agent(client::Client, ua::String) = set_header(client, "User-Agent", ua Set the Cookie header to be sent with all API calls. """ set_cookie(client::Client, ck::String) = set_header(client, "Cookie", ck) - + """ set_header(client::Client, name::String, value::String) @@ -292,7 +292,12 @@ function set_header_content_type(ctx::Ctx, ctypes::Vector{String}) end set_param(params::Dict{String,String}, name::String, value::Nothing; collection_format=",") = nothing -function set_param(params::Dict{String,String}, name::String, value; collection_format=",") +function set_param(params::Dict{String,String}, name::String, value; collection_format=",", style="form", is_explode=false) + deep_explode = style == "deepObject" && is_explode + if deep_explode + merge!(params, deep_object_serialize(Dict(name=>value))) + return nothing + end if isa(value, Dict) # implements the default serialization (style=form, explode=true, location=queryparams) # as mentioned in https://swagger.io/docs/specification/serialization/ @@ -789,7 +794,7 @@ function storefile(api_call::Function; folder::AbstractString = pwd(), filename::Union{String,Nothing} = nothing, )::Tuple{Any,ApiResponse,String} - + result, http_response = api_call() if isnothing(filename) @@ -828,4 +833,21 @@ function extract_filename(resp::Downloads.Response)::String return string("response", extension_from_mime(MIME(content_type_str))) end +function deep_object_serialize(dict::Dict, parent_key::String = "") + parts = Pair[] + for (key, value) in dict + new_key = parent_key == "" ? key : "$parent_key[$key]" + if isa(value, Dict) + append!(parts, collect(deep_object_serialize(value, new_key))) + elseif isa(value, Vector) + for (i, v) in enumerate(value) + push!(parts, "$new_key[$(i-1)]"=>"$v") + end + else + push!(parts, "$new_key"=>"$value") + end + end + return Dict(parts) +end + end # module Clients diff --git a/src/json.jl b/src/json.jl index 66b0563..c93789b 100644 --- a/src/json.jl +++ b/src/json.jl @@ -34,41 +34,77 @@ function lower(o::T) where {T<:UnionAPIModel} end end +struct StyleCtx + name::String + is_explode::Bool +end + +is_deep_explode(sctx::StyleCtx) = sctx.name == "deepObject" && sctx.is_explode + +function deep_object_to_array(src::Dict) + keys_are_int = all(key -> occursin(r"^\d+$", key), keys(src)) + if keys_are_int + sorted_keys = sort(collect(keys(src)), by=x->parse(Int, x)) + final = [] + for key in sorted_keys + push!(final, src[key]) + end + return final + else + src + end +end + to_json(o) = JSON.json(o) -from_json(::Type{Union{Nothing,T}}, json::Dict{String,Any}) where {T} = from_json(T, json) -from_json(::Type{T}, json::Dict{String,Any}) where {T} = from_json(T(), json) -from_json(::Type{T}, json::Dict{String,Any}) where {T <: Dict} = convert(T, json) -from_json(::Type{T}, j::Dict{String,Any}) where {T <: String} = to_json(j) -from_json(::Type{Any}, j::Dict{String,Any}) = j +from_json(::Type{Union{Nothing,T}}, json::Dict{String,Any}; stylectx=nothing) where {T} = from_json(T, json; stylectx) +from_json(::Type{T}, json::Dict{String,Any}; stylectx=nothing) where {T} = from_json(T(), json; stylectx) +from_json(::Type{T}, json::Dict{String,Any}; stylectx=nothing) where {T <: Dict} = convert(T, json) +from_json(::Type{T}, j::Dict{String,Any}; stylectx=nothing) where {T <: String} = to_json(j) +from_json(::Type{Any}, j::Dict{String,Any}; stylectx=nothing) = j +from_json(::Type{Vector{T}}, j::Vector{Any}; stylectx=nothing) where {T} = j + +function from_json(::Type{Vector{T}}, json::Dict{String, Any}; stylectx=nothing) where {T} + if !isnothing(stylectx) && is_deep_explode(stylectx) + cvt = deep_object_to_array(json) + if isa(cvt, Vector) + return from_json(Vector{T}, cvt; stylectx) + else + return from_json(T, json; stylectx) + end + else + return from_json(T, json; stylectx) + end +end -function from_json(o::T, json::Dict{String,Any}) where {T <: UnionAPIModel} - return from_json(o, :value, json) +function from_json(o::T, json::Dict{String,Any};stylectx=nothing) where {T <: UnionAPIModel} + return from_json(o, :value, json;stylectx) end -from_json(::Type{T}, val::Union{String,Real}) where {T <: UnionAPIModel} = T(val) -function from_json(o::T, val::Union{String,Real}) where {T <: UnionAPIModel} +from_json(::Type{T}, val::Union{String,Real};stylectx=nothing) where {T <: UnionAPIModel} = T(val) +function from_json(o::T, val::Union{String,Real};stylectx=nothing) where {T <: UnionAPIModel} o.value = val return o end -function from_json(o::T, json::Dict{String,Any}) where {T <: APIModel} +function from_json(o::T, json::Dict{String,Any};stylectx=nothing) where {T <: APIModel} jsonkeys = [Symbol(k) for k in keys(json)] for name in intersect(propertynames(o), jsonkeys) - from_json(o, name, json[String(name)]) + from_json(o, name, json[String(name)];stylectx) end return o end -function from_json(o::T, name::Symbol, json::Dict{String,Any}) where {T <: APIModel} +function from_json(o::T, name::Symbol, json::Dict{String,Any};stylectx=nothing) where {T <: APIModel} ftype = (T <: UnionAPIModel) ? property_type(T, name, json) : property_type(T, name) - fval = from_json(ftype, json) + fval = from_json(ftype, json; stylectx) setfield!(o, name, convert(ftype, fval)) return o end -function from_json(o::T, name::Symbol, v) where {T <: APIModel} +function from_json(o::T, name::Symbol, v; stylectx=nothing) where {T <: APIModel} ftype = (T <: UnionAPIModel) ? property_type(T, name, Dict{String,Any}()) : property_type(T, name) + atype = isa(ftype, Union) ? ((ftype.a === Nothing) ? ftype.b : ftype.a) : ftype if ftype === Any setfield!(o, name, v) elseif ZonedDateTime <: ftype @@ -80,13 +116,15 @@ function from_json(o::T, name::Symbol, v) where {T <: APIModel} elseif String <: ftype && isa(v, Real) # string numbers can have format specifiers that allow numbers, ensure they are converted to strings setfield!(o, name, string(v)) + elseif atype <: Real && isa(v, AbstractString) + setfield!(o, name, parse(atype, v)) else setfield!(o, name, convert(ftype, v)) end return o end -function from_json(o::T, name::Symbol, v::Vector) where {T <: APIModel} +function from_json(o::T, name::Symbol, v::Vector; stylectx=nothing) 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) @@ -111,7 +149,7 @@ function from_json(o::T, name::Symbol, v::Vector) where {T <: APIModel} if (vtype <: Vector) && (veltype <: OpenAPI.UnionAPIModel) vec = veltype[] for vecelem in v - push!(vec, from_json(veltype(), :value, vecelem)) + push!(vec, from_json(veltype(), :value, vecelem;stylectx)) end setfield!(o, name, vec) elseif (vtype <: Vector) && (veltype <: OpenAPI.APIModel) @@ -129,7 +167,7 @@ function from_json(o::T, name::Symbol, v::Vector) where {T <: APIModel} return o end -function from_json(o::T, name::Symbol, ::Nothing) where {T <: APIModel} +function from_json(o::T, name::Symbol, ::Nothing;stylectx=nothing) where {T <: APIModel} setfield!(o, name, nothing) return o -end \ No newline at end of file +end diff --git a/src/server.jl b/src/server.jl index 2e60526..16184d6 100644 --- a/src/server.jl +++ b/src/server.jl @@ -3,7 +3,7 @@ module Servers using JSON using HTTP -import ..OpenAPI: APIModel, ValidationException, from_json, to_json +import ..OpenAPI: APIModel, ValidationException, from_json, to_json, deep_object_to_array, StyleCtx, is_deep_explode function middleware(impl, read, validate, invoke; init=nothing, @@ -29,6 +29,38 @@ end ############################## # server parameter conversions ############################## +struct Param + keylist::Vector{String} + value::String +end + +function parse_query_dict(query_dict::Dict{String, String})::Vector{Param} + params = Vector{Param}() + for (key, value) in query_dict + keylist = replace.(split(key, "["), "]"=>"") + push!(params, Param(keylist, value)) + end + + return params +end + +function convert_to_dict(params::Vector{Param})::Dict{String, Any} + deserialized_dict = Dict{String, Any}() + + for param in params + current = deserialized_dict + for part in param.keylist[1:end-1] + current = get!(current, part, Dict{String, Any}()) + end + current[param.keylist[end]] = param.value + end + return deserialized_dict +end + +function deep_dict_repr(qp::Dict) + convert_to_dict(parse_query_dict(qp)) +end + function get_param(source::Dict, name::String, required::Bool) val = get(source, name, nothing) if required && isnothing(val) @@ -48,36 +80,50 @@ function get_param(source::Vector{HTTP.Forms.Multipart}, name::String, required: end end - -function to_param_type(::Type{T}, strval::String) where {T <: Number} +function to_param_type(::Type{T}, strval::String; stylectx=nothing) where {T <: Number} parse(T, strval) end -to_param_type(::Type{T}, val::T) where {T} = val -to_param_type(::Type{T}, ::Nothing) where {T} = nothing -to_param_type(::Type{String}, val::Vector{UInt8}) = String(copy(val)) -to_param_type(::Type{Vector{UInt8}}, val::String) = convert(Vector{UInt8}, copy(codeunits(val))) -to_param_type(::Type{Vector{T}}, val::Vector{T}, _collection_format::Union{String,Nothing}) where {T} = val +to_param_type(::Type{T}, val::T; stylectx=nothing) where {T} = val +to_param_type(::Type{T}, ::Nothing; stylectx=nothing) where {T} = nothing +to_param_type(::Type{String}, val::Vector{UInt8}; stylectx=nothing) = String(copy(val)) +to_param_type(::Type{Vector{UInt8}}, val::String; stylectx=nothing) = convert(Vector{UInt8}, copy(codeunits(val))) +to_param_type(::Type{Vector{T}}, val::Vector{T}, _collection_format::Union{String,Nothing}; stylectx=nothing) where {T} = val +to_param_type(::Type{Vector{T}}, json::Vector{Any}; stylectx=nothing) where {T} = [to_param_type(T, x; stylectx) for x in json] + +function to_param_type(::Type{Vector{T}}, json::Dict{String, Any}; stylectx=nothing) where {T} + if !isnothing(stylectx) && is_deep_explode(stylectx) + cvt = deep_object_to_array(json) + if isa(cvt, Vector) + to_param_type(Vector{T}, cvt; stylectx) + end + end + error("Unable to convert $json to $(Vector{T})") +end -function to_param_type(::Type{T}, strval::String) where {T <: APIModel} - from_json(T, JSON.parse(strval)) +function to_param_type(::Type{T}, strval::String; stylectx=nothing) where {T <: APIModel} + from_json(T, JSON.parse(strval); stylectx) end -function to_param_type(::Type{T}, json::Dict{String,Any}) where {T <: APIModel} - from_json(T, json) +function to_param_type(::Type{T}, json::Dict{String,Any}; stylectx=nothing) where {T <: APIModel} + from_json(T, json; stylectx) end -function to_param_type(::Type{Vector{T}}, strval::String, delim::String) where {T} +function to_param_type(::Type{Vector{T}}, strval::String, delim::String; stylectx=nothing) where {T} elems = string.(strip.(split(strval, delim))) - return map(x->to_param_type(T, x), elems) + return map(x->to_param_type(T, x; stylectx), elems) end -function to_param_type(::Type{Vector{T}}, strval::String) where {T} +function to_param_type(::Type{Vector{T}}, strval::String; stylectx=nothing) where {T} elems = JSON.parse(strval) - return map(x->to_param_type(T, x), elems) + return map(x->to_param_type(T, x; stylectx), elems) end -function to_param(T, source::Dict, name::String; required::Bool=false, collection_format::Union{String,Nothing}=",", multipart::Bool=false, isfile::Bool=false) +function to_param(T, source::Dict, name::String; required::Bool=false, collection_format::Union{String,Nothing}=",", multipart::Bool=false, isfile::Bool=false, style::String="form", is_explode::Bool=true) + deep_explode = style == "deepObject" && is_explode + if deep_explode + source = deep_dict_repr(source) + end param = get_param(source, name, required) if param === nothing return nothing @@ -86,10 +132,13 @@ function to_param(T, source::Dict, name::String; required::Bool=false, collectio # param is a Multipart param = isfile ? param.data : String(param.data) end + if deep_explode + return to_param_type(T, param; stylectx=StyleCtx(style, is_explode)) + end if T <: Vector - return to_param_type(T, param, collection_format) + to_param_type(T, param, collection_format) else - return to_param_type(T, param) + to_param_type(T, param) end end diff --git a/test/client/param_serialize.jl b/test/client/param_serialize.jl new file mode 100644 index 0000000..c6630aa --- /dev/null +++ b/test/client/param_serialize.jl @@ -0,0 +1,45 @@ +using OpenAPI.Clients: deep_object_serialize + +@testset "Test deep_object_serialize" begin + @testset "Single level object" begin + dict = Dict("key1" => "value1", "key2" => "value2") + expected = Dict("key1" => "value1", "key2" => "value2") + @test deep_object_serialize(dict) == expected + end + + @testset "Nested object" begin + dict = Dict("outer" => Dict("inner" => "value")) + expected = Dict("outer[inner]" => "value") + @test deep_object_serialize(dict) == expected + end + + @testset "Deeply nested object" begin + dict = Dict("a" => Dict("b" => Dict("c" => Dict("d" => "value")))) + expected = Dict("a[b][c][d]" => "value") + @test deep_object_serialize(dict) == expected + end + + @testset "Multiple nested objects" begin + dict = Dict("a" => Dict("b" => "value1", "c" => "value2")) + expected = Dict("a[b]" => "value1", "a[c]" => "value2") + @test deep_object_serialize(dict) == expected + end + + @testset "Dictionary represented array" begin + dict = Dict("a" => ["value1", "value2"]) + expected = Dict("a[0]" => "value1", "a[1]" => "value2") + @test deep_object_serialize(dict) == expected + end + + @testset "Mixed structure" begin + dict = Dict("a" => Dict("b" => "value1", "c" => ["value2", "value3"])) + expected = Dict("a[b]" => "value1", "a[c][0]" => "value2", "a[c][1]" => "value3") + @test deep_object_serialize(dict) == expected + end + + @testset "Blank values" begin + dict = Dict("a" => Dict("b" => "", "c" => "")) + expected = Dict("a[b]" => "", "a[c]" => "") + @test deep_object_serialize(dict) == expected + end +end diff --git a/test/client/runtests.jl b/test/client/runtests.jl index af4a380..640bbb2 100644 --- a/test/client/runtests.jl +++ b/test/client/runtests.jl @@ -11,6 +11,9 @@ include("openapigenerator_petstore_v3/runtests.jl") function runtests(; skip_petstore=false, test_file_upload=false) @testset "Client" begin + @testset "deepObj query param serialization" begin + include("client/param_serialize.jl") + end @testset "Utils" begin test_longpoll_exception_check() test_request_interrupted_exception_check() @@ -52,4 +55,4 @@ function run_openapigenerator_tests(; test_file_upload=false) end end -end # module OpenAPIClientTests \ No newline at end of file +end # module OpenAPIClientTests diff --git a/test/deep_object/DeepClient/.openapi-generator-ignore b/test/deep_object/DeepClient/.openapi-generator-ignore new file mode 100644 index 0000000..7484ee5 --- /dev/null +++ b/test/deep_object/DeepClient/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/test/deep_object/DeepClient/.openapi-generator/FILES b/test/deep_object/DeepClient/.openapi-generator/FILES new file mode 100644 index 0000000..e0018f3 --- /dev/null +++ b/test/deep_object/DeepClient/.openapi-generator/FILES @@ -0,0 +1,9 @@ +README.md +docs/FindPetsByStatus200Response.md +docs/FindPetsByStatusStatusParameter.md +docs/PetApi.md +src/DeepClient.jl +src/apis/api_PetApi.jl +src/modelincludes.jl +src/models/model_FindPetsByStatus200Response.jl +src/models/model_FindPetsByStatusStatusParameter.jl diff --git a/test/deep_object/DeepClient/.openapi-generator/VERSION b/test/deep_object/DeepClient/.openapi-generator/VERSION new file mode 100644 index 0000000..757e674 --- /dev/null +++ b/test/deep_object/DeepClient/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.0.0-SNAPSHOT \ No newline at end of file diff --git a/test/deep_object/DeepClient/Project.toml b/test/deep_object/DeepClient/Project.toml new file mode 100644 index 0000000..6925b14 --- /dev/null +++ b/test/deep_object/DeepClient/Project.toml @@ -0,0 +1,17 @@ +name = "DeepClient" +uuid = "a6d6279c-b61a-4cd3-8410-d9d61a86b071" +authors = ["vdayanand "] +version = "0.1.0" + +[deps] +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" +HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3" +OpenAPI = "d5e62ea6-ddf3-4d43-8e4c-ad5e6c8bfd7d" +TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53" +URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/test/deep_object/DeepClient/README.md b/test/deep_object/DeepClient/README.md new file mode 100644 index 0000000..0c1c45a --- /dev/null +++ b/test/deep_object/DeepClient/README.md @@ -0,0 +1,40 @@ +# Julia API client for DeepClient + +This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + +## Overview +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client. + +- API version: 1.0.0 +- Build package: org.openapitools.codegen.languages.JuliaClientCodegen + + +## Installation +Place the Julia files generated under the `src` folder in your Julia project. Include DeepClient.jl in the project code. +It would include the module named DeepClient. + +Documentation is generated as markdown files under the `docs` folder. You can include them in your project documentation. +Documentation is also embedded in Julia which can be used with a Julia specific documentation generator. + +## API Endpoints + +Class | Method +------------ | ------------- +*PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status)
**GET** /pet/findByStatus
Finds Pets by status + + +## Models + + - [FindPetsByStatus200Response](docs/FindPetsByStatus200Response.md) + - [FindPetsByStatusStatusParameter](docs/FindPetsByStatusStatusParameter.md) + + + +## Authorization +Endpoints do not require authorization. + + +## Author + + + diff --git a/test/deep_object/DeepClient/docs/FindPetsByStatus200Response.md b/test/deep_object/DeepClient/docs/FindPetsByStatus200Response.md new file mode 100644 index 0000000..7747550 --- /dev/null +++ b/test/deep_object/DeepClient/docs/FindPetsByStatus200Response.md @@ -0,0 +1,12 @@ +# FindPetsByStatus200Response + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**result** | [***FindPetsByStatusStatusParameter**](FindPetsByStatusStatusParameter.md) | | [optional] [default to nothing] + + +[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md) + + diff --git a/test/deep_object/DeepClient/docs/FindPetsByStatus200ResponseResult.md b/test/deep_object/DeepClient/docs/FindPetsByStatus200ResponseResult.md new file mode 100644 index 0000000..b388b95 --- /dev/null +++ b/test/deep_object/DeepClient/docs/FindPetsByStatus200ResponseResult.md @@ -0,0 +1,13 @@ +# FindPetsByStatus200ResponseResult + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **String** | | [optional] [default to nothing] +**statuses** | [**Vector{FindPetsByStatusStatusParameterStatusesInnerInner}**](FindPetsByStatusStatusParameterStatusesInnerInner.md) | | [optional] [default to nothing] + + +[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md) + + diff --git a/test/deep_object/DeepClient/docs/FindPetsByStatusStatusParameter.md b/test/deep_object/DeepClient/docs/FindPetsByStatusStatusParameter.md new file mode 100644 index 0000000..343827b --- /dev/null +++ b/test/deep_object/DeepClient/docs/FindPetsByStatusStatusParameter.md @@ -0,0 +1,13 @@ +# FindPetsByStatusStatusParameter + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **String** | | [optional] [default to nothing] +**statuses** | **Vector{String}** | | [optional] [default to nothing] + + +[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md) + + diff --git a/test/deep_object/DeepClient/docs/FindPetsByStatusStatusParameterStatusesInner.md b/test/deep_object/DeepClient/docs/FindPetsByStatusStatusParameterStatusesInner.md new file mode 100644 index 0000000..f435999 --- /dev/null +++ b/test/deep_object/DeepClient/docs/FindPetsByStatusStatusParameterStatusesInner.md @@ -0,0 +1,12 @@ +# FindPetsByStatusStatusParameterStatusesInner + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**type** | **String** | | [optional] [default to nothing] + + +[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md) + + diff --git a/test/deep_object/DeepClient/docs/FindPetsByStatusStatusParameterStatusesInnerInner.md b/test/deep_object/DeepClient/docs/FindPetsByStatusStatusParameterStatusesInnerInner.md new file mode 100644 index 0000000..4229b9a --- /dev/null +++ b/test/deep_object/DeepClient/docs/FindPetsByStatusStatusParameterStatusesInnerInner.md @@ -0,0 +1,12 @@ +# FindPetsByStatusStatusParameterStatusesInnerInner + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**type** | **String** | | [optional] [default to nothing] + + +[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md) + + diff --git a/test/deep_object/DeepClient/docs/PetApi.md b/test/deep_object/DeepClient/docs/PetApi.md new file mode 100644 index 0000000..05dee55 --- /dev/null +++ b/test/deep_object/DeepClient/docs/PetApi.md @@ -0,0 +1,39 @@ +# PetApi + +All URIs are relative to *http://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**find_pets_by_status**](PetApi.md#find_pets_by_status) | **GET** /pet/findByStatus | Finds Pets by status + + +# **find_pets_by_status** +> find_pets_by_status(_api::PetApi, status::FindPetsByStatusStatusParameter; _mediaType=nothing) -> FindPetsByStatus200Response, OpenAPI.Clients.ApiResponse
+> find_pets_by_status(_api::PetApi, response_stream::Channel, status::FindPetsByStatusStatusParameter; _mediaType=nothing) -> Channel{ FindPetsByStatus200Response }, OpenAPI.Clients.ApiResponse + +Finds Pets by status + +Multiple status values can be provided with comma separated strings + +### Required Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **_api** | **PetApi** | API context | +**status** | [**FindPetsByStatusStatusParameter**](.md)| Status values that need to be considered for filter | [default to nothing] + +### Return type + +[**FindPetsByStatus200Response**](FindPetsByStatus200Response.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + diff --git a/test/deep_object/DeepClient/src/DeepClient.jl b/test/deep_object/DeepClient/src/DeepClient.jl new file mode 100644 index 0000000..df7bca5 --- /dev/null +++ b/test/deep_object/DeepClient/src/DeepClient.jl @@ -0,0 +1,16 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + +module DeepClient + +using Dates, TimeZones +using OpenAPI +using OpenAPI.Clients + +const API_VERSION = "1.0.0" + +include("modelincludes.jl") + +include("apis/api_PetApi.jl") + +end # module DeepClient diff --git a/test/deep_object/DeepClient/src/apis/api_PetApi.jl b/test/deep_object/DeepClient/src/apis/api_PetApi.jl new file mode 100644 index 0000000..8fef975 --- /dev/null +++ b/test/deep_object/DeepClient/src/apis/api_PetApi.jl @@ -0,0 +1,46 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + +struct PetApi <: OpenAPI.APIClientImpl + client::OpenAPI.Clients.Client +end + +""" +The default API base path for APIs in `PetApi`. +This can be used to construct the `OpenAPI.Clients.Client` instance. +""" +basepath(::Type{ PetApi }) = "http://petstore.swagger.io/v2" + +const _returntypes_find_pets_by_status_PetApi = Dict{Regex,Type}( + Regex("^" * replace("200", "x"=>".") * "\$") => FindPetsByStatus200Response, + Regex("^" * replace("400", "x"=>".") * "\$") => Nothing, +) + +function _oacinternal_find_pets_by_status(_api::PetApi, status::FindPetsByStatusStatusParameter; _mediaType=nothing) + _ctx = OpenAPI.Clients.Ctx(_api.client, "GET", _returntypes_find_pets_by_status_PetApi, "/pet/findByStatus", []) + OpenAPI.Clients.set_param(_ctx.query, "status", status;style="deepObject", is_explode=true) # type FindPetsByStatusStatusParameter + OpenAPI.Clients.set_header_accept(_ctx, ["application/json", ]) + OpenAPI.Clients.set_header_content_type(_ctx, (_mediaType === nothing) ? [] : [_mediaType]) + return _ctx +end + +@doc raw"""Finds Pets by status + +Multiple status values can be provided with comma separated strings + +Params: +- status::FindPetsByStatusStatusParameter (required) + +Return: FindPetsByStatus200Response, OpenAPI.Clients.ApiResponse +""" +function find_pets_by_status(_api::PetApi, status::FindPetsByStatusStatusParameter; _mediaType=nothing) + _ctx = _oacinternal_find_pets_by_status(_api, status; _mediaType=_mediaType) + return OpenAPI.Clients.exec(_ctx) +end + +function find_pets_by_status(_api::PetApi, response_stream::Channel, status::FindPetsByStatusStatusParameter; _mediaType=nothing) + _ctx = _oacinternal_find_pets_by_status(_api, status; _mediaType=_mediaType) + return OpenAPI.Clients.exec(_ctx, response_stream) +end + +export find_pets_by_status diff --git a/test/deep_object/DeepClient/src/deep.jl b/test/deep_object/DeepClient/src/deep.jl new file mode 100644 index 0000000..2088dc6 --- /dev/null +++ b/test/deep_object/DeepClient/src/deep.jl @@ -0,0 +1,16 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + +module deep + +using Dates, TimeZones +using OpenAPI +using OpenAPI.Clients + +const API_VERSION = "1.0.0" + +include("modelincludes.jl") + +include("apis/api_PetApi.jl") + +end # module deep diff --git a/test/deep_object/DeepClient/src/modelincludes.jl b/test/deep_object/DeepClient/src/modelincludes.jl new file mode 100644 index 0000000..74221b3 --- /dev/null +++ b/test/deep_object/DeepClient/src/modelincludes.jl @@ -0,0 +1,5 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + +include("models/model_FindPetsByStatus200Response.jl") +include("models/model_FindPetsByStatusStatusParameter.jl") diff --git a/test/deep_object/DeepClient/src/models/model_FindPetsByStatus200Response.jl b/test/deep_object/DeepClient/src/models/model_FindPetsByStatus200Response.jl new file mode 100644 index 0000000..76efe04 --- /dev/null +++ b/test/deep_object/DeepClient/src/models/model_FindPetsByStatus200Response.jl @@ -0,0 +1,30 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + + +@doc raw"""findPetsByStatus_200_response + + FindPetsByStatus200Response(; + result=nothing, + ) + + - result::FindPetsByStatusStatusParameter +""" +Base.@kwdef mutable struct FindPetsByStatus200Response <: OpenAPI.APIModel + result = nothing # spec type: Union{ Nothing, FindPetsByStatusStatusParameter } + + function FindPetsByStatus200Response(result, ) + OpenAPI.validate_property(FindPetsByStatus200Response, Symbol("result"), result) + return new(result, ) + end +end # type FindPetsByStatus200Response + +const _property_types_FindPetsByStatus200Response = Dict{Symbol,String}(Symbol("result")=>"FindPetsByStatusStatusParameter", ) +OpenAPI.property_type(::Type{ FindPetsByStatus200Response }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_FindPetsByStatus200Response[name]))} + +function check_required(o::FindPetsByStatus200Response) + true +end + +function OpenAPI.validate_property(::Type{ FindPetsByStatus200Response }, name::Symbol, val) +end diff --git a/test/deep_object/DeepClient/src/models/model_FindPetsByStatus200ResponseResult.jl b/test/deep_object/DeepClient/src/models/model_FindPetsByStatus200ResponseResult.jl new file mode 100644 index 0000000..325cad5 --- /dev/null +++ b/test/deep_object/DeepClient/src/models/model_FindPetsByStatus200ResponseResult.jl @@ -0,0 +1,34 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + + +@doc raw"""findPetsByStatus_200_response_result + + FindPetsByStatus200ResponseResult(; + name=nothing, + statuses=nothing, + ) + + - name::String + - statuses::Vector{FindPetsByStatusStatusParameterStatusesInnerInner} +""" +Base.@kwdef mutable struct FindPetsByStatus200ResponseResult <: OpenAPI.APIModel + name::Union{Nothing, String} = nothing + statuses::Union{Nothing, Vector} = nothing # spec type: Union{ Nothing, Vector{FindPetsByStatusStatusParameterStatusesInnerInner} } + + function FindPetsByStatus200ResponseResult(name, statuses, ) + OpenAPI.validate_property(FindPetsByStatus200ResponseResult, Symbol("name"), name) + OpenAPI.validate_property(FindPetsByStatus200ResponseResult, Symbol("statuses"), statuses) + return new(name, statuses, ) + end +end # type FindPetsByStatus200ResponseResult + +const _property_types_FindPetsByStatus200ResponseResult = Dict{Symbol,String}(Symbol("name")=>"String", Symbol("statuses")=>"Vector{FindPetsByStatusStatusParameterStatusesInnerInner}", ) +OpenAPI.property_type(::Type{ FindPetsByStatus200ResponseResult }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_FindPetsByStatus200ResponseResult[name]))} + +function check_required(o::FindPetsByStatus200ResponseResult) + true +end + +function OpenAPI.validate_property(::Type{ FindPetsByStatus200ResponseResult }, name::Symbol, val) +end diff --git a/test/deep_object/DeepClient/src/models/model_FindPetsByStatusStatusParameter.jl b/test/deep_object/DeepClient/src/models/model_FindPetsByStatusStatusParameter.jl new file mode 100644 index 0000000..15507e3 --- /dev/null +++ b/test/deep_object/DeepClient/src/models/model_FindPetsByStatusStatusParameter.jl @@ -0,0 +1,34 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + + +@doc raw"""findPetsByStatus_status_parameter + + FindPetsByStatusStatusParameter(; + name=nothing, + statuses=nothing, + ) + + - name::String + - statuses::Vector{String} +""" +Base.@kwdef mutable struct FindPetsByStatusStatusParameter <: OpenAPI.APIModel + name::Union{Nothing, String} = nothing + statuses::Union{Nothing, Vector{String}} = nothing + + function FindPetsByStatusStatusParameter(name, statuses, ) + OpenAPI.validate_property(FindPetsByStatusStatusParameter, Symbol("name"), name) + OpenAPI.validate_property(FindPetsByStatusStatusParameter, Symbol("statuses"), statuses) + return new(name, statuses, ) + end +end # type FindPetsByStatusStatusParameter + +const _property_types_FindPetsByStatusStatusParameter = Dict{Symbol,String}(Symbol("name")=>"String", Symbol("statuses")=>"Vector{String}", ) +OpenAPI.property_type(::Type{ FindPetsByStatusStatusParameter }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_FindPetsByStatusStatusParameter[name]))} + +function check_required(o::FindPetsByStatusStatusParameter) + true +end + +function OpenAPI.validate_property(::Type{ FindPetsByStatusStatusParameter }, name::Symbol, val) +end diff --git a/test/deep_object/DeepClient/src/models/model_FindPetsByStatusStatusParameterStatusesInner.jl b/test/deep_object/DeepClient/src/models/model_FindPetsByStatusStatusParameterStatusesInner.jl new file mode 100644 index 0000000..b5eb6a5 --- /dev/null +++ b/test/deep_object/DeepClient/src/models/model_FindPetsByStatusStatusParameterStatusesInner.jl @@ -0,0 +1,30 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + + +@doc raw"""findPetsByStatus_status_parameter_statuses_inner + + FindPetsByStatusStatusParameterStatusesInner(; + type=nothing, + ) + + - type::String +""" +Base.@kwdef mutable struct FindPetsByStatusStatusParameterStatusesInner <: OpenAPI.APIModel + type::Union{Nothing, String} = nothing + + function FindPetsByStatusStatusParameterStatusesInner(type, ) + OpenAPI.validate_property(FindPetsByStatusStatusParameterStatusesInner, Symbol("type"), type) + return new(type, ) + end +end # type FindPetsByStatusStatusParameterStatusesInner + +const _property_types_FindPetsByStatusStatusParameterStatusesInner = Dict{Symbol,String}(Symbol("type")=>"String", ) +OpenAPI.property_type(::Type{ FindPetsByStatusStatusParameterStatusesInner }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_FindPetsByStatusStatusParameterStatusesInner[name]))} + +function check_required(o::FindPetsByStatusStatusParameterStatusesInner) + true +end + +function OpenAPI.validate_property(::Type{ FindPetsByStatusStatusParameterStatusesInner }, name::Symbol, val) +end diff --git a/test/deep_object/DeepClient/src/models/model_FindPetsByStatusStatusParameterStatusesInnerInner.jl b/test/deep_object/DeepClient/src/models/model_FindPetsByStatusStatusParameterStatusesInnerInner.jl new file mode 100644 index 0000000..4f716c2 --- /dev/null +++ b/test/deep_object/DeepClient/src/models/model_FindPetsByStatusStatusParameterStatusesInnerInner.jl @@ -0,0 +1,30 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + + +@doc raw"""findPetsByStatus_status_parameter_statuses_inner_inner + + FindPetsByStatusStatusParameterStatusesInnerInner(; + type=nothing, + ) + + - type::String +""" +Base.@kwdef mutable struct FindPetsByStatusStatusParameterStatusesInnerInner <: OpenAPI.APIModel + type::Union{Nothing, String} = nothing + + function FindPetsByStatusStatusParameterStatusesInnerInner(type, ) + OpenAPI.validate_property(FindPetsByStatusStatusParameterStatusesInnerInner, Symbol("type"), type) + return new(type, ) + end +end # type FindPetsByStatusStatusParameterStatusesInnerInner + +const _property_types_FindPetsByStatusStatusParameterStatusesInnerInner = Dict{Symbol,String}(Symbol("type")=>"String", ) +OpenAPI.property_type(::Type{ FindPetsByStatusStatusParameterStatusesInnerInner }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_FindPetsByStatusStatusParameterStatusesInnerInner[name]))} + +function check_required(o::FindPetsByStatusStatusParameterStatusesInnerInner) + true +end + +function OpenAPI.validate_property(::Type{ FindPetsByStatusStatusParameterStatusesInnerInner }, name::Symbol, val) +end diff --git a/test/deep_object/DeepServer/.openapi-generator-ignore b/test/deep_object/DeepServer/.openapi-generator-ignore new file mode 100644 index 0000000..7484ee5 --- /dev/null +++ b/test/deep_object/DeepServer/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/test/deep_object/DeepServer/.openapi-generator/FILES b/test/deep_object/DeepServer/.openapi-generator/FILES new file mode 100644 index 0000000..a9ca22d --- /dev/null +++ b/test/deep_object/DeepServer/.openapi-generator/FILES @@ -0,0 +1,9 @@ +README.md +docs/FindPetsByStatus200Response.md +docs/FindPetsByStatusStatusParameter.md +docs/PetApi.md +src/DeepServer.jl +src/apis/api_PetApi.jl +src/modelincludes.jl +src/models/model_FindPetsByStatus200Response.jl +src/models/model_FindPetsByStatusStatusParameter.jl diff --git a/test/deep_object/DeepServer/.openapi-generator/VERSION b/test/deep_object/DeepServer/.openapi-generator/VERSION new file mode 100644 index 0000000..757e674 --- /dev/null +++ b/test/deep_object/DeepServer/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.0.0-SNAPSHOT \ No newline at end of file diff --git a/test/deep_object/DeepServer/Project.toml b/test/deep_object/DeepServer/Project.toml new file mode 100644 index 0000000..c58820a --- /dev/null +++ b/test/deep_object/DeepServer/Project.toml @@ -0,0 +1,17 @@ +name = "DeepServer" +uuid = "c178418e-95dc-4e61-99ad-6838d361ce75" +authors = ["vdayanand "] +version = "0.1.0" + +[deps] +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" +HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3" +OpenAPI = "d5e62ea6-ddf3-4d43-8e4c-ad5e6c8bfd7d" +TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53" +URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/test/deep_object/DeepServer/README.md b/test/deep_object/DeepServer/README.md new file mode 100644 index 0000000..92bfb50 --- /dev/null +++ b/test/deep_object/DeepServer/README.md @@ -0,0 +1,58 @@ +# Julia API server for DeepServer + +This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + +## Overview +This API server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client. + +- API version: 1.0.0 +- Build package: org.openapitools.codegen.languages.JuliaServerCodegen + + +## Installation +Place the Julia files generated under the `src` folder in your Julia project. Include DeepServer.jl in the project code. +It would include the module named DeepServer. + +Implement the server methods as listed below. They are also documented with the DeepServer module. +Launch a HTTP server with a router that has all handlers registered. A `register` method is provided in DeepServer module for convenience. + +```julia +register( + router::HTTP.Router, # Router to register handlers in + impl; # Module that implements the server methods + path_prefix::String="", # Prefix to be applied to all paths + optional_middlewares... # Optional middlewares to be applied to all handlers +) +``` + +Optional middlewares can be one or more of: +- `init`: called before the request is processed +- `pre_validation`: called after the request is parsed but before validation +- `pre_invoke`: called after validation but before the handler is invoked +- `post_invoke`: called after the handler is invoked but before the response is sent + +The order in which middlewares are invoked are: +`init |> read |> pre_validation |> validate |> pre_invoke |> invoke |> post_invoke` + + +## API Endpoints + +The following server methods must be implemented: + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **GET** /pet/findByStatus | Finds Pets by status + + + +## Models + + - [FindPetsByStatus200Response](docs/FindPetsByStatus200Response.md) + - [FindPetsByStatusStatusParameter](docs/FindPetsByStatusStatusParameter.md) + + + +## Author + + + diff --git a/test/deep_object/DeepServer/docs/FindPetsByStatus200Response.md b/test/deep_object/DeepServer/docs/FindPetsByStatus200Response.md new file mode 100644 index 0000000..7747550 --- /dev/null +++ b/test/deep_object/DeepServer/docs/FindPetsByStatus200Response.md @@ -0,0 +1,12 @@ +# FindPetsByStatus200Response + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**result** | [***FindPetsByStatusStatusParameter**](FindPetsByStatusStatusParameter.md) | | [optional] [default to nothing] + + +[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md) + + diff --git a/test/deep_object/DeepServer/docs/FindPetsByStatus200ResponseResult.md b/test/deep_object/DeepServer/docs/FindPetsByStatus200ResponseResult.md new file mode 100644 index 0000000..b388b95 --- /dev/null +++ b/test/deep_object/DeepServer/docs/FindPetsByStatus200ResponseResult.md @@ -0,0 +1,13 @@ +# FindPetsByStatus200ResponseResult + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **String** | | [optional] [default to nothing] +**statuses** | [**Vector{FindPetsByStatusStatusParameterStatusesInnerInner}**](FindPetsByStatusStatusParameterStatusesInnerInner.md) | | [optional] [default to nothing] + + +[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md) + + diff --git a/test/deep_object/DeepServer/docs/FindPetsByStatusStatusParameter.md b/test/deep_object/DeepServer/docs/FindPetsByStatusStatusParameter.md new file mode 100644 index 0000000..343827b --- /dev/null +++ b/test/deep_object/DeepServer/docs/FindPetsByStatusStatusParameter.md @@ -0,0 +1,13 @@ +# FindPetsByStatusStatusParameter + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **String** | | [optional] [default to nothing] +**statuses** | **Vector{String}** | | [optional] [default to nothing] + + +[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md) + + diff --git a/test/deep_object/DeepServer/docs/FindPetsByStatusStatusParameterStatusesInner.md b/test/deep_object/DeepServer/docs/FindPetsByStatusStatusParameterStatusesInner.md new file mode 100644 index 0000000..f435999 --- /dev/null +++ b/test/deep_object/DeepServer/docs/FindPetsByStatusStatusParameterStatusesInner.md @@ -0,0 +1,12 @@ +# FindPetsByStatusStatusParameterStatusesInner + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**type** | **String** | | [optional] [default to nothing] + + +[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md) + + diff --git a/test/deep_object/DeepServer/docs/FindPetsByStatusStatusParameterStatusesInnerInner.md b/test/deep_object/DeepServer/docs/FindPetsByStatusStatusParameterStatusesInnerInner.md new file mode 100644 index 0000000..4229b9a --- /dev/null +++ b/test/deep_object/DeepServer/docs/FindPetsByStatusStatusParameterStatusesInnerInner.md @@ -0,0 +1,12 @@ +# FindPetsByStatusStatusParameterStatusesInnerInner + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**type** | **String** | | [optional] [default to nothing] + + +[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md) + + diff --git a/test/deep_object/DeepServer/docs/PetApi.md b/test/deep_object/DeepServer/docs/PetApi.md new file mode 100644 index 0000000..b4d46f1 --- /dev/null +++ b/test/deep_object/DeepServer/docs/PetApi.md @@ -0,0 +1,38 @@ +# PetApi + +All URIs are relative to *http://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**find_pets_by_status**](PetApi.md#find_pets_by_status) | **GET** /pet/findByStatus | Finds Pets by status + + +# **find_pets_by_status** +> find_pets_by_status(req::HTTP.Request, status::FindPetsByStatusStatusParameter;) -> FindPetsByStatus200Response + +Finds Pets by status + +Multiple status values can be provided with comma separated strings + +### Required Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **req** | **HTTP.Request** | The HTTP Request object | +**status** | [**FindPetsByStatusStatusParameter**](.md)| Status values that need to be considered for filter | [default to nothing] + +### Return type + +[**FindPetsByStatus200Response**](FindPetsByStatus200Response.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/test/deep_object/DeepServer/src/DeepServer.jl b/test/deep_object/DeepServer/src/DeepServer.jl new file mode 100644 index 0000000..750e3df --- /dev/null +++ b/test/deep_object/DeepServer/src/DeepServer.jl @@ -0,0 +1,54 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + + +@doc raw""" +Encapsulates generated server code for DeepServer + +The following server methods must be implemented: + +- **find_pets_by_status** + - *invocation:* GET /pet/findByStatus + - *signature:* find_pets_by_status(req::HTTP.Request, status::FindPetsByStatusStatusParameter;) -> FindPetsByStatus200Response +""" +module DeepServer + +using HTTP +using URIs +using Dates +using TimeZones +using OpenAPI +using OpenAPI.Servers + +const API_VERSION = "1.0.0" + +include("modelincludes.jl") + +include("apis/api_PetApi.jl") + +""" +Register handlers for all APIs in this module in the supplied `Router` instance. + +Paramerets: +- `router`: Router to register handlers in +- `impl`: module that implements the server methods + +Optional parameters: +- `path_prefix`: prefix to be applied to all paths +- `optional_middlewares`: Register one or more optional middlewares to be applied to all requests. + +Optional middlewares can be one or more of: + - `init`: called before the request is processed + - `pre_validation`: called after the request is parsed but before validation + - `pre_invoke`: called after validation but before the handler is invoked + - `post_invoke`: called after the handler is invoked but before the response is sent + +The order in which middlewares are invoked are: +`init |> read |> pre_validation |> validate |> pre_invoke |> invoke |> post_invoke` +""" +function register(router::HTTP.Router, impl; path_prefix::String="", optional_middlewares...) + registerPetApi(router, impl; path_prefix=path_prefix, optional_middlewares...) + return router +end + +end # module DeepServer diff --git a/test/deep_object/DeepServer/src/apis/api_PetApi.jl b/test/deep_object/DeepServer/src/apis/api_PetApi.jl new file mode 100644 index 0000000..6c4f113 --- /dev/null +++ b/test/deep_object/DeepServer/src/apis/api_PetApi.jl @@ -0,0 +1,37 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + + +function find_pets_by_status_read(handler) + function find_pets_by_status_read_handler(req::HTTP.Request) + openapi_params = Dict{String,Any}() + query_params = HTTP.queryparams(URIs.URI(req.target)) + openapi_params["status"] = OpenAPI.Servers.to_param(FindPetsByStatusStatusParameter, query_params, "status", required=true, style="deepObject", is_explode=true) + req.context[:openapi_params] = openapi_params + + return handler(req) + end +end + +function find_pets_by_status_validate(handler) + function find_pets_by_status_validate_handler(req::HTTP.Request) + openapi_params = req.context[:openapi_params] + + return handler(req) + end +end + +function find_pets_by_status_invoke(impl; post_invoke=nothing) + function find_pets_by_status_invoke_handler(req::HTTP.Request) + openapi_params = req.context[:openapi_params] + ret = impl.find_pets_by_status(req::HTTP.Request, openapi_params["status"];) + resp = OpenAPI.Servers.server_response(ret) + return (post_invoke === nothing) ? resp : post_invoke(req, resp) + end +end + + +function registerPetApi(router::HTTP.Router, impl; path_prefix::String="", optional_middlewares...) + HTTP.register!(router, "GET", path_prefix * "/pet/findByStatus", OpenAPI.Servers.middleware(impl, find_pets_by_status_read, find_pets_by_status_validate, find_pets_by_status_invoke; optional_middlewares...)) + return router +end diff --git a/test/deep_object/DeepServer/src/deep.jl b/test/deep_object/DeepServer/src/deep.jl new file mode 100644 index 0000000..6c6650a --- /dev/null +++ b/test/deep_object/DeepServer/src/deep.jl @@ -0,0 +1,54 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + + +@doc raw""" +Encapsulates generated server code for deep + +The following server methods must be implemented: + +- **find_pets_by_status** + - *invocation:* GET /pet/findByStatus + - *signature:* find_pets_by_status(req::HTTP.Request, status::FindPetsByStatusStatusParameter;) -> FindPetsByStatus200Response +""" +module deep + +using HTTP +using URIs +using Dates +using TimeZones +using OpenAPI +using OpenAPI.Servers + +const API_VERSION = "1.0.0" + +include("modelincludes.jl") + +include("apis/api_PetApi.jl") + +""" +Register handlers for all APIs in this module in the supplied `Router` instance. + +Paramerets: +- `router`: Router to register handlers in +- `impl`: module that implements the server methods + +Optional parameters: +- `path_prefix`: prefix to be applied to all paths +- `optional_middlewares`: Register one or more optional middlewares to be applied to all requests. + +Optional middlewares can be one or more of: + - `init`: called before the request is processed + - `pre_validation`: called after the request is parsed but before validation + - `pre_invoke`: called after validation but before the handler is invoked + - `post_invoke`: called after the handler is invoked but before the response is sent + +The order in which middlewares are invoked are: +`init |> read |> pre_validation |> validate |> pre_invoke |> invoke |> post_invoke` +""" +function register(router::HTTP.Router, impl; path_prefix::String="", optional_middlewares...) + registerPetApi(router, impl; path_prefix=path_prefix, optional_middlewares...) + return router +end + +end # module deep diff --git a/test/deep_object/DeepServer/src/modelincludes.jl b/test/deep_object/DeepServer/src/modelincludes.jl new file mode 100644 index 0000000..74221b3 --- /dev/null +++ b/test/deep_object/DeepServer/src/modelincludes.jl @@ -0,0 +1,5 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + +include("models/model_FindPetsByStatus200Response.jl") +include("models/model_FindPetsByStatusStatusParameter.jl") diff --git a/test/deep_object/DeepServer/src/models/model_FindPetsByStatus200Response.jl b/test/deep_object/DeepServer/src/models/model_FindPetsByStatus200Response.jl new file mode 100644 index 0000000..2e493a1 --- /dev/null +++ b/test/deep_object/DeepServer/src/models/model_FindPetsByStatus200Response.jl @@ -0,0 +1,29 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + + +@doc raw""" + FindPetsByStatus200Response(; + result=nothing, + ) + + - result::FindPetsByStatusStatusParameter +""" +Base.@kwdef mutable struct FindPetsByStatus200Response <: OpenAPI.APIModel + result = nothing # spec type: Union{ Nothing, FindPetsByStatusStatusParameter } + + function FindPetsByStatus200Response(result, ) + OpenAPI.validate_property(FindPetsByStatus200Response, Symbol("result"), result) + return new(result, ) + end +end # type FindPetsByStatus200Response + +const _property_types_FindPetsByStatus200Response = Dict{Symbol,String}(Symbol("result")=>"FindPetsByStatusStatusParameter", ) +OpenAPI.property_type(::Type{ FindPetsByStatus200Response }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_FindPetsByStatus200Response[name]))} + +function check_required(o::FindPetsByStatus200Response) + true +end + +function OpenAPI.validate_property(::Type{ FindPetsByStatus200Response }, name::Symbol, val) +end diff --git a/test/deep_object/DeepServer/src/models/model_FindPetsByStatus200ResponseResult.jl b/test/deep_object/DeepServer/src/models/model_FindPetsByStatus200ResponseResult.jl new file mode 100644 index 0000000..e543853 --- /dev/null +++ b/test/deep_object/DeepServer/src/models/model_FindPetsByStatus200ResponseResult.jl @@ -0,0 +1,33 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + + +@doc raw""" + FindPetsByStatus200ResponseResult(; + name=nothing, + statuses=nothing, + ) + + - name::String + - statuses::Vector{FindPetsByStatusStatusParameterStatusesInnerInner} +""" +Base.@kwdef mutable struct FindPetsByStatus200ResponseResult <: OpenAPI.APIModel + name::Union{Nothing, String} = nothing + statuses::Union{Nothing, Vector} = nothing # spec type: Union{ Nothing, Vector{FindPetsByStatusStatusParameterStatusesInnerInner} } + + function FindPetsByStatus200ResponseResult(name, statuses, ) + OpenAPI.validate_property(FindPetsByStatus200ResponseResult, Symbol("name"), name) + OpenAPI.validate_property(FindPetsByStatus200ResponseResult, Symbol("statuses"), statuses) + return new(name, statuses, ) + end +end # type FindPetsByStatus200ResponseResult + +const _property_types_FindPetsByStatus200ResponseResult = Dict{Symbol,String}(Symbol("name")=>"String", Symbol("statuses")=>"Vector{FindPetsByStatusStatusParameterStatusesInnerInner}", ) +OpenAPI.property_type(::Type{ FindPetsByStatus200ResponseResult }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_FindPetsByStatus200ResponseResult[name]))} + +function check_required(o::FindPetsByStatus200ResponseResult) + true +end + +function OpenAPI.validate_property(::Type{ FindPetsByStatus200ResponseResult }, name::Symbol, val) +end diff --git a/test/deep_object/DeepServer/src/models/model_FindPetsByStatusStatusParameter.jl b/test/deep_object/DeepServer/src/models/model_FindPetsByStatusStatusParameter.jl new file mode 100644 index 0000000..e1903a1 --- /dev/null +++ b/test/deep_object/DeepServer/src/models/model_FindPetsByStatusStatusParameter.jl @@ -0,0 +1,33 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + + +@doc raw""" + FindPetsByStatusStatusParameter(; + name=nothing, + statuses=nothing, + ) + + - name::String + - statuses::Vector{String} +""" +Base.@kwdef mutable struct FindPetsByStatusStatusParameter <: OpenAPI.APIModel + name::Union{Nothing, String} = nothing + statuses::Union{Nothing, Vector{String}} = nothing + + function FindPetsByStatusStatusParameter(name, statuses, ) + OpenAPI.validate_property(FindPetsByStatusStatusParameter, Symbol("name"), name) + OpenAPI.validate_property(FindPetsByStatusStatusParameter, Symbol("statuses"), statuses) + return new(name, statuses, ) + end +end # type FindPetsByStatusStatusParameter + +const _property_types_FindPetsByStatusStatusParameter = Dict{Symbol,String}(Symbol("name")=>"String", Symbol("statuses")=>"Vector{String}", ) +OpenAPI.property_type(::Type{ FindPetsByStatusStatusParameter }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_FindPetsByStatusStatusParameter[name]))} + +function check_required(o::FindPetsByStatusStatusParameter) + true +end + +function OpenAPI.validate_property(::Type{ FindPetsByStatusStatusParameter }, name::Symbol, val) +end diff --git a/test/deep_object/DeepServer/src/models/model_FindPetsByStatusStatusParameterStatusesInner.jl b/test/deep_object/DeepServer/src/models/model_FindPetsByStatusStatusParameterStatusesInner.jl new file mode 100644 index 0000000..6b43755 --- /dev/null +++ b/test/deep_object/DeepServer/src/models/model_FindPetsByStatusStatusParameterStatusesInner.jl @@ -0,0 +1,29 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + + +@doc raw""" + FindPetsByStatusStatusParameterStatusesInner(; + type=nothing, + ) + + - type::String +""" +Base.@kwdef mutable struct FindPetsByStatusStatusParameterStatusesInner <: OpenAPI.APIModel + type::Union{Nothing, String} = nothing + + function FindPetsByStatusStatusParameterStatusesInner(type, ) + OpenAPI.validate_property(FindPetsByStatusStatusParameterStatusesInner, Symbol("type"), type) + return new(type, ) + end +end # type FindPetsByStatusStatusParameterStatusesInner + +const _property_types_FindPetsByStatusStatusParameterStatusesInner = Dict{Symbol,String}(Symbol("type")=>"String", ) +OpenAPI.property_type(::Type{ FindPetsByStatusStatusParameterStatusesInner }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_FindPetsByStatusStatusParameterStatusesInner[name]))} + +function check_required(o::FindPetsByStatusStatusParameterStatusesInner) + true +end + +function OpenAPI.validate_property(::Type{ FindPetsByStatusStatusParameterStatusesInner }, name::Symbol, val) +end diff --git a/test/deep_object/DeepServer/src/models/model_FindPetsByStatusStatusParameterStatusesInnerInner.jl b/test/deep_object/DeepServer/src/models/model_FindPetsByStatusStatusParameterStatusesInnerInner.jl new file mode 100644 index 0000000..39ed8d1 --- /dev/null +++ b/test/deep_object/DeepServer/src/models/model_FindPetsByStatusStatusParameterStatusesInnerInner.jl @@ -0,0 +1,29 @@ +# This file was generated by the Julia OpenAPI Code Generator +# Do not modify this file directly. Modify the OpenAPI specification instead. + + +@doc raw""" + FindPetsByStatusStatusParameterStatusesInnerInner(; + type=nothing, + ) + + - type::String +""" +Base.@kwdef mutable struct FindPetsByStatusStatusParameterStatusesInnerInner <: OpenAPI.APIModel + type::Union{Nothing, String} = nothing + + function FindPetsByStatusStatusParameterStatusesInnerInner(type, ) + OpenAPI.validate_property(FindPetsByStatusStatusParameterStatusesInnerInner, Symbol("type"), type) + return new(type, ) + end +end # type FindPetsByStatusStatusParameterStatusesInnerInner + +const _property_types_FindPetsByStatusStatusParameterStatusesInnerInner = Dict{Symbol,String}(Symbol("type")=>"String", ) +OpenAPI.property_type(::Type{ FindPetsByStatusStatusParameterStatusesInnerInner }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_FindPetsByStatusStatusParameterStatusesInnerInner[name]))} + +function check_required(o::FindPetsByStatusStatusParameterStatusesInnerInner) + true +end + +function OpenAPI.validate_property(::Type{ FindPetsByStatusStatusParameterStatusesInnerInner }, name::Symbol, val) +end diff --git a/test/deep_object/deep.yaml b/test/deep_object/deep.yaml new file mode 100644 index 0000000..46d3c43 --- /dev/null +++ b/test/deep_object/deep.yaml @@ -0,0 +1,62 @@ +openapi: 3.0.0 +servers: + - url: 'http://petstore.swagger.io/v2' +info: + description: >- + This is a sample server Petstore server. For this sample, you can use the api key + `special-key` to test the authorization filters. + version: 1.0.0 + title: OpenAPI Petstore + license: + name: Apache-2.0 + url: 'https://www.apache.org/licenses/LICENSE-2.0.html' +tags: + - name: pet + description: Everything about your Pets + - name: store + description: Access to Petstore orders + - name: user + description: Operations about user +paths: + /pet/findByStatus: + get: + tags: + - pet + summary: Finds Pets by status + description: Multiple status values can be provided with comma separated strings + operationId: findPetsByStatus + parameters: + - name: status + in: query + description: Status values that need to be considered for filter + required: true + style: deepObject + explode: true + deprecated: true + schema: + type: object + properties: + name: + type: string + statuses: + items: + type: string + responses: + '200': + description: successful operation + content: + application/json: + schema: + type: object + properties: + result: + type: object + properties: + name: + type: string + statuses: + items: + type: string + + '400': + description: Invalid status value diff --git a/test/deep_object/deep_client.jl b/test/deep_object/deep_client.jl new file mode 100644 index 0000000..da954be --- /dev/null +++ b/test/deep_object/deep_client.jl @@ -0,0 +1,24 @@ +module DeepClientTest + +include("DeepClient/src/DeepClient.jl") +using .DeepClient +using .DeepClient.OpenAPI.Clients: Client +using .DeepClient: FindPetsByStatusStatusParameter + +using Test + +const server = "http://127.0.0.1:8081" + +function runtests() + @info("PetApi") + client = Client(server) + api = DeepClient.PetApi(client) + unsold = FindPetsByStatusStatusParameter("key", ["available", "pending"]) + resp, http_resp = find_pets_by_status(api, unsold) + res = resp.result + @test res.name == "key" + @test res.statuses == ["available", "pending"] + @test http_resp.status == 200 +end + +end # module DeepObjectClientTest diff --git a/test/deep_object/deep_server.jl b/test/deep_object/deep_server.jl new file mode 100644 index 0000000..8d56254 --- /dev/null +++ b/test/deep_object/deep_server.jl @@ -0,0 +1,38 @@ +module DeepServerTest +include("DeepServer/src/DeepServer.jl") +using .DeepServer +using HTTP +using .DeepServer: register, FindPetsByStatus200Response + +const server = Ref{Any}(nothing) + +function find_pets_by_status(::HTTP.Messages.Request, param::DeepServer.FindPetsByStatusStatusParameter) + return FindPetsByStatus200Response(param) +end + +function stop(::HTTP.Request) + HTTP.close(server[]) + return HTTP.Response(200, "") +end + +function ping(::HTTP.Request) + return HTTP.Response(200, "") +end + +function run_server(port=8081) + try + @info "Running deepserver" + router = HTTP.Router() + HTTP.register!(router, "GET", "/stop", stop) + HTTP.register!(router, "GET", "/ping", ping) + router = register(router, @__MODULE__) + server[] = HTTP.serve!(router, port) + @info "wait deepserver" + wait(server[]) + catch ex + @error("Server error", exception=(ex, catch_backtrace())) + end +end + +end # module DeepObjectClientTest +DeepServerTest.run_server() diff --git a/test/param_deserialize.jl b/test/param_deserialize.jl new file mode 100644 index 0000000..1881c71 --- /dev/null +++ b/test/param_deserialize.jl @@ -0,0 +1,99 @@ +using Test + +using OpenAPI.Servers: deep_dict_repr +using OpenAPI: deep_object_to_array +@testset "Test deep_dict_repr" begin + @testset "Single level object" begin + query_string = Dict("key1" => "value1", "key2" => "value2") + expected = Dict("key1" => "value1", "key2" => "value2") + @test deep_dict_repr(query_string) == expected + end + + @testset "Nested object" begin + query_string = Dict("outer[inner]" => "value") + expected = Dict("outer" => Dict("inner" => "value")) + @test deep_dict_repr(query_string) == expected + end + @testset "Deeply nested object" begin + query_string = Dict("a[b][c][d]" => "value") + expected = Dict("a" => Dict("b" => Dict("c" => Dict("d" => "value")))) + @test deep_dict_repr(query_string) == expected + end + + @testset "Multiple nested objects" begin + query_string = Dict("a[b]" => "value1", "a[c]" => "value2") + expected = Dict("a" => Dict("b" => "value1", "c" => "value2")) + @test deep_dict_repr(query_string) == expected + end + + @testset "List of values" begin + query_string = Dict("a[0]" => "value1", "a[1]" => "value2") + expected = Dict("a" => Dict("0" => "value1", "1" => "value2")) + @test deep_dict_repr(query_string) == expected + end + + @testset "Mixed structure" begin + query_string = + Dict("a[b]" => "value1", "a[c][0]" => "value2", "a[c][1]" => "value3") + expected = Dict( + "a" => Dict("b" => "value1", "c" => Dict("0" => "value2", "1" => "value3")), + ) + @test deep_dict_repr(query_string) == expected + end + + @testset "deep_object_to_array" begin + example = Dict( + "a" => Dict("b" => "value1", "c" => Dict("0" => "value2", "1" => "value3")), + ) + @test deep_object_to_array(example) == example + @test deep_object_to_array(example["a"]["c"]) == ["value2", "value3"] + end + + @testset "Blank values" begin + query_string = Dict("a[b]" => "", "a[c]" => "") + expected = Dict("a" => Dict("b" => "", "c" => "")) + @test deep_dict_repr(query_string) == expected + end + + @testset "Complex nested structure" begin + query_string = + Dict("a[b][c][d]" => "value1", "a[b][c][e]" => "value2", "a[f]" => "value3") + expected = Dict( + "a" => Dict( + "b" => Dict("c" => Dict("d" => "value1", "e" => "value2")), + "f" => "value3", + ), + ) + @test deep_dict_repr(query_string) == expected + end + @testset "Complex nested structure with numbers and nessted" begin + query_string = Dict{String,String}( + "filter[0][name]" => "name", + "filter[0][data][0]" => "Dog", + "pagination[type]" => "offset", + "pagination[page]" => "1", + "filter[0][type]" => "FilterSet", + "pagination[per_page]" => "5", + "pagination[foo]" => "5.0", + ) + expected = Dict( + "pagination" => Dict( + "page" => "1", + "per_page" => "5", + "type" => "offset", + "foo" => "5.0", + ), + "filter" => Dict( + "0" => Dict( + "name" => "name", + "data" => Dict("0" => "Dog"), + "type" => "FilterSet", + ), + ), + ) + d = deep_dict_repr(query_string) + @test d["pagination"] == expected["pagination"] + @test d["filter"] == expected["filter"] + end + +end diff --git a/test/runtests.jl b/test/runtests.jl index 1e4ade5..dfc1413 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,8 +7,10 @@ include("client/runtests.jl") include("client/allany/runtests.jl") include("forms/forms_client.jl") include("client/timeouttest/runtests.jl") +include("deep_object/deep_client.jl") @testset "OpenAPI" begin + include("param_deserialize.jl") @testset "ModelGen" begin TestModelGen.runtests() end @@ -18,15 +20,15 @@ include("client/timeouttest/runtests.jl") @testset "Petstore Client" begin try if run_tests_with_servers && !openapi_generator_env - run(`client/petstore_v2/start_petstore_server.sh`) - run(`client/petstore_v3/start_petstore_server.sh`) + run(`bash client/petstore_v2/start_petstore_server.sh`) + run(`bash client/petstore_v3/start_petstore_server.sh`) sleep(20) # let servers start end OpenAPIClientTests.runtests(; skip_petstore=openapi_generator_env, test_file_upload=false) finally if run_tests_with_servers && !openapi_generator_env - run(`client/petstore_v2/stop_petstore_server.sh`) - run(`client/petstore_v3/stop_petstore_server.sh`) + run(`bash client/petstore_v2/stop_petstore_server.sh`) + run(`bash client/petstore_v3/stop_petstore_server.sh`) end end end @@ -42,7 +44,7 @@ include("client/timeouttest/runtests.jl") servers_running &= wait_server(8080) servers_running &= wait_server(8081) else - servers_running = false + servers_running = false end servers_running && OpenAPIClientTests.runtests(; test_file_upload=true) finally @@ -68,7 +70,7 @@ include("client/timeouttest/runtests.jl") v3_ret, v3_out = run_server(joinpath(@__DIR__, "server", "openapigenerator_petstore_v3", "petstore_server.jl")) servers_running &= wait_server(8081) else - servers_running = false + servers_running = false end servers_running && OpenAPIClientTests.run_openapigenerator_tests(; test_file_upload=true) finally @@ -105,6 +107,28 @@ include("client/timeouttest/runtests.jl") end end run_tests_with_servers && sleep(20) # avoid port conflicts + @testset "DeepObject tests" begin + ret = out = nothing + servers_running = true + + try + if run_tests_with_servers + ret, out = run_server(joinpath(@__DIR__, "deep_object", "deep_server.jl")) + servers_running &= wait_server(8081) + DeepClientTest.runtests() + else + servers_running = false + end + finally + if run_tests_with_servers && !servers_running + # we probably had an error starting the servers + out_str = isnothing(out) ? "" : String(take!(out)) + @warn("Servers not running", ret=ret, out_str) + end + run_tests_with_servers && servers_running && stop_server(8081, ret, out) + end + end + run_tests_with_servers && sleep(20) # avoid port conflicts @testset "Union types" begin ret = out = nothing servers_running = true @@ -178,4 +202,5 @@ include("client/timeouttest/runtests.jl") end run_tests_with_servers && sleep(20) # avoid port conflicts + end diff --git a/test/server/petstore_v3/petstore/src/apis/api_PetApi.jl b/test/server/petstore_v3/petstore/src/apis/api_PetApi.jl index 5d05aa8..2d8ac35 100644 --- a/test/server/petstore_v3/petstore/src/apis/api_PetApi.jl +++ b/test/server/petstore_v3/petstore/src/apis/api_PetApi.jl @@ -15,7 +15,7 @@ end function add_pet_validate(handler) function add_pet_validate_handler(req::HTTP.Request) openapi_params = req.context[:openapi_params] - + return handler(req) end end @@ -45,7 +45,7 @@ end function delete_pet_validate(handler) function delete_pet_validate_handler(req::HTTP.Request) openapi_params = req.context[:openapi_params] - + return handler(req) end end @@ -73,7 +73,7 @@ end function find_pets_by_status_validate(handler) function find_pets_by_status_validate_handler(req::HTTP.Request) openapi_params = req.context[:openapi_params] - + return handler(req) end end @@ -101,7 +101,7 @@ end function find_pets_by_tags_validate(handler) function find_pets_by_tags_validate_handler(req::HTTP.Request) openapi_params = req.context[:openapi_params] - + return handler(req) end end @@ -129,7 +129,7 @@ end function get_pet_by_id_validate(handler) function get_pet_by_id_validate_handler(req::HTTP.Request) openapi_params = req.context[:openapi_params] - + return handler(req) end end @@ -156,7 +156,7 @@ end function update_pet_validate(handler) function update_pet_validate_handler(req::HTTP.Request) openapi_params = req.context[:openapi_params] - + return handler(req) end end @@ -188,7 +188,7 @@ end function update_pet_with_form_validate(handler) function update_pet_with_form_validate_handler(req::HTTP.Request) openapi_params = req.context[:openapi_params] - + return handler(req) end end @@ -220,7 +220,7 @@ end function upload_file_validate(handler) function upload_file_validate_handler(req::HTTP.Request) openapi_params = req.context[:openapi_params] - + return handler(req) end end diff --git a/test/testutils.jl b/test/testutils.jl index 72606d2..f3c1993 100644 --- a/test/testutils.jl +++ b/test/testutils.jl @@ -22,7 +22,6 @@ function run_server(script, flags=``) pipelined_cmd = pipeline(srvrcmd, stdout=iob, stderr=iob) @info("Launching ", script, srvrcmd) ret = run(pipelined_cmd, wait=false) - return ret, iob end