defenseunicorns / go-oscal

Repository for the generation of OSCAL data types
Apache License 2.0
15 stars 1 forks source link

refactor(validation)!: #274 refactor to accommodate updating to jsonschema v6 #282

Closed mike-winberry closed 2 months ago

mike-winberry commented 2 months ago

Description

jsonschema/v6 contains many changes to the compiler as well as the ValidationError leading to breaking changes in the validation package. Using the tests currently in place the updates should be made to ensure the maintenance of current behavior.

Type of change

Checklist before merging

mike-winberry commented 2 months ago

Changes look great! Testing various commands and want to request one modification.

Can you update the validate command and maybe migrate it away from RunE?

Noted duplicative output for the results to stdout:

dev@dev:~/work/go-oscal$ ./bin/go-oscal  validate -f testdata/validation/invalid-catalog.yaml -r output.yaml
go-oscal: 2024/07/18 17:16:31 WARNING: Currently using OSCAL version 1.0.4. The latest version is 1.1.2
Error: invalid OSCAL document, results: {
  "valid": false,
  "timeStamp": "2024-07-18T17:16:31.413900279Z",
  "errors": [
    {
      "keywordLocation": "/oneOf/0/properties/catalog/$ref/properties/metadata/$ref/required",
      "absoluteKeywordLocation": "https://github.com/defenseunicorns/go-oscal/tree/main/src/internal/schemas/oscal_complete_schema-1-0-4.json#/definitions/oscal-complete-oscal-metadata:metadata/required",
      "instanceLocation": "/catalog/metadata",
      "error": "\"missing property 'title'\""
    },
    {
      "keywordLocation": "/oneOf/0/properties/catalog/$ref/properties/metadata/$ref/properties/parties/items/$ref/properties/uuid/pattern",
      "absoluteKeywordLocation": "https://github.com/defenseunicorns/go-oscal/tree/main/src/internal/schemas/oscal_complete_schema-1-0-4.json#/definitions/oscal-complete-oscal-metadata:party/properties/uuid/pattern",
      "instanceLocation": "/catalog/metadata/parties/0/uuid",
      "error": "\"'invalid-uuid' does not match pattern '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$'\"",
      "failedValue": "invalid-uuid"
    },
    {
      "keywordLocation": "/oneOf/0/properties/catalog/$ref/properties/metadata/$ref/properties/links/items/$ref/properties/rel/pattern",
      "absoluteKeywordLocation": "https://github.com/defenseunicorns/go-oscal/tree/main/src/internal/schemas/oscal_complete_schema-1-0-4.json#/definitions/oscal-complete-oscal-metadata:link/properties/rel/pattern",
      "instanceLocation": "/catalog/metadata/links/0/rel",
      "error": "\"'https://something.com' does not match pattern '^(\\\\\\\\p{L}|_)(\\\\\\\\p{L}|\\\\\\\\p{N}|[.\\\\\\\\-_])*$'\"",
      "failedValue": "https://something.com"
    }
  ],
  "metadata": {
    "documentPath": "testdata/validation/invalid-catalog.yaml",
    "documentType": "catalog",
    "documentVersion": "1.0.4",
    "schemaVersion": "1.0.4"
  }
}
Usage:
  go-oscal validate [flags]

Flags:
  -h, --help                       help for validate
  -f, --input-file string          the path to a oscal json schema file
  -r, --validation-result string   the path to a validation result file

Global Flags:
  -l, --log-file string   the name of the file to write the log to (outputs to STDERR by default)

