Skip to content

Conversation

@simbo1905
Copy link
Owner

Summary

This PR addresses issue #102 by implementing comprehensive discriminator validation with compile-time enforcement and purely stack-based runtime validation.

Key Changes

Compile-time Discriminator Validation (RFC 8927 §2.2.8)

  • ✅ Enforce that discriminator mapping values must be PropertiesSchema (not EmptySchema)
  • ✅ Prevent nullable discriminator mappings with clear error messages
  • ✅ Validate that discriminator keys are not redefined in mapping schema properties/optionalProperties
  • ✅ Provide detailed error messages with actual values and schema context

Stack-based Runtime Validation

  • ✅ Refactored EnumSchema and TypeSchema to use validateWithFrame exclusively
  • ✅ Moved validation logic from direct validate() methods to frame-based approach
  • ✅ Enhanced error messages with offset and path information
  • ✅ Maintained backward compatibility through delegation patterns

Test Improvements

  • ✅ Fixed property test generation to avoid discriminator key conflicts
  • ✅ Updated manual tests to comply with RFC 8927 discriminator constraints
  • ✅ All validation now uses the iterative stack-based approach
  • ✅ Clear, descriptive error messages for all discriminator violations

Test Results

  • All 96 tests passing including property-based tests with 1000 generated cases
  • Full RFC 8927 compliance test suite passing
  • Integration tests with official JTD Test Suite passing

Implementation Details

The implementation ensures that:

  1. Invalid discriminators are rejected at compile time with clear, descriptive error messages
  2. Runtime validation uses purely stack-based approach without duplicate validation paths
  3. Discriminator tag exemption rules are properly enforced per RFC 8927 §2.2.8
  4. Error messages include full context with actual values, expected types, and schema location

This addresses the core requirements in issue #102 to tighten compile-time schema checks and rely exclusively on the stack validator for discriminators.

Closes #102

simbo1905 and others added 4 commits September 28, 2025 18:11
…error and use purely stack based runtime

This commit addresses issue #102 by implementing comprehensive discriminator validation with the following improvements:

**Compile-time Discriminator Validation (RFC 8927 §2.2.8):**
- Enforce that discriminator mapping values must be PropertiesSchema (not EmptySchema)
- Prevent nullable discriminator mappings with clear error messages
- Validate that discriminator keys are not redefined in mapping schema properties/optionalProperties
- Provide detailed error messages with actual values and schema context

**Stack-based Runtime Validation:**
- Refactored EnumSchema and TypeSchema to use validateWithFrame exclusively
- Moved validation logic from direct validate() methods to frame-based approach
- Enhanced error messages with offset and path information
- Maintained backward compatibility through delegation patterns

**Key Improvements:**
- Fixed property test generation to avoid discriminator key conflicts
- Updated manual tests to comply with RFC 8927 discriminator constraints
- All validation now uses the iterative stack-based approach
- Clear, descriptive error messages for all discriminator violations

**Test Results:**
- All 96 tests passing including property-based tests with 1000 generated cases
- Full RFC 8927 compliance test suite passing
- Integration tests with official JTD Test Suite passing

This implementation ensures discriminators are validated at compile time with clear error messages and uses the purely stack-based runtime approach as requested in issue #102.

Closes #102
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@simbo1905 simbo1905 requested a review from Copilot September 28, 2025 20:41
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses issue #102 by implementing comprehensive discriminator validation with compile-time enforcement and purely stack-based runtime validation. The changes ensure that invalid discriminators are rejected at compile time with clear error messages, while all runtime validation uses an iterative stack-based approach for consistency and performance.

  • Implemented compile-time discriminator validation per RFC 8927 §2.2.8 requirements
  • Refactored EnumSchema and TypeSchema to use purely stack-based validation
  • Enhanced test suites with property-based test improvements and new compilation tests

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
TestValidationErrors.java Updated error message format for unknown type validation
TestRfc8927.java Removed discriminator key redefinitions to comply with RFC 8927
JtdSpecIT.java Removed invalid schema tests that are now handled by separate compiler tests
JtdPropertyTest.java Fixed property test generation to avoid discriminator conflicts and improved error reporting
CompilerTest.java New comprehensive test suite for compile-time discriminator validation
CompilerSpecIT.java New integration test suite for official JTD invalid schema tests
JtdSchema.java Refactored TypeSchema and EnumSchema to use stack-based validation exclusively
Jtd.java Enhanced compiler with discriminator validation and better error handling
README.md Added documentation for discriminator constraints
ARCHITECTURE.md Enhanced architecture documentation with single-path validation details
PLAN.md Added comprehensive project plan documentation
AGENTS.md Enhanced error message standards and guidance
ci.yml Updated expected test count to reflect new test additions

@simbo1905 simbo1905 requested a review from Copilot September 28, 2025 22:05
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

@openhands-ai
Copy link

openhands-ai bot commented Sep 28, 2025

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • CI
    • CI

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #103 at branch `issue-102-discriminator-validation`

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

@simbo1905 simbo1905 merged commit 24166a4 into main Sep 28, 2025
4 checks passed
@simbo1905 simbo1905 deleted the issue-102-discriminator-validation branch September 28, 2025 22:33
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.

reject invalid discriminators at compile time with clear error and use purely stack based runtime

2 participants