@prorobotech/openapi-k8s-toolkit 1.2.0-alpha.1 → 1.2.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34166,35 +34166,53 @@
34166
34166
  const parseJsonPathTemplate = ({
34167
34167
  text,
34168
34168
  multiQueryData,
34169
- customFallback
34169
+ customFallback,
34170
+ replaceValues
34170
34171
  }) => {
34171
34172
  if (!text) return "";
34172
34173
  const placeholderRegex = /\{reqsJsonPath\[(\d+)\]\s*\[\s*(['"])([\s\S]*?)\2\s*\](?:\s*\[\s*(['"])([\s\S]*?)\4\s*\])?\}/g;
34173
- return text.replace(
34174
+ const resolve = (input) => input.replace(
34174
34175
  placeholderRegex,
34175
- (match, reqIndexStr, _quote, jsonPathExpr, _smth, fallback = "Undefined with no fallback") => {
34176
+ (match, reqIndexStr, _quote, rawJsonPathExpr, _fallbackQuote, inlineFallback = "Undefined with no fallback") => {
34176
34177
  try {
34177
- const reqIndex = parseInt(reqIndexStr, 10);
34178
+ const reqIndex = Number(reqIndexStr);
34178
34179
  const jsonRoot = multiQueryData[`req${reqIndex}`];
34179
- if (jsonRoot === void 0 && !customFallback) {
34180
- return fallback;
34181
- }
34182
- if (jsonRoot === void 0 && customFallback) {
34183
- return customFallback;
34180
+ let jsonPathExpr = rawJsonPathExpr;
34181
+ let previous2 = null;
34182
+ let loopGuard = 0;
34183
+ while (previous2 !== jsonPathExpr && loopGuard < 10) {
34184
+ previous2 = jsonPathExpr;
34185
+ jsonPathExpr = resolve(jsonPathExpr);
34186
+ loopGuard++;
34187
+ }
34188
+ if (replaceValues) {
34189
+ jsonPathExpr = prepareTemplate({
34190
+ template: jsonPathExpr,
34191
+ replaceValues
34192
+ });
34184
34193
  }
34185
- const results = jp.query(jsonRoot || {}, `$${jsonPathExpr}`);
34186
- if (results.length === 0 || results[0] == null || results[0] === void 0) {
34187
- if (customFallback) {
34188
- return customFallback;
34189
- }
34190
- return fallback;
34194
+ if (jsonRoot === void 0 && customFallback) return customFallback;
34195
+ if (jsonRoot === void 0) return inlineFallback;
34196
+ const results = jp.query(jsonRoot, `$${jsonPathExpr}`);
34197
+ const value = results?.[0];
34198
+ if (value == null) {
34199
+ return customFallback ?? inlineFallback;
34191
34200
  }
34192
- return String(results[0]);
34201
+ return String(value);
34193
34202
  } catch {
34194
34203
  return match;
34195
34204
  }
34196
34205
  }
34197
34206
  );
34207
+ let result = text;
34208
+ let previous = null;
34209
+ let iterations = 0;
34210
+ while (result !== previous && iterations < 10) {
34211
+ previous = result;
34212
+ result = resolve(result);
34213
+ iterations++;
34214
+ }
34215
+ return result;
34198
34216
  };
34199
34217
  const parseWithoutPartsOfUrl = ({
34200
34218
  text,
@@ -34222,7 +34240,8 @@
34222
34240
  text,
34223
34241
  multiQueryData
34224
34242
  }),
34225
- multiQueryData
34243
+ multiQueryData,
34244
+ replaceValues
34226
34245
  }),
34227
34246
  replaceValues
34228
34247
  });