Skip to content

Simplify enum deduplication logic in JtdPropertyTest #104

Open

Description

@simbo1905

Issue #99: Enforce RFC 8927 semantics for {} schema and remove AJV compatibility

Problem

Current codebase contains legacy AJV/JSON Schema compatibility where {} could mean "accept anything".
This contradicts RFC 8927: {} always means an object with no properties allowed
(properties = {}, optionalProperties = {}, additionalProperties = false).

This dual behavior causes complexity and test contradictions.

Goals

  1. Rip out all AJV-style "compatibility mode" handling (fromRef, EmptySchema fallback).
  2. Make {} always RFC 8927 strict (PropertiesSchema with no properties, no additionalProperties).
  3. Add an INFO log warning whenever {} is compiled to help developers spot semantic differences from AJV/JSON Schema.
  4. Rewrite AJV-derived tests to expect failures or exceptions under RFC mode.
  5. Update README.md and AGENTS.md to document the difference.

Implementation Notes

  • Follow Markdown-Driven-Development: update documentation before code
  • Add INFO-level logging when {} schema is compiled
  • Ensure all tests validate strict RFC 8927 behavior
  • Update user-facing documentation to explain the semantic difference

EOF < /dev/null

Activity

  1. simbo1905 commented on Jan 26, 2026

    @simbo1905
    OwnerAuthor

    Analysis of Current State (main branch after PR #117 merge)

    Issue Body Mismatch ⚠️

    Note: The issue body appears to contain copy-paste content from issue #99 about RFC 8927 semantics. This analysis addresses the title: "Simplify enum deduplication logic in JtdPropertyTest".

    Current Implementation

    File: json-java21-jtd/src/test/java/json/java21/jtd/JtdPropertyTest.java (lines 263-269)

    private static Arbitrary<JtdTestSchema> enumSchemaArbitrary() {
      // Ensure no duplicates by using distinct values
      return Arbitraries.of(ENUM_VALUES).list().ofMinSize(1).ofMaxSize(4).map(values -> {
        // Remove duplicates to ensure valid enum schema per RFC 8927
        List<String> distinctValues = values.stream().distinct().toList();
        return new EnumSchema(new ArrayList<>(distinctValues));
      });
    }

    Problem

    The current approach:

    1. Generates lists that may contain duplicates
    2. Post-processes with stream().distinct() to remove them
    3. This is inefficient and unnecessarily complex

    Suggested Fix

    jqwik provides ListArbitrary.uniqueElements() which generates unique elements at generation time:

    private static Arbitrary<JtdTestSchema> enumSchemaArbitrary() {
      // Use jqwik's uniqueElements() to ensure no duplicates per RFC 8927
      return Arbitraries.of(ENUM_VALUES).list()
          .ofMinSize(1)
          .ofMaxSize(4)
          .uniqueElements()
          .map(values -> new EnumSchema(new ArrayList<>(values)));
    }

    Benefits

    1. Cleaner code: Removes intermediate stream processing
    2. More efficient: Uniqueness enforced at generation time, not post-processing
    3. Idiomatic jqwik: Uses the library's built-in uniqueness constraint
    4. Better shrinking: Works better with jqwik's shrinking algorithm

    Scope

    This is a small, isolated change affecting only the private enumSchemaArbitrary() helper method. No other tests affected.

    Clarification Needed

    Please confirm if this issue is only about the enum deduplication simplification (per the title), or if the RFC 8927 content in the body is also intended to be addressed here.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions