@@ -18,8 +18,7 @@ public class Jtd {
1818 /// Top-level definitions map for ref resolution
1919 private final Map <String , JtdSchema > definitions = new java .util .HashMap <>();
2020
21- /// Raw definition values for context-aware ref resolution
22- private final Map <String , JsonValue > rawDefinitions = new java .util .HashMap <>();
21+ // Removed: RFC 8927 strict mode - no context-aware compilation needed
2322
2423 /// Stack frame for iterative validation with path and offset tracking
2524 record Frame (JtdSchema schema , JsonValue instance , String ptr , Crumbs crumbs , String discriminatorKey ) {
@@ -285,11 +284,6 @@ void pushChildFrames(Frame frame, java.util.Deque<Frame> stack) {
285284
286285 /// Compiles a JsonValue into a JtdSchema based on RFC 8927 rules
287286 JtdSchema compileSchema (JsonValue schema ) {
288- return compileSchema (schema , false ); // Default: not from ref resolution
289- }
290-
291- /// Compiles a JsonValue into a JtdSchema with context-aware handling of {}
292- JtdSchema compileSchema (JsonValue schema , boolean fromRef ) {
293287 if (!(schema instanceof JsonObject obj )) {
294288 throw new IllegalArgumentException ("Schema must be an object" );
295289 }
@@ -308,19 +302,18 @@ JtdSchema compileSchema(JsonValue schema, boolean fromRef) {
308302 for (String key : defsObj .members ().keySet ()) {
309303 if (definitions .get (key ) == null ) {
310304 JsonValue rawDef = defsObj .members ().get (key );
311- rawDefinitions .put (key , rawDef ); // Store raw definition for context-aware ref resolution
312- // Compile definitions with fromRef=true for compatibility mode
313- JtdSchema compiled = compileSchema (rawDef , true );
305+ // Compile definitions normally (RFC 8927 strict)
306+ JtdSchema compiled = compileSchema (rawDef );
314307 definitions .put (key , compiled );
315308 }
316309 }
317310 }
318311
319- return compileObjectSchema (obj , fromRef );
312+ return compileObjectSchema (obj );
320313 }
321314
322- /// Compiles an object schema according to RFC 8927 with context-aware handling
323- JtdSchema compileObjectSchema (JsonObject obj , boolean fromRef ) {
315+ /// Compiles an object schema according to RFC 8927 with strict semantics
316+ JtdSchema compileObjectSchema (JsonObject obj ) {
324317 // Check for mutually-exclusive schema forms
325318 List <String > forms = new ArrayList <>();
326319 Map <String , JsonValue > members = obj .members ();
@@ -347,18 +340,15 @@ JtdSchema compileObjectSchema(JsonObject obj, boolean fromRef) {
347340 // Parse the specific schema form
348341 JtdSchema schema ;
349342
350- // Context-aware handling of {} - RFC vs compatibility mode
343+ // RFC 8927 strict: {} always means "no properties allowed"
351344 if (forms .isEmpty () && obj .members ().isEmpty ()) {
352- if (fromRef ) {
353- // Compatibility mode: {} from ref resolution behaves as EmptySchema (accept anything)
354- schema = new JtdSchema .EmptySchema ();
355- } else {
356- // RFC mode: {} at root or direct context behaves as PropertiesSchema (no properties allowed)
357- schema = new JtdSchema .PropertiesSchema (Map .of (), Map .of (), false );
358- }
345+ LOG .info (() -> "Empty schema {} encountered. "
346+ + "Note: In some JSON validation specs this means 'accept anything', "
347+ + "but per RFC 8927 it means an object with no properties allowed." );
348+ return new JtdSchema .PropertiesSchema (Map .of (), Map .of (), false );
359349 } else if (forms .isEmpty ()) {
360350 // Empty schema with no explicit form - default to EmptySchema for backwards compatibility
361- schema = new JtdSchema .EmptySchema ();
351+ return new JtdSchema .EmptySchema ();
362352 } else {
363353 String form = forms .getFirst ();
364354 schema = switch (form ) {
@@ -503,10 +493,7 @@ JtdSchema compileDiscriminatorSchema(JsonObject obj) {
503493 return new JtdSchema .DiscriminatorSchema (discStr .value (), mapping );
504494 }
505495
506- /// Gets raw definition value for context-aware ref resolution
507- JsonValue getRawDefinition (String ref ) {
508- return rawDefinitions .get (ref );
509- }
496+ // Removed: RFC 8927 strict mode - no context-aware ref resolution needed
510497
511498 /// Extracts and stores top-level definitions for ref resolution
512499 private Map <String , JtdSchema > parsePropertySchemas (JsonObject propsObj ) {
0 commit comments