Skip to content

schema: fix canvas/dock child layout properties - #548

Open
Cyb3RGER wants to merge 1 commit into
black-sliver:masterfrom
Cyb3RGER:fix_canvas_child_props
Open

schema: fix canvas/dock child layout properties#548
Cyb3RGER wants to merge 1 commit into
black-sliver:masterfrom
Cyb3RGER:fix_canvas_child_props

Conversation

@Cyb3RGER

@Cyb3RGER Cyb3RGER commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

didn't test this in pack-checker so you might want to still do that

resolves PopTracker/pack-checker#58

@black-sliver

Copy link
Copy Markdown
Owner

Do we need error cases so we see if pack-checker fails validation properly?

@Cyb3RGER

Copy link
Copy Markdown
Contributor Author

I mean error case would be as simple to add an additional property, and maybe check that the something like the dock property only validates on children of dock layouts. if dock works canvas is likely also work as it's implemented in the same way.

As I said I didn't test against pack-checker, I only really checked the results in vs code because that was quickest way to test.

@black-sliver

black-sliver commented Jul 15, 2026

Copy link
Copy Markdown
Owner

It appears to do the right thing in pack checker, but the error message is pretty bad.

I added a "dock": "left" to the outermost dock of the template_pack (and also to the first map, same output) and I got

layouts/tracker.jsonc: Unevaluated properties are not allowed ('background', 'content', 'type' were unexpected)

Failed validating 'unevaluatedProperties' in schema['patternProperties']['^tracker_default$']:
    {'allOf': [{'$ref': '#/$defs/layout_base'}],
     'unevaluatedProperties': False}

On instance['tracker_default']:
    <the whole tracker_default tree>

It doesn't say which property is the problem nor where the problem is.

@black-sliver

Copy link
Copy Markdown
Owner

For completeness sake, with the old schema, an unknown property would look something like this:

Failed validating 'anyOf' in schema['patternProperties']['^tracker_default$']['allOf'][0]['then']['properties']['content']:
[...]

On instance['content'][1]['tabs'][0]['content']:
    <actual element that has the problem>

@Cyb3RGER

Copy link
Copy Markdown
Contributor Author

that might be an issue with the python jsonschema package and/or how you use it.
From a quick test if I use specifically the Draft202012Validator directly instead of validate()

from jsonschema import Draft202012Validator

with io.open(f"schema/packs/strict/{item.type}.json") as schema_file:
    validator = Draft202012Validator(json.load(schema_file))
errors = list( validator.iter_errors(item.data))
for error in errors:
    path = "/".join(str(p) for p in error.absolute_path) or "<root>"
    print(f"{path}: {error.message}")

I get

tracker_default/content/0: Unevaluated properties are not allowed ('dock' was unexpected)
tracker_default: Unevaluated properties are not allowed ('background', 'content', 'type' were unexpected)

I would assume that pack-checker or validate swallow the upper error here.
I think validate is supposed to pick the right validator via $schema in the schema but adding "$schema": "https://json-schema.org/draft/2020-12/schema" did not change the output, so ¯\(ツ)/¯.

Either way I would still prefer this to be merged since it simplifies the schema while also actually correctly validating the properties now.

@black-sliver

black-sliver commented Jul 20, 2026

Copy link
Copy Markdown
Owner

I do want to merge this, but I feel like we need to figure this out because it makes other errors unreadable. :S

adding "$schema": "https://json-schema.org/draft/2020-12/schema" did not change the output

validate() should go through the registry, which should default to 202012 already if unspecified.

I would assume that pack-checker or validate swallow the upper error here.

If I change the code in the pack-checker from validate(...) to

                schema = json.load(open(f".../strict/{item.type}.json"))
                validator = Draft202012Validator(schema)
                errors = list(validator.iter_errors(item.data))
                for error in errors:
                    print(f"{error.message}")

or if I run this snippet

import io
import json
from jsonschema import Draft202012Validator
from typing import NamedTuple


class Item(NamedTuple):
    type: str
    data: str


item = Item("layouts", json.load(open(".../template_pack/layouts/tracker.jsonc")))

with io.open(f".../strict/{item.type}.json") as schema_file:
    validator = Draft202012Validator(json.load(schema_file))
errors = list(validator.iter_errors(item.data))
for error in errors:
    path = "/".join(str(p) for p in error.absolute_path) or "<root>"
    print(f"{path}: {error.message}")

I get the same Unevaluated properties are not allowed ('background', 'content', 'type' were unexpected).

I took the template pack, opened the tracker.jsonc, removed the 2 comments up top and changed the Map 1 map widget to include "blerf": "blerf",. If I remove that property again it validates fine (no errors).

It appears that the layout root matches the wrong thing and fails if an inner node has a bad property. If I put the "blerf": "blerf" right after "tracker_default": {, I get a sensible error ('blerf' was unexpected).

I tried with both py3.12 in my existing venv and py3.14 in a fresh venv where I only pip installed latest jsonschema.

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

Successfully merging this pull request may close these issues.

Canvas Child Additional Properties Support

2 participants