Require type for oneOf mutual exclusion by Namnamseo · Pull Request #5426 · golangci/golangci-lint (original) (raw)
Hello!
The following config:
linters-settings: custom: foo: path: "bin/linter/myplugin.so"
is considered broken under current JSON schema for config:
{ "custom": { "type": "object", "patternProperties": { "^.$": { "type": "object", "additionalProperties": false, "properties": { "type": { "enum": [ "module", "goplugin" ], "default": "goplugin" }, "path": { "type": "string", "examples": [ "/path/to/example.so" ] }, / ... */ }, "oneOf": [ { "properties": { "type": { "enum": [ "module" ] } } }, { "required": [ "path" ] } ] } } } }
for two reasons:
- In JSON Schema,
oneOf
requires exactly one of each options. When both sub-schemas match the object, the validation fails. - In JSON Schema, all properties are deemed optional unless explicitly stated to be
"required"
.
The given YAML:
- matches the first sub-schema, which states: "If it has a
type
property, it should be one among["module"]
.". Since it doesn't have that property, the statement is (vacuously) true. - matches the second sub-schema, which states: "It should have a
"path"
property.". It does.
I think the oneOf
clause was there to do a mutual exclusion between "module" and "goplugin" type. Since the default is considered the latter, the "module" case should explicitly require for the property to be present.
This PR adds the requirement, and adds some test cases for that.
Since I'm new to the code base, I don't know which files among jsonschema/*.json
needs to change; please point me if I'm wrong.