fix: strictSchema "log" should warn (not throw) on unknown format#2636
Open
chatman-media wants to merge 1 commit into
Open
fix: strictSchema "log" should warn (not throw) on unknown format#2636chatman-media wants to merge 1 commit into
chatman-media wants to merge 1 commit into
Conversation
The format keyword's unknownFormat() only special-cased strictSchema === false (log) and threw for everything else, so strictSchema: "log" incorrectly threw instead of logging a warning. Replace the hand-rolled branch with the shared checkStrictMode helper, which correctly handles the true/false/"log" tri-state used everywhere else and is silent (not a warning) when strict mode is disabled. Closes ajv-validator#2538
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2538.
What issue does this pull request resolve?
With
strictSchema: "log", an unknownformatin a schema throws an exception instead of logging a warning. Per the documented option values,"log"should log a warning while onlytrueshould throw.Root cause
In
lib/vocabularies/format/format.ts,unknownFormat()only special-casedopts.strictSchema === false(warn) and threw for every other value. Since"log"is not=== false, it fell through tothrow. As a side effect,strictSchema: falsealso emitted a warning, whereas it should be silent ("ignore all strict schema violations").Fix
Replace the hand-rolled branch with the shared
checkStrictModehelper (lib/compile/util.ts), which is already used throughout the codebase for thetrue | false | "log"tri-state:true→ throw"log"→logger.warnfalse→ silent (no-op)This also makes the message consistent with every other strict-mode violation (prefixed with
strict mode:).Tests
Added
spec/issues/2538_strict_schema_log_unknown_format.spec.tscovering all three modes. The"log"andfalsecases fail onmasterand pass with this change;truestill throws. Existingspec/options/unknownFormats.spec.tsand the strict-mode suites remain green, and the full JSON Schema conformance suite passes.