@skmtc/core 0.0.787 → 0.0.789

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.
Files changed (55) hide show
  1. package/esm/context/GenerateContext.d.ts +95 -0
  2. package/esm/context/GenerateContext.d.ts.map +1 -1
  3. package/esm/context/GenerateContext.js +95 -0
  4. package/esm/context/ParseContext.d.ts +178 -0
  5. package/esm/context/ParseContext.d.ts.map +1 -1
  6. package/esm/context/ParseContext.js +108 -0
  7. package/esm/dsl/Inserted.d.ts +240 -0
  8. package/esm/dsl/Inserted.d.ts.map +1 -1
  9. package/esm/dsl/Inserted.js +231 -0
  10. package/esm/dsl/JsonFile.d.ts +162 -0
  11. package/esm/dsl/JsonFile.d.ts.map +1 -1
  12. package/esm/dsl/JsonFile.js +157 -0
  13. package/esm/helpers/refFns.d.ts +160 -0
  14. package/esm/helpers/refFns.d.ts.map +1 -1
  15. package/esm/helpers/refFns.js +156 -0
  16. package/esm/oas/components/Components.d.ts +252 -2
  17. package/esm/oas/components/Components.d.ts.map +1 -1
  18. package/esm/oas/components/Components.js +241 -2
  19. package/esm/oas/operation/Operation.d.ts +107 -1
  20. package/esm/oas/operation/Operation.d.ts.map +1 -1
  21. package/esm/oas/operation/Operation.js +107 -1
  22. package/esm/oas/ref/Ref.d.ts +86 -0
  23. package/esm/oas/ref/Ref.d.ts.map +1 -1
  24. package/esm/oas/ref/Ref.js +86 -0
  25. package/esm/oas/union/Union.d.ts +119 -5
  26. package/esm/oas/union/Union.d.ts.map +1 -1
  27. package/esm/oas/union/Union.js +108 -5
  28. package/package.json +1 -1
  29. package/script/context/GenerateContext.d.ts +95 -0
  30. package/script/context/GenerateContext.d.ts.map +1 -1
  31. package/script/context/GenerateContext.js +95 -0
  32. package/script/context/ParseContext.d.ts +178 -0
  33. package/script/context/ParseContext.d.ts.map +1 -1
  34. package/script/context/ParseContext.js +108 -0
  35. package/script/dsl/Inserted.d.ts +240 -0
  36. package/script/dsl/Inserted.d.ts.map +1 -1
  37. package/script/dsl/Inserted.js +231 -0
  38. package/script/dsl/JsonFile.d.ts +162 -0
  39. package/script/dsl/JsonFile.d.ts.map +1 -1
  40. package/script/dsl/JsonFile.js +157 -0
  41. package/script/helpers/refFns.d.ts +160 -0
  42. package/script/helpers/refFns.d.ts.map +1 -1
  43. package/script/helpers/refFns.js +156 -0
  44. package/script/oas/components/Components.d.ts +252 -2
  45. package/script/oas/components/Components.d.ts.map +1 -1
  46. package/script/oas/components/Components.js +241 -2
  47. package/script/oas/operation/Operation.d.ts +107 -1
  48. package/script/oas/operation/Operation.d.ts.map +1 -1
  49. package/script/oas/operation/Operation.js +107 -1
  50. package/script/oas/ref/Ref.d.ts +86 -0
  51. package/script/oas/ref/Ref.d.ts.map +1 -1
  52. package/script/oas/ref/Ref.js +86 -0
  53. package/script/oas/union/Union.d.ts +119 -5
  54. package/script/oas/union/Union.d.ts.map +1 -1
  55. package/script/oas/union/Union.js +108 -5
