Fix schema with “properties” and “additionalProperties”#80
Open
cwalther wants to merge 2 commits intolbovet:masterfrom
Open
Fix schema with “properties” and “additionalProperties”#80cwalther wants to merge 2 commits intolbovet:masterfrom
cwalther wants to merge 2 commits intolbovet:masterfrom
Conversation
Currently fails with "oops – TypeError: Attempted to assign to readonly property.".
The error is encountered when rendering a schema containing both "properties" and "additionalProperties" and occurs because the "name" helper is invoked with Handlebars' nullContext, a read-only empty object. Checking for "additionalProperties" and then rendering "../additionalProperties" makes no sense. I'm not sure why this worked previously (apparently the parent context was the same as the current context at some point), it seems to have been broken in 7d17a0d where many dependencies were updated over several major versions.
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.
Rendering a schema containing both “properties” and “additionalProperties” currently fails with
oops – TypeError: Attempted to assign to readonly property.printed to the console.The source of the TypeError is that the “name” helper is invoked with Handlebars’
nullContextas the first argument, a read-only empty object, coming from{{schema ../additionalProperties}}in box.html. This strikes me as making no sense – why get the property from the parent context after checking for it on the current context using{{#if additionalProperties}}?This used to work, but I’m not even sure why – apparently the parent context was the same as the current context at that invocation, at some point. I could’t quite figure out what broke it – bisection indicates it seems to have happened in 7d17a0d, where not much happened in the Docson code, but many dependencies, including Handlebars, were updated over several major versions in the switch from bundled libraries to ones installed by npm. I didn’t dig any deeper than that.
The attached commits add a test that currently fails, using a schema from tests/additionalProperties.json (if those manual tests were still working, maybe the bug would have been noticed earlier), as well as a fix.
(We are getting closer to the bug I actually wanted to fix, but this is not it yet. 🙂)