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

feat: adds validation logic with model load and initial validation logic #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jpower432
Copy link
Member

@jpower432 jpower432 commented Feb 10, 2025

Description

Adds option to validate when loading a model from an io.Reader. A noop validation is added for testing or when skipping validation is desired. A schema validator is added for validation against the OSCAL JSON schemas.

Rationale

The implemented validation logic is meant to be a post-decoding semantic validation of the models where a validation interface is added. The goal is to allow customized validation including combined validations before after decoding and before encoding. Adding the schema validation after unmarshaling to a struct has some performance overhead because of the requirement to encode back to JSON for validation against the schema.

Implementation for schema validation on raw JSON before decoding with this solution

With this solution the schema validation can still be done before load using a solution like the following with the underlying go-oscal validator

	data, err := os.ReadFile("catalog.json")
	if err != nil {
		return err
	}

	validator, err := oscalValidation.NewValidator(data)
	if err != nil {
		return err
	}

	err = validator.Validate()
	if err != nil {
		return err
	}

	byteReader := bytes.NewReader(data)
	

	// Replace noop validation with future semantic validation of choice
	definition, err := models.NewComponentDefinition(byteReader, validation.NoopValidator{})
	if err != nil {
		return err
	}

Fixes #40

Will need rebase after #36 merge

How has this been tested?

  • Unit tests added

Types of changes

  • Hot fix (emergency fix and release)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Documentation (change which affects the documentation site)
  • Breaking change (fix or feature that would cause existing functionality to change)

Quality assurance (all should be covered).

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes
  • All commits are signed-off.

@jpower432 jpower432 force-pushed the feat/oscal-schema-validation branch from 9d82fa5 to 6d27dd2 Compare February 14, 2025 21:08
Adds option to validate when loading a model from
a io.Reader. A noop validation is added for testing or when
skipping validation is desired. A schema validator is added for validation
against the OSCAL JSON schemas.

The implemented validation logic is meant to be a post-decoding semantic
validation of the models where a validation interface is added. The goal is to
allow customized validation including combined validations. Adding the schema validation after
unmarshaling to a struct has some performance overhead to the requirement to marshal
back to JSON for validation against the schema. This may be reevaluated, but proposing this
trade off be accepted for additional validation flexibility.

Signed-off-by: Jennifer Power <[email protected]>

feat: adds default SchemaValidator for the suppored OSCAL version

Signed-off-by: Jennifer Power <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Schema Validation
1 participant