Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Failure To Generate from_json Method Using Defined Schema Objects #73

Open
TheCedarPrince opened this issue Apr 15, 2024 · 3 comments

Comments

@TheCedarPrince
Copy link

Hi folks,

I am seeing an error in my IPUMS.jl package where when I used the OpenAPI definition for IPUMS (also see here for the reference documentation: https://developer.ipums.org/docs/v2/reference/nhgis/), the methods to handle from_json definitions being generated by OpenAPI do not exist to handle the schema objects defined in the original OpenAPI definition for IPUMS.

Instead, what I am forced to do is to basically, self-pirate these generated methods within my package to get things working. Otherwise, I get errors such as these:

ERROR: MethodError: no method matching from_json(::Vector{IPUMS.TimeSeriesTableSimple}, ::Dict{String, Any})

Closest candidates are:
  from_json(::Vector{IPUMS.DatasetSimple}, ::Any)
   @ IPUMS ~/FOSS/IPUMS.jl/src/piracy.jl:7
  from_json(::Vector{IPUMS.TimeSeriesTableFull}, ::Any)
   @ IPUMS ~/FOSS/IPUMS.jl/src/piracy.jl:12
  from_json(::Vector{IPUMS.Shapefile}, ::Any)
   @ IPUMS ~/FOSS/IPUMS.jl/src/piracy.jl:16
  ...

Stacktrace:
 [1] from_json(::Type{Vector{IPUMS.TimeSeriesTableSimple}}, json::Dict{String, Any})
   @ OpenAPI ~/.julia/packages/OpenAPI/GMeGW/src/json.jl:40
 [2] response(::Type{Vector{IPUMS.TimeSeriesTableSimple}}, data::Dict{String, Any})
   @ OpenAPI.Clients ~/.julia/packages/OpenAPI/GMeGW/src/client.jl:428
 [3] response(::Type{Vector{IPUMS.TimeSeriesTableSimple}}, is_json::Bool, body::Vector{UInt8})
   @ OpenAPI.Clients ~/.julia/packages/OpenAPI/GMeGW/src/client.jl:417
 [4] response(::Type{Vector{IPUMS.TimeSeriesTableSimple}}, resp::Downloads.Response, body::Vector{UInt8})
   @ OpenAPI.Clients ~/.julia/packages/OpenAPI/GMeGW/src/client.jl:412
 [5] exec(ctx::OpenAPI.Clients.Ctx, stream_to::Nothing)
   @ OpenAPI.Clients ~/.julia/packages/OpenAPI/GMeGW/src/client.jl:634
 [6] exec
   @ ~/.julia/packages/OpenAPI/GMeGW/src/client.jl:614 [inlined]
 [7] #metadata_nhgis_time_series_tables_get#61
   @ ~/FOSS/IPUMS.jl/src/apis/api_DefaultApi.jl:315 [inlined]
 [8] metadata_nhgis_time_series_tables_get(_api::DefaultApi, version::String)
   @ IPUMS ~/FOSS/IPUMS.jl/src/apis/api_DefaultApi.jl:313
 [9] top-level scope
   @ REPL[11]:1

or

ERROR: MethodError: Cannot `convert` an object of type Vector{Any} to an object of type IPUMS.DatasetFullBreakdowns

Closest candidates are:
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:84
  convert(::Type{T}, ::Dict{String, Any}) where T<:OpenAPI.APIModel
   @ OpenAPI ~/.julia/packages/OpenAPI/GMeGW/src/client.jl:715
  convert(::Type{T}, ::Nothing) where T<:OpenAPI.APIModel
   @ OpenAPI ~/.julia/packages/OpenAPI/GMeGW/src/client.jl:716
  ...

Stacktrace:
  [1] convert(::Type{Union{Nothing, IPUMS.DatasetFullBreakdowns}}, x::Vector{Any})
    @ Base ./some.jl:37
  [2] from_json(o::IPUMS.DatasetFull, name::Symbol, v::Vector{Any})
    @ OpenAPI ~/.julia/packages/OpenAPI/GMeGW/src/json.jl:103
  [3] from_json(o::IPUMS.DatasetFull, json::Dict{String, Any})
    @ OpenAPI ~/.julia/packages/OpenAPI/GMeGW/src/json.jl:58
  [4] from_json
    @ ~/.julia/packages/OpenAPI/GMeGW/src/json.jl:40 [inlined]
  [5] response
    @ ~/.julia/packages/OpenAPI/GMeGW/src/client.jl:428 [inlined]
  [6] response(::Type{IPUMS.DatasetFull}, is_json::Bool, body::Vector{UInt8})
    @ OpenAPI.Clients ~/.julia/packages/OpenAPI/GMeGW/src/client.jl:417
  [7] response(::Type{IPUMS.DatasetFull}, resp::Downloads.Response, body::Vector{UInt8})
    @ OpenAPI.Clients ~/.julia/packages/OpenAPI/GMeGW/src/client.jl:412
  [8] exec(ctx::OpenAPI.Clients.Ctx, stream_to::Nothing)
    @ OpenAPI.Clients ~/.julia/packages/OpenAPI/GMeGW/src/client.jl:634
  [9] exec
    @ ~/.julia/packages/OpenAPI/GMeGW/src/client.jl:614 [inlined]
 [10] #metadata_nhgis_datasets_dataset_get#52
    @ ~/FOSS/IPUMS.jl/src/apis/api_DefaultApi.jl:216 [inlined]
 [11] metadata_nhgis_datasets_dataset_get(_api::DefaultApi, dataset::String, version::String)
    @ IPUMS ~/FOSS/IPUMS.jl/src/apis/api_DefaultApi.jl:214
 [12] top-level scope
    @ REPL[13]:1

Here's a mostly working MWE minus an API key (that you can generate here):

julia> using IPUMS

julia> using OpenAPI.Clients

julia> import OpenAPI.Clients: Client

julia> client = Client("https://api.ipums.org", headers = Dict("Authorization" => "API_KEY")

julia> api = DefaultApi(client)

And this would be after you generate the API with the openapi-cli tool. Happy to provide further information.

@TheCedarPrince
Copy link
Author

CC @asinghvi17 -- thanks for helping me investigate/explore this! :D

@tanmaykm
Copy link
Member

Could you provide a MWE spec with client and server implementation? It will help eliminate instances where there is mismatch between spec and server response.

@TheCedarPrince
Copy link
Author

Hey @tanmaykm, sure, but I really do not know what you are looking for. I didn't create this spec that I am making OpenAPI.jl consume (link here: https://developer.ipums.org/docs/v2/reference/nhgis/) and I have no idea how to make one.

What are you referring to?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants