Last updated: 14 Oct 2024
publishing-api: Changing an existing content schema
When not adding or removing top-level fields
This describes how to add or remove fields that extend the top-level fields
defined in default_format.jsonnet
. For example, if you wanted to submit an
additional field via a form in a publishing app, you might add a field nested
within details
(a field already defined in default_format.jsonnet
).
- If you're adding or removing a required field:
- Update publishing app(s) to provide/stop providing the field
- If removing a field, update frontend app(s) to no longer access the soon-to-be-removed field
- Update existing data in Content Store to ensure they conform with the incoming schema changes
- Update the relevant schema fragment under
content_schemas/formats/<format_name>.jsonnet
- Add or remove the desired
details
>properties
property - If the field is/was required, update the
details
>required
array
- Add or remove the desired
- If necessary, add, remove or update relevant definition file within
content_schemas/formats/shared/definitions
to add or remove the definition for the field - Add, remove, or update the relevant example schemas in
content_schemas/examples/**/<example_name>.jsonnet
- Run
rake build_schemas
to compile the updated schemas incontent_schemas/dist/
and validate the example schemas - Check that all the CI workflows pass. These will verify that the content schemas are compatible with the suite of publishing apps
Non-top-level field examples
- Adding a new optional field to the
details
property - Adding a new definition
- Updating a definition
- Requiring a property
When adding or removing top-level fields
This describes how to add or remove top-level fields to the default format.
These fields tend to be overridden in .jsonnet
schemas that extend
default_format.jsonnet
. This allows you to, among other things, define a
top-level "forbidden"
field that should not be provided by consumers of the
API, then allow it for schemas further down the chain by marking it as
"optional"
.
- If you're adding or removing a required field:
- Update publishing app(s) to provide/stop providing the field
- If removing a field, update frontend app(s) to no longer access the soon-to-be-removed field
- Update existing data in Content Store to ensure they conform with the incoming schema changes
- Add/remove the new field in
default_format.jsonnet
, giving it a status ofrequired
,optional
,forbidden
ornull
. - Add/remove the new definition file for this field type in
content_schemas/formats/shared/definitions
. This will need to include a definition for the field and a definition for theoptional
/required
/forbidden
status where relevant. This will be read by theformat
code in the next step - Add a new method named after this field to
lib/schema_generator/format.rb
to have it written to the generated files. This specifies which definition to use based on the status specified injsonnet
schema - Add a new key to the
derived_properties
method's hash to read the value inlib/schema_generator/{publisher_content/frontend/notification}_schema_generator.rb
when generating the schema - Update any extending
jsonnet
files to override this value by setting a different status against this field where required, e.g. to mark a defaultforbidden
field asoptional
at a lower level - Run
rake build_schemas
to compile the updated schemas incontent_schemas/dist/
and validate the example schemas - Check that all the CI workflows pass. These will verify that the content schemas are compatible with the suite of publishing apps