You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add JSON schema validation for rules and tests (#626)
* Add JSON schema validation for rules and tests
Introduces JSON schema validation for Application Inspector rules using JsonSchema.Net. Adds RuleSchemaProvider and rule-schema.json, updates RulesVerifier and RuleStatus to support schema validation, and extends RulesVerifierOptions for configuration. Includes unit tests for schema validation in SchemaValidationTests.
* Update AppInspector.RulesEngine/Schema/RuleSchemaProvider.cs
Co-authored-by: Copilot <[email protected]>
* Update rule schema and improve schema validation tests
Changed 'must-match' and 'must-not-match' in rule-schema.json to arrays of strings with updated descriptions. Enhanced SchemaValidationTests to validate all embedded default rules using RuleSetUtils and provide detailed error reporting for failed schema validations.
* Cache schema validation results in rules
Adds a SchemaValidationResult property to Rule and updates TypedRuleSet to validate and store schema results when loading rules from JSON. RulesVerifier now uses the cached schema validation result if available, avoiding redundant validations. Also updates constructors to pass the schema provider and simplifies JSON serialization in RuleSchemaProvider.
* Remove line number and position from schema errors
Eliminated the inclusion of line number and position details from schema validation error and warning messages in RulesVerifier. Also removed the corresponding properties from the RuleSchemaProvider error class, simplifying error reporting.
* Remove debug code from schema validation test
Eliminated commented-out and unused debug code related to JSON serialization and error output in SchemaValidationTests. This cleanup improves test readability and removes unnecessary code.
* Add negative schema validation tests for rules
Introduces multiple unit tests to verify that invalid rule definitions fail schema validation as expected. Tests cover invalid pattern types, confidence levels, severities, scopes, empty arrays, missing required fields, and schema validation error handling at both error and warning levels.
* Update AppInspector.Tests/RuleProcessor/SchemaValidationTests.cs
Co-authored-by: Copilot <[email protected]>
* Update rule schema handling and add versioned schema
Moved rule-schema.json to the project root and updated its $id. Added rule-schema-v1.json as a new versioned schema file. Updated project and code references to use the new rule-schema-v1.json as the embedded resource.
* Update schema validation tests and remove rule-schema.json
Replaces deprecated Assert.Empty with Assert.Fail in SchemaValidationTests and simplifies type references for schema validation result and error classes. Also removes the rule-schema.json file, possibly indicating a migration to a different schema management approach.
* Refactor error collection to use stack instead of recursion
Replaces recursive calls in CollectErrorsFromResult with an explicit stack to avoid potential stack overflow on deeply nested validation results. This change improves robustness when processing large or deeply nested schemas.
---------
Co-authored-by: Copilot <[email protected]>
0 commit comments