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 found related to Boolean fields (with solution) #91

Open
santiregui opened this issue Nov 15, 2024 · 0 comments
Open

Bug found related to Boolean fields (with solution) #91

santiregui opened this issue Nov 15, 2024 · 0 comments

Comments

@santiregui
Copy link

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.

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

1 participant