Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errata01 schema addition to region is invalid #578

Closed
sthagen opened this issue May 20, 2023 · 2 comments
Closed

Errata01 schema addition to region is invalid #578

sthagen opened this issue May 20, 2023 · 2 comments

Comments

@sthagen
Copy link
Contributor

sthagen commented May 20, 2023

Symptoms

Current schema raises errors like:

Unexpected token encountered when reading value for 'anyOf'. Expected StartObject, got StartArray. Path 'definitions.region.properties.anyOf', line 1783, position 18.

Or (using a different tool):

#/definitions/region/properties/anyOf: expected type is one of Boolean or JsonObject, found: JsonArray

Cause

The problem is not the ingredients of the anyOf we use here, those are OK but the embedding into the region object.

Unfortunately the schema implementation of the added anyOf constraint in the ERRATA01 is invalid as the confusingly named properties key of our domain specific language may have led us to believe we should inject the anyOf directly following that object.

    "region": {
      "description": "A region within an artifact where a result was detected.",
      "additionalProperties": false,
      "type": "object",
      "properties": {
        "snip": "some ... - - - 8< - - -",
        "properties": {
          "description": "Key/value pairs that provide additional information about the region.",
          "$ref": "#/definitions/propertyBag"
        },
        "anyOf": [
          { "required": [ "startLine" ] },
          { "required": [ "charOffset" ] },
          { "required": [ "byteOffset" ] }
        ]
      }
    },

Cure

Instead we should inject it following the outer propertiesobject (that is a JSON Schema key adhering object). Like so:

  "region": {
    "description": "A region within an artifact where a result was detected.",
    "additionalProperties": false,
    "type": "object",
    "properties": {
      "snip": "some ... - - - 8< - - -",
      "properties": {
          "description": "Key/value pairs that provide additional information about the region.",
          "$ref": "#/definitions/propertyBag"
      }
    },
    "anyOf": [
      { "required": [ "startLine" ] },
      { "required": [ "charOffset" ] },
      { "required": [ "byteOffset" ] }
    ]
  },

Then validation succeeds.

Diff

The diff (against the failing complete JSON file in the distributed errata package at https://www.oasis-open.org/committees/document.php?document_id=71047&wg_abbrev=sarif) is:

❯ diff -u ../errata_bundle_20230519/sarif-schema-2.1.0-errata01-csd01-complete.json sarif-schema-2.1.0-errata01-csd01-complete.json
--- ../errata_bundle_20230519/sarif-schema-2.1.0-errata01-csd01-complete.json	2023-05-03 16:23:56.000000000 +0200
+++ sarif-schema-2.1.0-errata01-csd01-complete.json	2023-05-20 13:39:13.000000000 +0200
@@ -1778,14 +1778,13 @@
         "properties": {
           "description": "Key/value pairs that provide additional information about the region.",
           "$ref": "#/definitions/propertyBag"
-        },
-
-        "anyOf": [
-          { "required": [ "startLine" ] },
-          { "required": [ "charOffset" ] },
-          { "required": [ "byteOffset" ] }
-        ]
-      }
+        }
+      },
+      "anyOf": [
+        { "required": [ "startLine" ] },
+        { "required": [ "charOffset" ] },
+        { "required": [ "byteOffset" ] }
+      ]
     },

     "replacement": {

The tricky thing (in 2023) is, to debug draft4 JSON Schema issues as not all "alive" validators support such archaic versions.

@dmk42
Copy link
Contributor

dmk42 commented May 25, 2023

Thanks. We should definitely address this before publishing the errata.

@dmk42
Copy link
Contributor

dmk42 commented Jun 13, 2023

Thanks again. This has been addressed with the 2023-06-12 errata bundle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants