Filter $$ref from examples (#4392)
* fix(dev-server): don't open localhost in a browser * tests: refactor model-example enzyme tests to be more isolated * tests: add failing sampleFromSchema tests for $$ref keys * tests: add additional test for user-created $$ref values * fix: create deeplyStripKey; use it to filter $$refs out of examples * tests: add cases for deeplyStripKey
This commit is contained in:
@@ -712,3 +712,25 @@ export const createDeepLinkPath = (str) => typeof str == "string" || str instanc
|
||||
export const escapeDeepLinkPath = (str) => cssEscape( createDeepLinkPath(str) )
|
||||
|
||||
export const getExtensions = (defObj) => defObj.filter((v, k) => /^x-/.test(k))
|
||||
|
||||
// Deeply strips a specific key from an object.
|
||||
//
|
||||
// `predicate` can be used to discriminate the stripping further,
|
||||
// by preserving the key's place in the object based on its value.
|
||||
export function deeplyStripKey(input, keyToStrip, predicate = () => true) {
|
||||
if(typeof input !== "object" || Array.isArray(input) || !keyToStrip) {
|
||||
return input
|
||||
}
|
||||
|
||||
const obj = Object.assign({}, input)
|
||||
|
||||
Object.keys(obj).forEach(k => {
|
||||
if(k === keyToStrip && predicate(obj[k], k)) {
|
||||
delete obj[k]
|
||||
return
|
||||
}
|
||||
obj[k] = deeplyStripKey(obj[k], keyToStrip, predicate)
|
||||
})
|
||||
|
||||
return obj
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user