@skmtc/core 0.47.1 → 0.47.3

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.
@@ -514,14 +514,31 @@ export class ParseContext {
514
514
  logIssueAt(issue, parent) {
515
515
  const added = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_addIssue).call(this, toParseIssue(issue));
516
516
  if (added && !this.silent) {
517
- this.logger.warn({
517
+ const payload = {
518
518
  protocol: issue.protocol,
519
519
  level: issue.level,
520
520
  location: issue.location,
521
521
  message: issue.message,
522
522
  type: issue.type,
523
523
  ...(parent === undefined ? {} : { parent: JSON.stringify(parent) })
524
- });
524
+ };
525
+ // Each issue is logged at its own level, so a log threshold above
526
+ // DEBUG leaves `debug` issues out.
527
+ switch (issue.level) {
528
+ case 'error':
529
+ this.logger.error(payload);
530
+ break;
531
+ case 'warning':
532
+ this.logger.warn(payload);
533
+ break;
534
+ case 'debug':
535
+ this.logger.debug(payload);
536
+ break;
537
+ default: {
538
+ const _exhaustive = issue;
539
+ throw new Error(`Unhandled issue level: ${JSON.stringify(_exhaustive)}`);
540
+ }
541
+ }
525
542
  }
526
543
  }
527
544
  // -- OAS-flavored surface (StackTrail-based) ---------------------
