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

JSON schema validation proposal #5852

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Commits on Jan 6, 2024

  1. add test/cli/test-json.py: Schema validation for JSON files.

    test-json.py uses jsonschema (https://pypi.org/project/jsonschema/) to validate
    JSON files against schemas, optionally with custom format checkers.
    
    All JSON files in the project must be accounted for in
    test-json.schema_mapping(), either as a schema, or as a file to be validated
    against a schema. The JSON schemas are implicitly validated against the most
    recent metaschema available in jsonschema.
    
    This commit adds schemas for JSON addon files and for namingng config files.
    
    TODO:
    - runtime schema validation
    - remove current ad-hoc validation
    - generate documentation from schemas
    mvds00 committed Jan 6, 2024
    Configuration menu
    Copy the full SHA
    b45061b View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    8ebd9bb View commit details
    Browse the repository at this point in the history

Commits on Jan 7, 2024

  1. lib/addoninfo.cpp: Add JSON schema validation.

    For JSON schema validation in cpp code, valijson
    (https://github.com/tristanpenman/valijson) is added. It supports picojson and
    is actively maintained. It is used in one-header-include style, because it
    seems the simplest solution, for now at least. The header is added, alongside
    the LICENSE file, in externals/valijson/.
    
    Various warnings that are emitted compiling the default code generated by
    valijson are fixed; these fixes are pushed upstream.
    
    As JSON is now validated against a schema, various ad-hoc checks could be
    safely removed.
    
    A simple way to test addon JSON schema validation, is to invoke cppcheck using:
    
       cppcheck --addon='{"script":1}' test.c
    
    A minor bugfix is that the file specified by "executable" was searched using
    getFullPath() with fileName as the second argument; it looks like this should
    have been exename.
    
    The fileName argument of parseAddonInfo() is only used for log messages, and is
    now replaced by the string "inline JSON" instead of the actual JSON string that
    was parsed. The command as given above will therefore output:
    
       Loading inline JSON failed. JSON schema validation failed: <root> [script]
       Value type not permitted by 'type' constraint., <root> Failed to validate
       against schema associated with property name 'script'.
    
    The addon JSON unit tests are also updated and now operate on JSON specified on
    the command line.
    mvds00 committed Jan 7, 2024
    Configuration menu
    Copy the full SHA
    b540616 View commit details
    Browse the repository at this point in the history