Skip to content

IJPL-173071 JSON Schema: fix Draft 2020-12 meta-schema validation for const keyword#3438

Open
deinspanjer wants to merge 1 commit intoJetBrains:masterfrom
deinspanjer:dre/fix/IJPL-173071/fix-json-schema-2020-12-dynref
Open

IJPL-173071 JSON Schema: fix Draft 2020-12 meta-schema validation for const keyword#3438
deinspanjer wants to merge 1 commit intoJetBrains:masterfrom
deinspanjer:dre/fix/IJPL-173071/fix-json-schema-2020-12-dynref

Conversation

@deinspanjer
Copy link

Correct metadata inheritance priority in Draft 2020-12 to prevent root meta-schema constraints from incorrectly leaking into boolean schema definitions.

Key changes:

  • Corrected parameter order in InheritedJsonSchemaObjectView.kt helper functions to prioritize base schema over context.
  • Added a short-circuit in JsonSchemaAnnotatorChecker.java to skip type validation for constant schemas.
  • Ensured ConstantSchemaValidation takes precedence in JsonSchema202012Strategy.kt and jsonSchemaValidationsCollector.kt.

… const keyword

Correct metadata inheritance priority in Draft 2020-12 to prevent root meta-schema
constraints from incorrectly leaking into boolean schema definitions.

Key changes:
- Corrected parameter order in InheritedJsonSchemaObjectView.kt helper functions to prioritize base schema over context.
- Added a short-circuit in JsonSchemaAnnotatorChecker.java to skip type validation for constant schemas.
- Ensured ConstantSchemaValidation takes precedence in JsonSchema202012Strategy.kt and jsonSchemaValidationsCollector.kt.
@deinspanjer
Copy link
Author

I also did a git pickaxe with the help of Junie to make sure the order of the parameters wasn't flipped intentionally:

I have performed a git pickaxe (using both -S and -G flags) on InheritedJsonSchemaObjectView.kt to trace the history of those helper method calls.
Findings

  1. Original Implementation: The helper methods were introduced in the file's very first commit (9e2898c on March 13, 2025) by Nikita Katkov during a major refactoring ([json + remdev] IJPL-176240 Move classes...).
  2. The Parameters: From day one, these private extension functions were passing (other, base) to the underlying merger logic:
private fun InheritedJsonSchemaObjectView.booleanAndNullable(memberReference: JsonSchemaObject.() -> Boolean?): Boolean? {
  return booleanAndNullable(other, base, memberReference)
}

  1. No Intentional "Reversal" Found: I examined every commit since the file was created (mostly import optimizations and compilation fixes). There was no commit that explicitly swapped the order from (base, other) to (other, base). It appears it was simply written this way from the start.
  2. Verification of the Fix: In InheritedJsonSchemaObjectView, base represents the child/specific schema, and other represents the parent/context schema. By passing (other, base), the system was consistently prioritizing the parent context over the specific child properties.

Conclusion
The reversal you noticed was an original logic error from the initial implementation of the light-weight JSON schema nodes, rather than a deliberate change made later for a specific bug fix. Swapping them to (base, other) is correct and restores the expected "child overrides parent" inheritance model.
You can safely proceed with the rebase and commit cleanup as planned.

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.

2 participants