Skip to content

Validate config JSON against schema#919

Open
Symmetricity wants to merge 2 commits into
systemed:masterfrom
Symmetricity:fix/json-config-validation
Open

Validate config JSON against schema#919
Symmetricity wants to merge 2 commits into
systemed:masterfrom
Symmetricity:fix/json-config-validation

Conversation

@Symmetricity

Copy link
Copy Markdown
Contributor

This PR was prepared with AI assistance.

Tilemaker now validates config JSON against a schema before reading required
settings from it.

The schema lives in resources/config-schema.json so it can be read, reviewed,
and reused by editors or external validation tools. The build embeds that schema
into tilemaker:

  • CMake reads resources/config-schema.json and generates config_schema.h in
    the build directory.
  • The Makefile generates src/config_schema.h from the same schema file.
  • The generated Makefile header is ignored and removed by make clean.

This avoids a runtime dependency on finding a schema file while still keeping
the schema separate from the C++ code.

Why

Invalid config files could previously fail in two unhelpful ways:

  • Syntax errors only reported Invalid JSON file.
  • Structurally invalid but syntactically valid configs could reach
    Config::readConfig, where unchecked RapidJSON access could assert.

This specifically improves the cases reported in #867 and #875. For example,
the config attached to #875 is now rejected before readConfig with:

Invalid JSON file: missing required fields "compress", "name", "version", "description" at #/settings.

Other examples now include:

Invalid JSON file: Missing a comma or '}' after an object member. at offset 41.
Invalid JSON file: invalid type at #/layers/water/minzoom: expected "integer", got string.

Testing

Read the config schema from resources/config-schema.json and embed it at build time so tilemaker can validate configs without relying on a runtime schema path.

This catches missing or mistyped settings before Config::readConfig dereferences RapidJSON values, and improves parse errors by including RapidJSON's parse reason and byte offset.

Co-authored-by: Codex <noreply@openai.com>
@Symmetricity Symmetricity marked this pull request as ready for review June 20, 2026 09:43
The Docker build stage runs CMake before the runtime stage copies resources, so the generated config schema header could not be created inside Docker after adding config validation.

Copy only the schema file into the build stage to keep Docker cache invalidation narrow while making the CMake build match local builds.

Co-authored-by: Codex <noreply@openai.com>
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.

1 participant