ValidateOptions request: 3rd "strategy" argument for handling unknown keys

RESOLVED INCOMPLETE

Status

Add-on SDK
General
P3
normal
RESOLVED INCOMPLETE
5 years ago
a month ago

People

(Reporter: Gregg Lind (Fx Strategy and Insights - Shield - Heartbeat ), Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Use case:

* validate the keys I care about
* ignore other keys (which become essentially **kwargs)

Options for 'strategy' might be:

* strict | fail  -> current
* allow | ignore ->  unknown / unvalidated keys are fine, and pass through
* (a function) ->  run on all unknown keys?


(previous discussion around enhancements:  https://bugzilla.mozilla.org/show_bug.cgi?id=569122)
Gregg, did you still need this?
Flags: needinfo?(glind)
Debatable.  I built around this... 

Having ValidateOptions around is nearly as powerful JSONSchema.  My own solution here is gross.  I would rather see some power expansion in the core (options:  omit, allow, 'function'). 

======
let validateOptionsLiberal = exports.validateOptionsLiberal = function(options,requirements){
	let out = validateOptions(options,requirements);
	for (let k in options) {
		if (! (k in requirements)){
			out[k] = options[k] // unvalidated
		}
	}
	return out
}
=========
Flags: needinfo?(glind)

Updated

5 years ago
Priority: -- → P3
https://bugzilla.mozilla.org/show_bug.cgi?id=1399562
Status: NEW → RESOLVED
Last Resolved: a month ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.