go-oscal: 2024/07/18 17:16:31 invalid OSCAL document, results: {
  "valid": false,
  "timeStamp": "2024-07-18T17:16:31.413900279Z",
  "errors": [
    {
      "keywordLocation": "/oneOf/0/properties/catalog/$ref/properties/metadata/$ref/required",
      "absoluteKeywordLocation": "https://github.com/defenseunicorns/go-oscal/tree/main/src/internal/schemas/oscal_complete_schema-1-0-4.json#/definitions/oscal-complete-oscal-metadata:metadata/required",
      "instanceLocation": "/catalog/metadata",
      "error": "\"missing property 'title'\""
    },
    {
      "keywordLocation": "/oneOf/0/properties/catalog/$ref/properties/metadata/$ref/properties/parties/items/$ref/properties/uuid/pattern",
      "absoluteKeywordLocation": "https://github.com/defenseunicorns/go-oscal/tree/main/src/internal/schemas/oscal_complete_schema-1-0-4.json#/definitions/oscal-complete-oscal-metadata:party/properties/uuid/pattern",
      "instanceLocation": "/catalog/metadata/parties/0/uuid",
      "error": "\"'invalid-uuid' does not match pattern '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$'\"",
      "failedValue": "invalid-uuid"
    },
    {
      "keywordLocation": "/oneOf/0/properties/catalog/$ref/properties/metadata/$ref/properties/links/items/$ref/properties/rel/pattern",
      "absoluteKeywordLocation": "https://github.com/defenseunicorns/go-oscal/tree/main/src/internal/schemas/oscal_complete_schema-1-0-4.json#/definitions/oscal-complete-oscal-metadata:link/properties/rel/pattern",
      "instanceLocation": "/catalog/metadata/links/0/rel",
      "error": "\"'https://something.com' does not match pattern '^(\\\\\\\\p{L}|_)(\\\\\\\\p{L}|\\\\\\\\p{N}|[.\\\\\\\\-_])*$'\"",
      "failedValue": "https://something.com"
    }
  ],
  "metadata": {
    "documentPath": "testdata/validation/invalid-catalog.yaml",
    "documentType": "catalog",
    "documentVersion": "1.0.4",
    "schemaVersion": "1.0.4"
  }
}

Fixed duplicative output and noisy usage messages.

go-oscal: 2024/07/29 10:07:29 WARNING: Currently using OSCAL version 1.0.4. The latest version is 1.1.2
go-oscal: 2024/07/29 10:07:29 invalid OSCAL document, results: {
  "valid": false,
  "timeStamp": "2024-07-29T10:07:29.693433-07:00",
  "errors": [
    {
      "keywordLocation": "/oneOf/0/properties/catalog/$ref/properties/metadata/$ref/required",
      "absoluteKeywordLocation": "https://github.com/defenseunicorns/go-oscal/tree/main/src/internal/schemas/oscal_complete_schema-1-0-4.json#/definitions/oscal-complete-oscal-metadata:metadata/required",
      "instanceLocation": "/catalog/metadata",
      "error": "\"missing property 'title'\""
    },
    {
      "keywordLocation": "/oneOf/0/properties/catalog/$ref/properties/metadata/$ref/properties/links/items/$ref/properties/rel/pattern",
      "absoluteKeywordLocation": "https://github.com/defenseunicorns/go-oscal/tree/main/src/internal/schemas/oscal_complete_schema-1-0-4.json#/definitions/oscal-complete-oscal-metadata:link/properties/rel/pattern",
      "instanceLocation": "/catalog/metadata/links/0/rel",
      "error": "\"'https://something.com' does not match pattern '^(\\\\\\\\p{L}|_)(\\\\\\\\p{L}|\\\\\\\\p{N}|[.\\\\\\\\-_])*$'\"",
      "failedValue": "https://something.com"
    },
    {
      "keywordLocation": "/oneOf/0/properties/catalog/$ref/properties/metadata/$ref/properties/parties/items/$ref/properties/uuid/pattern",
      "absoluteKeywordLocation": "https://github.com/defenseunicorns/go-oscal/tree/main/src/internal/schemas/oscal_complete_schema-1-0-4.json#/definitions/oscal-complete-oscal-metadata:party/properties/uuid/pattern",
      "instanceLocation": "/catalog/metadata/parties/0/uuid",
      "error": "\"'invalid-uuid' does not match pattern '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$'\"",
      "failedValue": "invalid-uuid"
    }
  ],
  "metadata": {
    "documentPath": "testdata/validation/invalid-catalog.yaml",
    "documentType": "catalog",
    "documentVersion": "1.0.4",
    "schemaVersion": "1.0.4"
  }
}