Messaging System Schemas¶
Docs¶
More information about Messaging System.
Messages¶
There are JSON schemas for each type of message that the Firefox Messaging System handles:
Together, they are combined into the Messaging Experiments via a script. This is the schema used for Nimbus experiments that target messaging features. All incoming messaging experiments will be validated against this schema.
Schema Changes¶
To add a new message type to the Messaging Experiments schema:
Add your message template schema.
Your message template schema only needs to define the following fields at a minimum:
template
: a string field that defines an identifier for your message. This must be either aconst
orenum
field.For example, the
template
field of Spotlight looks like:{ "type": "string", "const": "spotlight" }
content
: an object field that defines your per-message unique content.
If your message requires
targeting
, you must add a targeting field.If your message supports triggering, there is a definition you can reference the
MessageTrigger
shared definition.The
groups
,frequency
, andpriority
fields will automatically be inherited by your message.Ensure the schema has an
$id
member. This allows for references (e.g.,{ "$ref": "#!/$defs/Foo" }
) to work in the bundled schema. See docs on bundling JSON schemas for more information.Add the new schema to the list in make-schemas.py.
Build the new schema by running:
cd browser/components/asrouter/content-src/schemas/ ../../../../../mach python make-schemas.py
Commit the results.
Likewise, if you are modifying a message schema you must rebuild the generated schema:
cd browser/components/asrouter/content-src/schemas/
../../../../../mach python make-schemas.py
If you do not, the Firefox MS Schemas CI job will fail.
You can run this locally via:
cd browser/components/asrouter/content-src/schemas/
../../../../../mach xpcshell extract-test-corpus.js
../../../../../mach python make-schemas.py --check
This test will re-generate the schema and compare it to
MessagingExperiment.schema.json
. If there is a difference, it will fail.
The test will also validate the list of in-tree messages with the same schema
validator that Experimenter uses to ensure that our schemas are compatible with
Experimenter.
Schema Tests¶
We have in-tree tests (Test_CFRMessageProvider, Test_OnboardingMessageProvider, and Test_PanelTestProvider), which validate existing messages with the generated schema.
We also have compatibility tests for ensuring that our schemas work in Experimenter. Experimenter uses a different JSON schema validation library, which is reused in the Firefox MS Schemas CI job. This test validates a test corpus from CFRMessageProvider, OnboardingMessageProvider, and PanelTestProvider with the same JSON schema validation library and configuration as Experimenter.
See how to run these tests above.