Providing JSON schemas for Foundry VTT module.json / system.json manifests & League of Extraordinary Foundry Developers
manifest+ extensions in addition to compiled validator functions. The current manifest+ support is v1.1.0
.
There are four schema variations.
ATTENTION: validate-manifest
needs contributors to help update the schema covered for the latest Foundry v11
manifests. The current released NPM version covers Foundry v8. The infrastructure for this project is thoroughly updated
and working smoothly as of Jan '23. As the maintainer I'd be glad to help get any contributors onboarded with how to
build and update the schemas.
The schemas submitted to the JSON schema store are not from this effort. In an ideal world this project gets updated for Foundry v11 and new schemas are submitted to the schema store. In the future this project can be potentially versioned allowing manual installation of specific Foundry versions as the schema store gets updated for the latest Foundry version.
For end developers it is useful to set up the appropriate JSON schema with your IDE. Check these links for IDE info for
Webstorm or
VS Code. Point to the relevant JSON
schema file found in ./schema
and enable intellisense in your IDE. For reference since this is a NPM module you will
link ./node_modules/@typhonjs-fvtt/validate-manifest/schema/module+.json
. The schema files ending in +
include the standard manifest and manifest plus coverage.
There are 4 schemas available:
./schema/module.json
./schema/module+.json
./schema/system.json
./schema/system+.json
For Foundry VTT tools developers and anyone needing to validate manifest files. The validator functions are compiled
by ajv
and are located in the ./dist
directory. The main entry point for the NPM module points to the
./dist/validators.js
.
There are 4 validator functions:
- validateModule
- validateModulePlus
- validateSystem
- validateSystemPlus
A trivial example of using the validateModule
function.
import fs from 'fs';
import { validateModule } from '@typhonjs-fvtt/validate-manifest';
const moduleJSONObject = JSON.parse(fs.readFileSync('./src/module.json', 'utf8');); // load from some location.
if (!validateModule(moduleJSONObject))
{
console.log(JSON.stringify(validateModule.errors);
}
Please see ajv and ajv-errors for
more information about the validator functions and resulting error entries stored in the errors
array after a
validator function is invoked. Considerable work has been done to ensure that one condition resolves to one error
listed in the errors
array. There is a comprehensive test suite which covers all possible errors that may occur
with data contained in the manifest files.
If you are planning on displaying error information to end users you may want to take a look at the
@typhonjs-utils/better-ajv-errors module
which formats the errors array with user readable messages and associated code frames. An example of using the
better-ajv-errors
module.
import fs from 'fs';
import BetterErrors from '@typhonjs-utils/better-ajv-errors';
import { validateModule } from '@typhonjs-fvtt/validate-manifest';
const moduleJSONFile = fs.readFileSync('./src/module.json', 'utf8'); // load the text string for the manifest.
const moduleJSONObject = JSON.parse(moduleJSONFile); // parse the manifest file.
if (!validateModule(moduleJSONObject))
{
console.log(BetterErrors.asString(validateModule.errors, { file: moduleJSONFile }));
}
A very brief overview... The base source schemas is shared across all variations and located in ./src/schema
and is
compiled / dereferenced into single file variations in ./schema
by the compile
NPM script. There
is a custom merge step with template includes found in ./src/schema/merge
. These are common definitions which are
then combined into the final schema files.
Please reach out and get in touch if you need any more assistance at the issues forum.
npm install
npm run compile
- Compiles the schemas and validation codenpm run test
- Compiles then runs tests.