Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

未關閉
#73 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
julia, openapi
領域
api, tooling

研究方向

從 src/json.jl 和 src/client.jl、堆疊追蹤中顯示的 OpenAPI 檔案開始,並使用 IPUMS.jl 的 MWE 和產生的 schema 物件重現該失敗。將產生的方法與 IPUMS.jl/src/piracy.jl 中的 self-pirated methods 進行比較。當產生的用戶端能夠在不使用這些額外方法的情況下反序列化所回報的 schema 物件時,即表示完成。

由索引模型根據 Issue 內容生成。

描述

stale

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.

主要語言
Julia
星號
56
分支
16
平均合併
1 天 51 分鐘
30 天內合併 PR
12

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

JuliaComputing/OpenAPI.jl 的其他 Issue

查看 JuliaComputing/OpenAPI.jl 的全部 Issue

相似的 Issue

更多 Julia Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。