json-schema-spell-checker
Version:
Check the spelling of your JSON Schema (including OpenAPI!) documents
25 lines (21 loc) • 470 B
JavaScript
var { JSONPath } = require("jsonpath-plus");
/**
* Extracts all titles and descriptions from a specification
*/
const extract = (document, fields = []) => {
let path;
if (typeof fields == "string") {
path = fields;
} else {
path = `$..[${fields.join(",")}]`;
}
return JSONPath({ path, json: document, resultType: "all" }).map(
({ path, value }) => {
return {
path,
value,
};
}
);
};
module.exports = extract;