@@ -7,7 +7,7 @@ import type { OasSchema } from '../oas/schema/Schema.js';
7
7
  type CollatedExampleArgs = {
8
8
  /** The OpenAPI schema or reference to extract examples from */
9
9
  objectSchema: OasSchema | OasRef<'schema'> | undefined;
10
- /** Current recursion depth (used to prevent infinite loops) */
10
+ /** Current recursion depth. A schema deeper than 15 has no example. */
11
11
  depth: number;
12
12
  /**
13
13
  * The `$ref` pointers already entered on THIS path, used to cut reference
@@ -26,7 +26,8 @@ type CollatedExampleArgs = {
26
26
  * This function traverses OpenAPI schema structures and generates comprehensive
27
27
  * example values based on the schema definitions and any explicit examples provided.
28
28
  * It handles complex nested structures including objects, arrays, unions, and
29
- * references while preventing infinite recursion through depth limiting.
29
+ * references. The part of a schema past the depth limit of 15 is left out, and the
30
+ * rest of the example is kept.
30
31
  *
31
32
  * The function prioritizes explicit examples when available and falls back to
32
33
  * generating examples from nested schemas. It's particularly useful for creating
@@ -34,11 +35,9 @@ type CollatedExampleArgs = {
34
35
  *
35
36
  * @param args - Configuration for example collation
36
37
  * @param args.objectSchema - The schema to extract examples from
37
- * @param args.depth - Current recursion depth (prevents infinite loops)
38
+ * @param args.depth - Current recursion depth, 0 for the first call
38
39
  * @returns Collated example value matching the schema structure, or undefined if no examples
39
40
  *
40
- * @throws {Error} When recursion depth exceeds 15 levels (prevents stack overflow)
41
- *
42
41
  * @example Basic schema examples
43
42
  * ```typescript
44
43
  * import { collateExamples } from '@skmtc/core';
@@ -133,16 +132,20 @@ type CollatedExampleArgs = {
133
132
  * // }
134
133
  * ```
135
134
  *
136
- * @example Depth limiting and error handling
135
+ * @example Depth limit and missing schemas
137
136
  * ```typescript
138
- * // Deep nesting detection
139
- * try {
140
- * const deepExample = collateExamples({ objectSchema: someSchema, depth: 16 });
141
- * } catch (error) {
142
- * console.error('Depth limit exceeded:', error.message); // 'Depth limit reached'
143
- * }
137
+ * // `id` is at depth 15 and `name` is at depth 16, past the limit
138
+ * const deepSchema = new OasObject({
139
+ * properties: {
140
+ * id: new OasInteger({ example: 123 }),
141
+ * owner: new OasObject({ properties: { name: new OasString({ example: 'Jane' }) } })
142
+ * }
143
+ * });
144
+ *
145
+ * const deepExample = collateExamples({ objectSchema: deepSchema, depth: 14 });
146
+ * console.log(deepExample); // { id: 123 }
144
147
  *
145
- * // Handling missing schemas
148
+ * // A missing schema has no example
146
149
  * const emptyExample = collateExamples({ objectSchema: undefined, depth: 0 });
147
150
  * console.log(emptyExample); // undefined
148
151
  * ```
@@ -8,7 +8,8 @@ import { DanglingRefError } from '../oas/ref/DanglingRefError.js';
8
8
  * This function traverses OpenAPI schema structures and generates comprehensive
9
9
  * example values based on the schema definitions and any explicit examples provided.
10
10
  * It handles complex nested structures including objects, arrays, unions, and
11
- * references while preventing infinite recursion through depth limiting.
11
+ * references. The part of a schema past the depth limit of 15 is left out, and the
12
+ * rest of the example is kept.
12
13
  *
13
14
  * The function prioritizes explicit examples when available and falls back to
14
15
  * generating examples from nested schemas. It's particularly useful for creating
@@ -16,11 +17,9 @@ import { DanglingRefError } from '../oas/ref/DanglingRefError.js';
16
17
  *
17
18
  * @param args - Configuration for example collation
18
19
  * @param args.objectSchema - The schema to extract examples from
19
- * @param args.depth - Current recursion depth (prevents infinite loops)
20
+ * @param args.depth - Current recursion depth, 0 for the first call
20
21
  * @returns Collated example value matching the schema structure, or undefined if no examples
21
22
  *
22
- * @throws {Error} When recursion depth exceeds 15 levels (prevents stack overflow)
23
- *
24
23
  * @example Basic schema examples
25
24
  * ```typescript
26
25
  * import { collateExamples } from '@skmtc/core';
@@ -115,16 +114,20 @@ import { DanglingRefError } from '../oas/ref/DanglingRefError.js';
115
114
  * // }
116
115
  * ```
117
116
  *
118
- * @example Depth limiting and error handling
117
+ * @example Depth limit and missing schemas
119
118
  * ```typescript
120
- * // Deep nesting detection
121
- * try {
122
- * const deepExample = collateExamples({ objectSchema: someSchema, depth: 16 });
123
- * } catch (error) {
124
- * console.error('Depth limit exceeded:', error.message); // 'Depth limit reached'
125
- * }
119
+ * // `id` is at depth 15 and `name` is at depth 16, past the limit
120
+ * const deepSchema = new OasObject({
121
+ * properties: {
122
+ * id: new OasInteger({ example: 123 }),
123
+ * owner: new OasObject({ properties: { name: new OasString({ example: 'Jane' }) } })
124
+ * }
125
+ * });
126
126
  *
127
- * // Handling missing schemas
127
+ * const deepExample = collateExamples({ objectSchema: deepSchema, depth: 14 });
128
+ * console.log(deepExample); // { id: 123 }
129
+ *
130
+ * // A missing schema has no example
128
131
  * const emptyExample = collateExamples({ objectSchema: undefined, depth: 0 });
129
132
  * console.log(emptyExample); // undefined
130
133
  * ```
@@ -152,18 +155,15 @@ export const collateExamples = ({ objectSchema, depth, seen }) => {
152
155
  return undefined;
153
156
  }
154
157
  if (depth > 15) {
155
- throw new Error('Depth limit reached');
158
+ return undefined;
156
159
  }
157
160
  switch (objectSchema.type) {
158
161
  case 'ref': {
159
162
  // A schema that reaches itself has no finite example, so the recursive
160
163
  // key is omitted and collation continues around it.
161
164
  //
162
- // Without this the cycle simply pads the path until the depth limit
163
- // throws, roughly sixteen steps in — so a self-referential schema and a
164
- // legitimately deep one fail identically, and a caller that only wanted a
165
- // sample body gets an exception instead. Cutting the cycle here is what
166
- // makes the depth limit mean what it says.
165
+ // Without this the example would repeat the cycle until the depth limit,
166
+ // and a cycle of intersection members, which add no depth, would not end.
167
167
  return collateRef({ ref: objectSchema, depth: depth + 1, seen });
168
168
  }
169
169
  case 'object': {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.47.1",
3
+ "version": "0.47.3",
4
4
  "description": "Skmtc is a declarative code generation framework",
5
5
  "keywords": [
6
6
  "openapi",
@@ -517,14 +517,31 @@ class ParseContext {
517
517
  logIssueAt(issue, parent) {
518
518
  const added = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_addIssue).call(this, toParseIssue(issue));
519
519
  if (added && !this.silent) {
520
- this.logger.warn({
520
+ const payload = {
521
521
  protocol: issue.protocol,
522
522
  level: issue.level,
523
523
  location: issue.location,
524
524
  message: issue.message,
525
525
  type: issue.type,
526
526
  ...(parent === undefined ? {} : { parent: JSON.stringify(parent) })
527
- });
527
+ };
528
+ // Each issue is logged at its own level, so a log threshold above
529
+ // DEBUG leaves `debug` issues out.
530
+ switch (issue.level) {
531
+ case 'error':
532
+ this.logger.error(payload);
533
+ break;
534
+ case 'warning':
535
+ this.logger.warn(payload);
536
+ break;
537
+ case 'debug':
538
+ this.logger.debug(payload);
539
+ break;
540
+ default: {
541
+ const _exhaustive = issue;
542
+ throw new Error(`Unhandled issue level: ${JSON.stringify(_exhaustive)}`);
543
+ }
544
+ }
528
545
  }
529
546
  }
530
547
  // -- OAS-flavored surface (StackTrail-based) ---------------------
@@ -7,7 +7,7 @@ import type { OasSchema } from '../oas/schema/Schema.js';
7
7
  type CollatedExampleArgs = {
8
8
  /** The OpenAPI schema or reference to extract examples from */
9
9
  objectSchema: OasSchema | OasRef<'schema'> | undefined;
10
- /** Current recursion depth (used to prevent infinite loops) */
10
+ /** Current recursion depth. A schema deeper than 15 has no example. */
11
11
  depth: number;
12
12
  /**
13
13
  * The `$ref` pointers already entered on THIS path, used to cut reference
@@ -26,7 +26,8 @@ type CollatedExampleArgs = {
26
26
  * This function traverses OpenAPI schema structures and generates comprehensive
27
27
  * example values based on the schema definitions and any explicit examples provided.
28
28
  * It handles complex nested structures including objects, arrays, unions, and
29
- * references while preventing infinite recursion through depth limiting.
29
+ * references. The part of a schema past the depth limit of 15 is left out, and the
30
+ * rest of the example is kept.
30
31
  *
31
32
  * The function prioritizes explicit examples when available and falls back to
32
33
  * generating examples from nested schemas. It's particularly useful for creating
@@ -34,11 +35,9 @@ type CollatedExampleArgs = {
34
35
  *
35
36
  * @param args - Configuration for example collation
36
37
  * @param args.objectSchema - The schema to extract examples from
37
- * @param args.depth - Current recursion depth (prevents infinite loops)
38
+ * @param args.depth - Current recursion depth, 0 for the first call
38
39
  * @returns Collated example value matching the schema structure, or undefined if no examples
39
40
  *
40
- * @throws {Error} When recursion depth exceeds 15 levels (prevents stack overflow)
41
- *
42
41
  * @example Basic schema examples
43
42
  * ```typescript
44
43
  * import { collateExamples } from '@skmtc/core';
@@ -133,16 +132,20 @@ type CollatedExampleArgs = {
133
132
  * // }
134
133
  * ```
135
134
  *
136
- * @example Depth limiting and error handling
135
+ * @example Depth limit and missing schemas
137
136
  * ```typescript
138
- * // Deep nesting detection
139
- * try {
140
- * const deepExample = collateExamples({ objectSchema: someSchema, depth: 16 });
141
- * } catch (error) {
142
- * console.error('Depth limit exceeded:', error.message); // 'Depth limit reached'
143
- * }
137
+ * // `id` is at depth 15 and `name` is at depth 16, past the limit
138
+ * const deepSchema = new OasObject({
139
+ * properties: {
140
+ * id: new OasInteger({ example: 123 }),
141
+ * owner: new OasObject({ properties: { name: new OasString({ example: 'Jane' }) } })
142
+ * }
143
+ * });
144
+ *
145
+ * const deepExample = collateExamples({ objectSchema: deepSchema, depth: 14 });
146
+ * console.log(deepExample); // { id: 123 }
144
147
  *
145
- * // Handling missing schemas
148
+ * // A missing schema has no example
146
149
  * const emptyExample = collateExamples({ objectSchema: undefined, depth: 0 });
147
150
  * console.log(emptyExample); // undefined
148
151
  * ```
@@ -11,7 +11,8 @@ const DanglingRefError_js_1 = require("../oas/ref/DanglingRefError.js");
11
11
  * This function traverses OpenAPI schema structures and generates comprehensive
12
12
  * example values based on the schema definitions and any explicit examples provided.
13
13
  * It handles complex nested structures including objects, arrays, unions, and
14
- * references while preventing infinite recursion through depth limiting.
14
+ * references. The part of a schema past the depth limit of 15 is left out, and the
15
+ * rest of the example is kept.
15
16
  *
16
17
  * The function prioritizes explicit examples when available and falls back to
17
18
  * generating examples from nested schemas. It's particularly useful for creating
@@ -19,11 +20,9 @@ const DanglingRefError_js_1 = require("../oas/ref/DanglingRefError.js");
19
20
  *
20
21
  * @param args - Configuration for example collation
21
22
  * @param args.objectSchema - The schema to extract examples from
22
- * @param args.depth - Current recursion depth (prevents infinite loops)
23
+ * @param args.depth - Current recursion depth, 0 for the first call
23
24
  * @returns Collated example value matching the schema structure, or undefined if no examples
24
25
  *
25
- * @throws {Error} When recursion depth exceeds 15 levels (prevents stack overflow)
26
- *
27
26
  * @example Basic schema examples
28
27
  * ```typescript
29
28
  * import { collateExamples } from '@skmtc/core';
@@ -118,16 +117,20 @@ const DanglingRefError_js_1 = require("../oas/ref/DanglingRefError.js");
118
117
  * // }
119
118
  * ```
120
119
  *
121
- * @example Depth limiting and error handling
120
+ * @example Depth limit and missing schemas
122
121
  * ```typescript
123
- * // Deep nesting detection
124
- * try {
125
- * const deepExample = collateExamples({ objectSchema: someSchema, depth: 16 });
126
- * } catch (error) {
127
- * console.error('Depth limit exceeded:', error.message); // 'Depth limit reached'
128
- * }
122
+ * // `id` is at depth 15 and `name` is at depth 16, past the limit
123
+ * const deepSchema = new OasObject({
124
+ * properties: {
125
+ * id: new OasInteger({ example: 123 }),
126
+ * owner: new OasObject({ properties: { name: new OasString({ example: 'Jane' }) } })
127
+ * }
128
+ * });
129
129
  *
130
- * // Handling missing schemas
130
+ * const deepExample = collateExamples({ objectSchema: deepSchema, depth: 14 });
131
+ * console.log(deepExample); // { id: 123 }
132
+ *
133
+ * // A missing schema has no example
131
134
  * const emptyExample = collateExamples({ objectSchema: undefined, depth: 0 });
132
135
  * console.log(emptyExample); // undefined
133
136
  * ```
@@ -155,18 +158,15 @@ const collateExamples = ({ objectSchema, depth, seen }) => {
155
158
  return undefined;
156
159
  }
157
160
  if (depth > 15) {
158
- throw new Error('Depth limit reached');
161
+ return undefined;
159
162
  }
160
163
  switch (objectSchema.type) {
161
164
  case 'ref': {
162
165
  // A schema that reaches itself has no finite example, so the recursive
163
166
  // key is omitted and collation continues around it.
164
167
  //
165
- // Without this the cycle simply pads the path until the depth limit
166
- // throws, roughly sixteen steps in — so a self-referential schema and a
167
- // legitimately deep one fail identically, and a caller that only wanted a
168
- // sample body gets an exception instead. Cutting the cycle here is what
169
- // makes the depth limit mean what it says.
168
+ // Without this the example would repeat the cycle until the depth limit,
169
+ // and a cycle of intersection members, which add no depth, would not end.
170
170
  return collateRef({ ref: objectSchema, depth: depth + 1, seen });
171
171
  }
172
172
  case 'object': {