Skip to content

JTD validator incorrectly defaults additionalProperties to true when no properties are defined #91

@simbo1905

Description

@simbo1905

Bug Description

The JTD validator has incorrect logic for handling the default value of additionalProperties in PropertiesSchema.

Current (Incorrect) Behavior

In Jtd.java line 446, when both properties and optionalProperties are empty, the code sets additionalProperties = true. This means an empty properties schema like {} or {additionalProperties: false} allows any additional properties.

Expected (Correct) Behavior

According to RFC 8927, additionalProperties should default to false when properties or optionalProperties are defined. An empty properties schema should reject additional properties by default.

Test Case That Reveals the Bug

Schema: {elements: {properties: {}}}
This should reject additional properties but currently allows them

This document should FAIL validation but currently PASSES:
[{}, {extraProperty:extra-value}]

Code Location

File: json-java21-jtd/src/main/java/json/java21/jtd/Jtd.java
Lines: 436-446

The fix should change line 446 from:
additionalProperties = true;
to:
additionalProperties = false;

This ensures that empty properties schemas reject additional properties by default, which is the correct RFC 8927 behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions