Validation and JSON Schema
Editor autocomplete with the published JSON Schemas, and how the runtime validator treats errors and warnings.
JSON Schema in your editor
Upwell publishes JSON Schemas for both files. Add $schema to get autocomplete, hover docs and
inline errors in VS Code and other editors:
{
"$schema": "https://upwell.run/schemas/policy.schema.json",
"schemaVersion": 1
}| File | Schema |
|---|---|
policy.json | https://upwell.run/schemas/policy.schema.json |
releases.json | https://upwell.run/schemas/releases.schema.json |
The schemas also ship in the packages (upwell/schemas/policy.schema.json, or
@upwell/core/schemas/policy.schema.json), so you can validate in CI with any JSON Schema validator:
npx ajv-cli validate --spec=draft7 -s node_modules/upwell/schemas/policy.schema.json -d policy.jsonThe runtime validator
Every fetched policy goes through validatePolicy() before it's used. It's stricter than the schema:
| Check | Result |
|---|---|
schemaVersion isn't 1 | Error |
version / build aren't comparable (e.g. "three") | Error |
releasedAt isn't an ISO date | Error |
minimum.build is above latest.build | Error: every install would be blocked with nothing to update to |
rollout outside 0–100, negative day counts | Error |
Unknown applyMode | Error |
appStoreId isn't numeric, country isn't two letters | Error |
requireAfterDays below recommendAfterDays | Warning: users skip the recommendation |
| Unknown keys | Warning, ignored |
Errors reject the whole policy, and Upwell keeps using the last valid copy. Warnings don't stop anything, so newer policies stay compatible with older app versions.
releases.json is validated the same way with validateReleases(): required fields, known kind
and platforms values, ISO timestamps, and unique ids.
Validating in CI
The CLI runs the same validators and fails with exit code 1 on errors:
npx @upwell/cli policy validate
npx @upwell/cli releases validateOr call them yourself: the validators are plain functions from
@upwell/core, which has no dependencies, so a plain Node script
can run them and fail CI before you publish a broken policy:
import { readFileSync } from 'node:fs';
import { validatePolicy, validateReleases } from '@upwell/core';
const read = (path) => JSON.parse(readFileSync(path, 'utf8'));
let failed = false;
for (const [name, result] of [
['policy.json', validatePolicy(read('upwell/policy.json'))],
['releases.json', validateReleases(read('upwell/releases.json'))],
]) {
for (const w of result.warnings) console.warn(`${name}: ${w}`);
if (!result.ok) {
for (const e of result.errors) console.error(`${name}: ${e}`);
failed = true;
}
}
process.exit(failed ? 1 : 0);Add @upwell/core as a dev dependency for this (it's already installed with upwell, but list
what you import). Or run the same checks in your app's existing Jest setup:
import { validatePolicy, validateReleases } from 'upwell';
import policy from '../upwell/policy.json';
import releases from '../upwell/releases.json';
test('policy.json is valid', () => {
const result = validatePolicy(policy);
expect(result.ok ? [] : result.errors).toEqual([]);
expect(result.warnings).toEqual([]);
});
test('releases.json is valid', () => {
const result = validateReleases(releases);
expect(result.ok ? [] : result.errors).toEqual([]);
});You can also assert decisions there with decide(), e.g. "build 290
is required to update".
A dedicated npx @upwell/cli validate command is on the roadmap.
Seeing errors on a device
Validation errors show up in the trace:
policy: latest fetch failed (invalid policy: policy.android.minimum.build: 400 is above latest.build 340; …); using last known goodRead it with explain(), the dev menu, debug: true, or onError.