Fixed extra:analytics
schema for custom providers
#6361
Merged
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.
I've fixed the JSON schema for specifying custom providers which don't use the
property
property like Google Analytics and/or have additional properties.This is a set of test cases that show the current validation results in VS Code:
With the changed schema in this PR, all test cases yield the expected results.
Before, the schema didn't couple
provider: google
with makingproperty
required, and as a side-effect,property
was always defined using a schema specific to Google Analytics. Further,additionalProperties: false
prevented any other custom properties that may be needed for some analytics solution.Now,
provider: google
,property
with the Google-specific schema, declaring both as required properties, and disallowing additional properties are all coupled. For any otherprovider: <string>
, additional properties are allowed without defined schemas. The probably obvious approaches to express this with JSON Schema are to useoneOf
, which doesn't work because the schema forprovider: <string>
is a superset ofprovider: google
, so more than one schema matches, oranyOf
as an attempt at fixing the problem withoneOf
, but then theprovider: <string>
schema matches always and the additional constraints from theprovider: google
schema don't apply.The solution I've implemented uses a combination of
allOf
andif-then
(withoutelse
), such that any valid config of a defined provider (only Google Analytics at the moment) matches both the corresponding schema and theprovider: <string>
schema, whereas a config of a custom provider matches only theprovider: <string>
schema. Note that it's important to declare also thefeedback
property in eachallOf
schema of a specific provider becauseadditionalProperties: false
limits the set of valid properties only to those defined in the same schema and doesn't recognize thefeedback
property schema in the parent schema ofallOf
. But for clarity, I've also declared thefeedback
property in theprovider: <string>
schema, although it isn't necessary as the missingadditionalProperties
impliestrue
, sofeedback
would be allowed anyway.I hope the rationale of the solution, combined with the PR diff, is somewhat clear, although I'm not sure I was able to explain it so well.
WDYT, @squidfunk?