Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Bug found related to Boolean fields (with solution)

オープン
#91 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
lua
領域
backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Lua
スター
136
フォーク
29
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

api7/jsonschema のほかの issue

api7/jsonschema の issue をすべて見る

似ている issue

Lua の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。