addons-linter icon indicating copy to clipboard operation
addons-linter copied to clipboard

Propagate min/max_manifest_version set on JSONSchema `type: array` entries into its `items` sub-property as part of the Firefox API schema data import

Open rpl opened this issue 4 years ago • 0 comments

As part of #3763, we did notice that:

  • we need to explicitly set min/max_manifest_version on the items sub-property of the JSONSchema type: array entries that have a min/max_manifest_version
  • because we need to make sure that the validation errors collected from those manifest properties are going to have a min/max_manifest_version property available as error.parentSchema.min_manifest_version/max_manifest_version, so that we can determine if they are actually relevant for the manifest_version set on the addon being validated.

Because of how ajv works, the validation errors collected will have access to the schema that triggered the validation error (available as error.schema) and to the schema of the parent entry (available as error.parentSchema), but there is no reference to the other ascendants.

This means that errors triggered by a schema entry nested more than 1 level inside one using the custom keywords min/max_manifest_version isn't going to include the details we need to determine if it is relevant.

In #3763 we opted to propagate min/max_manifest_version from the type: "array" entries to their items sub-property at runtime, and only for the entries that are actually being hit during the addon validation, as a short run solution.

This issue goal is to do that at import time (from src/schema/firefox-schemas-import.js) and remove the short-run solution introduced in #3763 (added into the definition of the min_manifest_version and max_manifest_version ajv custom keywords handlers).

As an example the web_accessible_resources manifest property JSONSchema is defined as follows:

"web_accessible_resources": {
  "anyOf": [
    ...,
    {
      "min_manifest_version": 3,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "resources": {
            "type": "array",
            "items": {
               "type": "string"
            }
          },
          "matches": {
            "type": "array",
            "items": {
              "$ref": "#/types/MatchPatternRestricted"
            }
          }
        },
        "required": ["resources", "matches"]
      }
    }
  ]
},
...
  • based on a validation error collected for "matches" or resources we would not know if the error was part of schema data only relevant when manifest_version in >= 3

rpl avatar Jun 17 '21 16:06 rpl