@@ -1 +1 @@
1
- {"version":3,"file":"JsonFile.d.ts","sourceRoot":"","sources":["../../src/dsl/JsonFile.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC,CAAA;AAED,qBAAa,QAAQ;IACnB,QAAQ,EAAE,MAAM,CAAS;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;gBAEpB,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,YAAY;IAK3C,QAAQ,IAAI,MAAM;CAGnB"}
1
+ {"version":3,"file":"JsonFile.d.ts","sourceRoot":"","sources":["../../src/dsl/JsonFile.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,KAAK,YAAY,GAAG;IAClB,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+GG;AACH,qBAAa,QAAQ;IACnB,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAS;IAEzB,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAA;IAEZ,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEhC;;;;;;;;;;;;;;;;;;OAkBG;gBACS,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,YAAY;IAK3C;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
@@ -1,17 +1,151 @@
1
+ /**
2
+ * Represents a JSON file in the SKMTC DSL system.
3
+ *
4
+ * The `JsonFile` class is used to generate JSON files as part of the code generation
5
+ * process. It provides a simple interface for creating configuration files, manifests,
6
+ * package.json files, and other JSON-based artifacts with proper formatting.
7
+ *
8
+ * ## Key Features
9
+ *
10
+ * - **JSON Formatting**: Automatically formats JSON with 2-space indentation
11
+ * - **Type Safety**: Accepts any valid JSON-serializable content structure
12
+ * - **Path Management**: Associates content with specific file paths
13
+ * - **String Conversion**: Easy integration with file writing systems
14
+ *
15
+ * @example Basic JSON file creation
16
+ * ```typescript
17
+ * import { JsonFile } from '@skmtc/core';
18
+ *
19
+ * const packageJson = new JsonFile({
20
+ * path: './package.json',
21
+ * content: {
22
+ * name: 'my-api-client',
23
+ * version: '1.0.0',
24
+ * type: 'module',
25
+ * main: './index.js',
26
+ * dependencies: {
27
+ * 'axios': '^1.0.0'
28
+ * }
29
+ * }
30
+ * });
31
+ *
32
+ * const jsonContent = packageJson.toString();
33
+ * console.log(jsonContent);
34
+ * // {
35
+ * // "name": "my-api-client",
36
+ * // "version": "1.0.0",
37
+ * // "type": "module",
38
+ * // "main": "./index.js",
39
+ * // "dependencies": {
40
+ * // "axios": "^1.0.0"
41
+ * // }
42
+ * // }
43
+ * ```
44
+ *
45
+ * @example Configuration file generation
46
+ * ```typescript
47
+ * const configFile = new JsonFile({
48
+ * path: './src/config/api.json',
49
+ * content: {
50
+ * baseUrl: 'https://api.example.com',
51
+ * timeout: 5000,
52
+ * retryAttempts: 3,
53
+ * endpoints: {
54
+ * users: '/users',
55
+ * products: '/products',
56
+ * orders: '/orders'
57
+ * }
58
+ * }
59
+ * });
60
+ *
61
+ * // Write to file system
62
+ * await Deno.writeTextFile(configFile.path, configFile.toString());
63
+ * ```
64
+ *
65
+ * @example OpenAPI specification output
66
+ * ```typescript
67
+ * const openApiFile = new JsonFile({
68
+ * path: './dist/openapi.json',
69
+ * content: {
70
+ * openapi: '3.0.0',
71
+ * info: {
72
+ * title: 'My API',
73
+ * version: '1.0.0'
74
+ * },
75
+ * paths: {
76
+ * '/users': {
77
+ * get: {
78
+ * summary: 'List users',
79
+ * responses: {
80
+ * '200': {
81
+ * description: 'Success'
82
+ * }
83
+ * }
84
+ * }
85
+ * }
86
+ * }
87
+ * }
88
+ * });
89
+ * ```
90
+ *
91
+ * @example Using with generator registration
92
+ * ```typescript
93
+ * class MyGenerator extends ContentBase {
94
+ * generate() {
95
+ * const manifestFile = new JsonFile({
96
+ * path: './generated/manifest.json',
97
+ * content: {
98
+ * generatedAt: new Date().toISOString(),
99
+ * version: '1.0.0',
100
+ * files: [
101
+ * './models/User.ts',
102
+ * './models/Product.ts'
103
+ * ]
104
+ * }
105
+ * });
106
+ *
107
+ * // Register with the generation context
108
+ * this.register({ jsonFile: manifestFile });
109
+ * }
110
+ * }
111
+ * ```
112
+ */
1
113
  export class JsonFile {
114
+ /**
115
+ * Creates a new JsonFile instance.
116
+ *
117
+ * @param args - JSON file configuration
118
+ * @param args.path - The output path for this JSON file
119
+ * @param args.content - The JSON content to write
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * const configFile = new JsonFile({
124
+ * path: './config/settings.json',
125
+ * content: {
126
+ * theme: 'dark',
127
+ * language: 'en',
128
+ * features: ['auth', 'notifications']
129
+ * }
130
+ * });
131
+ * ```
132
+ */
2
133
  constructor({ path, content }) {
134
+ /** The file type, always 'json' for JSON files */
3
135
  Object.defineProperty(this, "fileType", {
4
136
  enumerable: true,
5
137
  configurable: true,
6
138
  writable: true,
7
139
  value: 'json'
8
140
  });
141
+ /** The file path for this generated JSON file */
9
142
  Object.defineProperty(this, "path", {
10
143
  enumerable: true,
11
144
  configurable: true,
12
145
  writable: true,
13
146
  value: void 0
14
147
  });
148
+ /** The JSON content to write to the file */
15
149
  Object.defineProperty(this, "content", {
16
150
  enumerable: true,
17
151
  configurable: true,
@@ -21,6 +155,29 @@ export class JsonFile {
21
155
  this.path = path;
22
156
  this.content = content;
23
157
  }
158
+ /**
159
+ * Converts the JSON content to a formatted string.
160
+ *
161
+ * This method serializes the content object to JSON with 2-space indentation
162
+ * for readable output. The resulting string is suitable for writing directly
163
+ * to a file or including in the generation pipeline.
164
+ *
165
+ * @returns The formatted JSON content as a string
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * const file = new JsonFile({
170
+ * path: './data.json',
171
+ * content: { name: 'test', value: 42 }
172
+ * });
173
+ *
174
+ * console.log(file.toString());
175
+ * // {
176
+ * // "name": "test",
177
+ * // "value": 42
178
+ * // }
179
+ * ```
180
+ */
24
181
  toString() {
25
182
  return JSON.stringify(this.content, null, 2);
26
183
  }
@@ -2,11 +2,171 @@ import "../_dnt.polyfills.js";
2
2
  import type { RefName } from '../types/RefName.js';
3
3
  import type { OpenAPIV3 } from 'openapi-types';
4
4
  import type { ReferenceObject } from '../oas/_merge-all-of/types.js';
5
+ /**
6
+ * Extracts a reference name from an OpenAPI $ref string.
7
+ *
8
+ * This function parses JSON Pointer references (like '#/components/schemas/User')
9
+ * and extracts the final component as a branded RefName type. It's used throughout
10
+ * the SKMTC system to convert string references into type-safe reference names.
11
+ *
12
+ * @param $ref - The OpenAPI reference string (e.g., '#/components/schemas/User')
13
+ * @returns The extracted reference name as a branded RefName type
14
+ *
15
+ * @throws {Error} When the reference string is invalid or empty
16
+ *
17
+ * @example Basic usage
18
+ * ```typescript
19
+ * import { toRefName } from '@skmtc/core/helpers';
20
+ *
21
+ * const refName = toRefName('#/components/schemas/User');
22
+ * console.log(refName); // 'User' (typed as RefName)
23
+ *
24
+ * const responseRef = toRefName('#/components/responses/ErrorResponse');
25
+ * console.log(responseRef); // 'ErrorResponse' (typed as RefName)
26
+ * ```
27
+ *
28
+ * @example Error cases
29
+ * ```typescript
30
+ * // These will throw errors:
31
+ * toRefName('invalid/ref/'); // Error: 'Invalid reference'
32
+ * toRefName('#/components/schemas/'); // Error: 'Invalid reference'
33
+ * ```
34
+ *
35
+ * @example Integration with OAS processing
36
+ * ```typescript
37
+ * class SchemaProcessor {
38
+ * processReference(ref: string) {
39
+ * const refName = toRefName(ref);
40
+ * const schema = this.document.components.schemas[refName];
41
+ * return this.processSchema(schema, refName);
42
+ * }
43
+ * }
44
+ * ```
45
+ */
5
46
  export declare const toRefName: ($ref: string) => RefName;
47
+ /**
48
+ * Type representing an object with a $ref property.
49
+ */
6
50
  type Ref = {
51
+ /** The OpenAPI reference string */
7
52
  $ref: string;
8
53
  };
54
+ /**
55
+ * Type guard function to check if a value is an OpenAPI reference object.
56
+ *
57
+ * This function performs runtime type checking to determine if an unknown value
58
+ * is an OpenAPI Reference Object (contains a $ref property with a string value).
59
+ * It's essential for safely handling mixed schema/reference data during processing.
60
+ *
61
+ * @param value - The value to check for reference properties
62
+ * @returns True if the value is a reference object, false otherwise
63
+ *
64
+ * @example Basic type checking
65
+ * ```typescript
66
+ * import { isRef } from '@skmtc/core/helpers';
67
+ *
68
+ * const schemaOrRef: unknown = { $ref: '#/components/schemas/User' };
69
+ *
70
+ * if (isRef(schemaOrRef)) {
71
+ * // TypeScript now knows schemaOrRef has a $ref property
72
+ * console.log(schemaOrRef.$ref); // Safe to access
73
+ * const refName = toRefName(schemaOrRef.$ref);
74
+ * } else {
75
+ * // Handle as actual schema object
76
+ * console.log('Direct schema object');
77
+ * }
78
+ * ```
79
+ *
80
+ * @example Processing mixed data
81
+ * ```typescript
82
+ * function processSchemaOrRef(data: unknown) {
83
+ * if (isRef(data)) {
84
+ * // Handle reference
85
+ * return resolveReference(data.$ref);
86
+ * } else {
87
+ * // Handle direct schema
88
+ * return processSchema(data as SchemaObject);
89
+ * }
90
+ * }
91
+ * ```
92
+ *
93
+ * @example Array processing
94
+ * ```typescript
95
+ * const mixedArray: unknown[] = [
96
+ * { type: 'string' },
97
+ * { $ref: '#/components/schemas/User' },
98
+ * { type: 'number' }
99
+ * ];
100
+ *
101
+ * const references = mixedArray.filter(isRef);
102
+ * const schemas = mixedArray.filter(item => !isRef(item));
103
+ * ```
104
+ */
9
105
  export declare const isRef: (value: unknown) => value is Ref;
106
+ /**
107
+ * Creates a reference resolver function for an OpenAPI document.
108
+ *
109
+ * This higher-order function returns a resolver that can dereference OpenAPI
110
+ * JSON Pointer references within the context of a specific document. It handles
111
+ * nested references by recursively resolving reference chains until it reaches
112
+ * an actual schema object.
113
+ *
114
+ * The resolver is particularly useful during schema processing where you need
115
+ * to follow reference chains to get the actual schema definitions.
116
+ *
117
+ * @param oasDocument - The OpenAPI document containing the schemas to resolve against
118
+ * @returns A function that resolves reference objects to schema objects
119
+ *
120
+ * @throws {Error} When a reference cannot be resolved or points to a non-existent schema
121
+ *
122
+ * @example Basic usage
123
+ * ```typescript
124
+ * import { toGetRef } from '@skmtc/core/helpers';
125
+ *
126
+ * const resolver = toGetRef(openApiDocument);
127
+ *
128
+ * const userSchema = resolver({ $ref: '#/components/schemas/User' });
129
+ * console.log(userSchema.type); // 'object'
130
+ * console.log(userSchema.properties); // User properties
131
+ * ```
132
+ *
133
+ * @example Resolving nested references
134
+ * ```typescript
135
+ * // If User references Address, and Address references Country
136
+ * const resolver = toGetRef(document);
137
+ *
138
+ * // This will follow the chain: User -> Address -> Country
139
+ * const resolvedSchema = resolver({ $ref: '#/components/schemas/User' });
140
+ * // Returns the final resolved schema object
141
+ * ```
142
+ *
143
+ * @example Error handling
144
+ * ```typescript
145
+ * const resolver = toGetRef(document);
146
+ *
147
+ * try {
148
+ * const schema = resolver({ $ref: '#/components/schemas/NonExistent' });
149
+ * } catch (error) {
150
+ * console.error('Reference resolution failed:', error.message);
151
+ * // Error: Invalid reference: #/components/schemas/NonExistent
152
+ * }
153
+ * ```
154
+ *
155
+ * @example Integration with schema processing
156
+ * ```typescript
157
+ * class SchemaProcessor {
158
+ * private resolver = toGetRef(this.document);
159
+ *
160
+ * processProperty(property: SchemaObject | ReferenceObject) {
161
+ * if (isRef(property)) {
162
+ * const resolved = this.resolver(property);
163
+ * return this.processSchema(resolved);
164
+ * }
165
+ * return this.processSchema(property);
166
+ * }
167
+ * }
168
+ * ```
169
+ */
10
170
  export declare const toGetRef: (oasDocument: OpenAPIV3.Document) => ({ $ref }: ReferenceObject) => OpenAPIV3.SchemaObject;
11
171
  export {};
12
172
  //# sourceMappingURL=refFns.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"refFns.d.ts","sourceRoot":"","sources":["../../src/helpers/refFns.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAEpE,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,OASxC,CAAA;AAED,KAAK,GAAG,GAAG;IACT,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,GAM/C,CAAA;AAED,eAAO,MAAM,QAAQ,GAClB,aAAa,SAAS,CAAC,QAAQ,MAC/B,UAAU,eAAe,KAAG,SAAS,CAAC,YActC,CAAA"}
1
+ {"version":3,"file":"refFns.d.ts","sourceRoot":"","sources":["../../src/helpers/refFns.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,OASxC,CAAA;AAED;;GAEG;AACH,KAAK,GAAG,GAAG;IACT,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,eAAO,MAAM,KAAK,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,GAM/C,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,eAAO,MAAM,QAAQ,GAClB,aAAa,SAAS,CAAC,QAAQ,MAC/B,UAAU,eAAe,KAAG,SAAS,CAAC,YActC,CAAA"}
@@ -1,4 +1,45 @@
1
1
  import "../_dnt.polyfills.js";
2
+ /**
3
+ * Extracts a reference name from an OpenAPI $ref string.
4
+ *
5
+ * This function parses JSON Pointer references (like '#/components/schemas/User')
6
+ * and extracts the final component as a branded RefName type. It's used throughout
7
+ * the SKMTC system to convert string references into type-safe reference names.
8
+ *
9
+ * @param $ref - The OpenAPI reference string (e.g., '#/components/schemas/User')
10
+ * @returns The extracted reference name as a branded RefName type
11
+ *
12
+ * @throws {Error} When the reference string is invalid or empty
13
+ *
14
+ * @example Basic usage
15
+ * ```typescript
16
+ * import { toRefName } from '@skmtc/core/helpers';
17
+ *
18
+ * const refName = toRefName('#/components/schemas/User');
19
+ * console.log(refName); // 'User' (typed as RefName)
20
+ *
21
+ * const responseRef = toRefName('#/components/responses/ErrorResponse');
22
+ * console.log(responseRef); // 'ErrorResponse' (typed as RefName)
23
+ * ```
24
+ *
25
+ * @example Error cases
26
+ * ```typescript
27
+ * // These will throw errors:
28
+ * toRefName('invalid/ref/'); // Error: 'Invalid reference'
29
+ * toRefName('#/components/schemas/'); // Error: 'Invalid reference'
30
+ * ```
31
+ *
32
+ * @example Integration with OAS processing
33
+ * ```typescript
34
+ * class SchemaProcessor {
35
+ * processReference(ref: string) {
36
+ * const refName = toRefName(ref);
37
+ * const schema = this.document.components.schemas[refName];
38
+ * return this.processSchema(schema, refName);
39
+ * }
40
+ * }
41
+ * ```
42
+ */
2
43
  export const toRefName = ($ref) => {
3
44
  // TODO: Add validation here to ensure reference exists
4
45
  const refName = $ref.split('/').slice(-1)[0];
@@ -7,6 +48,57 @@ export const toRefName = ($ref) => {
7
48
  }
8
49
  return refName;
9
50
  };
51
+ /**
52
+ * Type guard function to check if a value is an OpenAPI reference object.
53
+ *
54
+ * This function performs runtime type checking to determine if an unknown value
55
+ * is an OpenAPI Reference Object (contains a $ref property with a string value).
56
+ * It's essential for safely handling mixed schema/reference data during processing.
57
+ *
58
+ * @param value - The value to check for reference properties
59
+ * @returns True if the value is a reference object, false otherwise
60
+ *
61
+ * @example Basic type checking
62
+ * ```typescript
63
+ * import { isRef } from '@skmtc/core/helpers';
64
+ *
65
+ * const schemaOrRef: unknown = { $ref: '#/components/schemas/User' };
66
+ *
67
+ * if (isRef(schemaOrRef)) {
68
+ * // TypeScript now knows schemaOrRef has a $ref property
69
+ * console.log(schemaOrRef.$ref); // Safe to access
70
+ * const refName = toRefName(schemaOrRef.$ref);
71
+ * } else {
72
+ * // Handle as actual schema object
73
+ * console.log('Direct schema object');
74
+ * }
75
+ * ```
76
+ *
77
+ * @example Processing mixed data
78
+ * ```typescript
79
+ * function processSchemaOrRef(data: unknown) {
80
+ * if (isRef(data)) {
81
+ * // Handle reference
82
+ * return resolveReference(data.$ref);
83
+ * } else {
84
+ * // Handle direct schema
85
+ * return processSchema(data as SchemaObject);
86
+ * }
87
+ * }
88
+ * ```
89
+ *
90
+ * @example Array processing
91
+ * ```typescript
92
+ * const mixedArray: unknown[] = [
93
+ * { type: 'string' },
94
+ * { $ref: '#/components/schemas/User' },
95
+ * { type: 'number' }
96
+ * ];
97
+ *
98
+ * const references = mixedArray.filter(isRef);
99
+ * const schemas = mixedArray.filter(item => !isRef(item));
100
+ * ```
101
+ */
10
102
  export const isRef = (value) => {
11
103
  if (value && typeof value === 'object' && '$ref' in value && typeof value.$ref === 'string') {
12
104
  return true;
@@ -15,6 +107,70 @@ export const isRef = (value) => {
15
107
  return false;
16
108
  }
17
109
  };
110
+ /**
111
+ * Creates a reference resolver function for an OpenAPI document.
112
+ *
113
+ * This higher-order function returns a resolver that can dereference OpenAPI
114
+ * JSON Pointer references within the context of a specific document. It handles
115
+ * nested references by recursively resolving reference chains until it reaches
116
+ * an actual schema object.
117
+ *
118
+ * The resolver is particularly useful during schema processing where you need
119
+ * to follow reference chains to get the actual schema definitions.
120
+ *
121
+ * @param oasDocument - The OpenAPI document containing the schemas to resolve against
122
+ * @returns A function that resolves reference objects to schema objects
123
+ *
124
+ * @throws {Error} When a reference cannot be resolved or points to a non-existent schema
125
+ *
126
+ * @example Basic usage
127
+ * ```typescript
128
+ * import { toGetRef } from '@skmtc/core/helpers';
129
+ *
130
+ * const resolver = toGetRef(openApiDocument);
131
+ *
132
+ * const userSchema = resolver({ $ref: '#/components/schemas/User' });
133
+ * console.log(userSchema.type); // 'object'
134
+ * console.log(userSchema.properties); // User properties
135
+ * ```
136
+ *
137
+ * @example Resolving nested references
138
+ * ```typescript
139
+ * // If User references Address, and Address references Country
140
+ * const resolver = toGetRef(document);
141
+ *
142
+ * // This will follow the chain: User -> Address -> Country
143
+ * const resolvedSchema = resolver({ $ref: '#/components/schemas/User' });
144
+ * // Returns the final resolved schema object
145
+ * ```
146
+ *
147
+ * @example Error handling
148
+ * ```typescript
149
+ * const resolver = toGetRef(document);
150
+ *
151
+ * try {
152
+ * const schema = resolver({ $ref: '#/components/schemas/NonExistent' });
153
+ * } catch (error) {
154
+ * console.error('Reference resolution failed:', error.message);
155
+ * // Error: Invalid reference: #/components/schemas/NonExistent
156
+ * }
157
+ * ```
158
+ *
159
+ * @example Integration with schema processing
160
+ * ```typescript
161
+ * class SchemaProcessor {
162
+ * private resolver = toGetRef(this.document);
163
+ *
164
+ * processProperty(property: SchemaObject | ReferenceObject) {
165
+ * if (isRef(property)) {
166
+ * const resolved = this.resolver(property);
167
+ * return this.processSchema(resolved);
168
+ * }
169
+ * return this.processSchema(property);
170
+ * }
171
+ * }
172
+ * ```
173
+ */
18
174
  export const toGetRef = (oasDocument) => ({ $ref }) => {
19
175
  const refName = toRefName($ref);
20
176
  const item = oasDocument.components?.schemas?.[refName];