Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (coreStrings === undefined) {
I18n.init();
}
if (options.isThemeString) {
// If not in memory, load translations for theme
if (themeStrings === undefined) {
I18n.loadThemeTranslations();
}
// Both jsonpath's dot-notation and bracket-notation start with '$'
// E.g.: $.store.book.title or $['store']['book']['title']
// The {{t}} translation helper passes the default English text
// The full Unicode jsonpath with '$' is built here
// jp.stringify and jp.value are jsonpath methods
// Info: https://www.npmjs.com/package/jsonpath
path = jp.stringify(['$', msgPath]);
candidateString = jp.value(themeStrings, path) || msgPath;
} else {
// Backend messages use dot-notation, and the '$.' prefix is added here
// While bracket-notation allows any Unicode characters in keys for themes,
// dot-notation allows only word characters in keys for backend messages
// (that is \w or [A-Za-z0-9_] in RegExp)
path = `$.${msgPath}`;
candidateString = jp.value(coreStrings, path);
}
matchingString = candidateString || {};
if (isObject(matchingString) || isEqual(matchingString, {})) {
if (options.log) {
logging.error(new errors.IncorrectUsageError({
message: `i18n error: path "${msgPath}" was not found`
let jp_source_data_2 = jp.nodes(data, '$..price');
let enriched_property_name = promise.getConfig().target_property;
for(let node of jp_source_data) {
let node_path = node.path.join('.').substring(2); // Remove leading $. from path string for object path
enrichment_target = node.value;
promise.setData(enrichment_target);
intermediate_result = enrichment_target;
intermediate_result = await promise.process(intermediate_result);
let deep_copied_intermediate_result = JSON.parse(JSON.stringify(intermediate_result));
// Check node type
if(typeof node.value !== 'object' && !Array.isArray(node.value)) {
path_expression = jp.stringify(node.path);
let node_path_deep_copy = JSON.parse(JSON.stringify(node.path));
//node_path_deep_copy.pop();
node_path_deep_copy.shift();
parent_object_path = node_path_deep_copy.join('.');
// get parent and check if it's an array
parent = jp.parent(data, path_expression);
if(Array.isArray(parent)) {
let enriched_intermediate_object = {value: node.value};
enriched_intermediate_object[enriched_property_name] = deep_copied_intermediate_result;
object_path.set(data, parent_object_path, enriched_intermediate_object);
} else {
parent[enriched_property_name] = deep_copied_intermediate_result;
}
}
}
let nodePath = typeof node.path === "string" ? [node.path] : node.path
if (
node.code === "OBJECT_MISSING_REQUIRED_PROPERTY" ||
node.code === "OBJECT_ADDITIONAL_PROPERTIES"
) {
// For multiple missing/additional properties , each node would only contain one param.
if (node.params && node.params.length > 0) {
nodePath = nodePath.concat(node.params[0] as string)
}
}
const pathSegments = consolidatePath(path, nodePath)
node.path = pathSegments.join("/")
node.jsonPath = (pathSegments.length && stringify(pathSegments)) || ""
}
// check code 200,201,202,203...
if (key.startsWith("20")) {
const response = responses.value[key]
const resolvedSchema = await getResolvedResponseSchema(response.schema)
if (!resolvedSchema) {
continue
}
const systemData = (resolvedSchema as any).systemData
if (systemData && Object.keys(systemData)) {
hasSystemData = true
}
}
}
if (!hasSystemData) {
// operationId is located in the parent object of responses
const operationId = nodes(resolvedDoc, stringify(responses.path.slice(0, -1)))[0].value.operationId
yield {
message: `The response of operation:'${operationId}' is defined without 'systemData'. Consider adding the systemData to the response.`,
location: responses.path.slice(0, -1)
}
}
}
}
}
}
})
_.each(jpath.nodes(spec, plugin.pathExpression), function(node) {
const name = _.last(node.path);
const parent = jpath.value(spec, jpath.stringify(_.dropRight(node.path)));
plugin.process(parent, name, node.path, spec);
});
plugin.finish && plugin.finish(spec);
async *asyncRun(doc, node, path) {
const msg: string =
"the default error response schema does not correspond to the schema documented at https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/common-api-details.md#error-response-content."
const resolvedDoc = await getResolvedJson(doc)
if (!resolvedDoc) {
return
}
for (const n of nodes(doc, "$.paths.*.*.responses")) {
const response: any = n.value
if (response.default && response.default.schema) {
const paths = n.path.concat(["default"])
const pathExpression = stringify(paths.concat(["schema"]))
const schema: any = await getResolvedResponseSchema(nodes(resolvedDoc, pathExpression)[0].value)
/*
* the schema should match below structure:
{
"error":{
"code":"error code",
"message":"error message"
...
}
}
*/
if (!schema || !schema.error || !schema.error.code || !schema.error.message) {
yield { message: `${msg}`, location: paths }
}
export function stringify(jsonPath: JsonPath): string {
return jsonpath.stringify(["$" as JsonPathComponent].concat(jsonPath));
}
function toJPath(path, unit) {
let n = count$(path)
let segs = isLinkConfigData(path) ? ['$'] : ['$', unit.module(), unit.name()].slice(0, n)
let prefix = jsonpath.stringify(segs)
let tail = path.slice(n)
return prefix + delimiter(tail) + tail
}
function ensureAllArraysAreStrings(obj) {
var nodes = jp.nodes(obj, "$..*[*]");
for (var i = 0; i < nodes.length; i++) {
var item = nodes[i].value;
var path = nodes[i].path;
if (l.isNumber(item)) {
var pathExpr = jp.stringify(path);
log(`Replacing number found: ${item} at ${pathExpr} with string.`);
jp.value(obj, pathExpr, item.toString());
}
}
}
public * GetDefinitionLocations(jsonQuery: string): Iterable<{ value: any, jsonPath: string }> {
for (const path of nodes(this.fullyResolvedAndMergedDefinition, jsonQuery)) {
yield {
value: path.value,
jsonPath: stringify(path.path)
};
}
}
}