snap-on-openapi 1.0.27 → 1.0.29

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.
@@ -57,25 +57,25 @@ export class Logger {
57
57
  if (typeof data !== 'object') {
58
58
  return data;
59
59
  }
60
- const seen = new Set();
61
- const recurse = (obj, path = []) => {
60
+ const recurse = (obj, path = ['self'], seen = new Map()) => {
61
+ const currentPath = path.join('.');
62
+ seen.set(obj, currentPath);
62
63
  if (Array.isArray(obj)) {
63
64
  const result = [];
64
- let index = -1;
65
- for (const val of obj) {
66
- index++;
67
- if (typeof val === 'object' && val) {
68
- if (seen.has(val)) {
69
- result.push('circular->' + path.join('.'));
70
- continue;
65
+ obj.forEach((val, index) => {
66
+ if (typeof val === 'object' && val !== null) {
67
+ const existingPath = seen.get(val);
68
+ if (existingPath) {
69
+ result.push(`circular->${existingPath === 'self' ? 'self' : existingPath.replace('self.', '')}`);
70
+ }
71
+ else {
72
+ result.push(recurse(val, [...path, index.toString()], new Map(seen)));
71
73
  }
72
- seen.add(val);
73
- const newPath = [...path, index.toString()];
74
- result.push(recurse(val, newPath));
75
- continue;
76
74
  }
77
- result.push(val);
78
- }
75
+ else {
76
+ result.push(val);
77
+ }
78
+ });
79
79
  return result;
80
80
  }
81
81
  if (obj instanceof Date) {
@@ -83,17 +83,19 @@ export class Logger {
83
83
  }
84
84
  const result = {};
85
85
  for (const key of Object.keys(obj)) {
86
- if (typeof obj[key] === 'object' && obj[key]) {
87
- if (seen.has(obj[key])) {
88
- result[key] = 'circular->' + path.join('.');
89
- continue;
86
+ const val = obj[key];
87
+ if (typeof val === 'object' && val !== null) {
88
+ const existingPath = seen.get(val);
89
+ if (existingPath) {
90
+ result[key] = `circular->${existingPath === 'self' ? 'self' : existingPath.replace('self.', '')}`;
90
91
  }
91
- seen.add(obj[key]);
92
- const newPath = [...path, key];
93
- result[key] = recurse(obj[key], newPath);
94
- continue;
92
+ else {
93
+ result[key] = recurse(val, [...path, key], new Map(seen));
94
+ }
95
+ }
96
+ else {
97
+ result[key] = val;
95
98
  }
96
- result[key] = obj[key];
97
99
  }
98
100
  return result;
99
101
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "snap-on-openapi",
3
3
  "author": "Alex Sarychev",
4
- "version": "1.0.27",
4
+ "version": "1.0.29",
5
5
  "description": "Swiftly build type-checked OpenAPI applications with Zod and TypeScript",
6
6
  "type": "module",
7
7
  "license": "ISC",