Bug found related to Boolean fields (with solution)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
Inspect jsonschema.lua around line 701 and reproduce the failure with the Boolean oneOf schema and default value shown in the issue. Verify that validator generation handles Boolean defaults without the sformat error, and add or run a regression check if the repository provides one.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I found a bug when using boolean fields in my JSON Schema. My partial JSON Schema which I use to detect the error was the following:
...
"bool_param":{
"oneOf":[{
"type":"boolean"
},{
"enum":["external"]
}],
"default":true,
"description":"Description of bool_param. Set as 'external' if the value is not yet known and thus will be set externally at runtime (only once) depending on e.g. the outcome of a previous action or the outcome of another module."
},
...
When setting it to true or false, I got the following error when validating the schema:
lua: /usr/local/share/lua/5.1/jsonschema.lua:701: bad argument #4 to 'sformat' (string expected, got boolean)
stack traceback:
[C]: in function 'sformat'
/usr/local/share/lua/5.1/jsonschema.lua:701: in function 'generate_validator'
/usr/local/share/lua/5.1/jsonschema.lua:173: in function 'validator'
/usr/local/share/lua/5.1/jsonschema.lua:678: in function 'generate_validator'
/usr/local/share/lua/5.1/jsonschema.lua:173: in function 'validator'
/usr/local/share/lua/5.1/jsonschema.lua:1184: in function 'generate_main_validator_ctx'
/usr/local/share/lua/5.1/jsonschema.lua:1201: in function 'generate_validator'
./task_requirements.lua:501: in function 'load_json_table'
example.lua:35: in main chunk
[C]: ?
The bug was (apparently) easily fixed by changing line 701 of the jsonschema.lua from:
ctx:stmt(sformat(' %s[%s] = %s', ctx:param(1), str_filter(prop), default))
to
ctx:stmt(sformat(' %s[%s] = %s', tostring(ctx:param(1)), str_filter(prop), tostring(default)))
I guess this happens because lua does not convert booleans to strings automatically.
- Ngôn ngữ chính
- Lua
- Star
- 136
- Fork
- 29
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của api7/jsonschema
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
api7/jsonschema#95 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
api7/jsonschema#105 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
api7/jsonschema#93 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
api7/jsonschema#92 ·
-
Support pcre2Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
api7/jsonschema#89 ·
Tất cả issue của api7/jsonschema
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
fw876/helloworld#2074 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
bug documentation lua
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100