1
1
import type { Config } from '../../../types/config' ;
2
2
import type { Logger } from '../../../utils/logger' ;
3
3
import { jsonPointerToPath } from '../../../utils/ref' ;
4
+ import deepEqual from '../utils/deepEqual' ;
4
5
import { buildGraph , type Graph , type Scope } from '../utils/graph' ;
5
6
import { buildName } from '../utils/name' ;
6
7
import { deepClone } from '../utils/schema' ;
@@ -16,43 +17,6 @@ import {
16
17
specToSchemasPointerNamespace ,
17
18
} from './utils' ;
18
19
19
- /**
20
- * Deep equality for JSON-compatible values (objects, arrays, primitives).
21
- * Used to determine whether read/write pruned variants actually differ.
22
- */
23
- const deepEqual = ( a : unknown , b : unknown ) : boolean => {
24
- if ( a === b ) return true ;
25
- if ( a === null || b === null ) return a === b ;
26
- const typeA = typeof a ;
27
- const typeB = typeof b ;
28
- if ( typeA !== typeB ) return false ;
29
- if ( typeA !== 'object' ) return false ;
30
-
31
- // Arrays
32
- if ( Array . isArray ( a ) || Array . isArray ( b ) ) {
33
- if ( ! Array . isArray ( a ) || ! Array . isArray ( b ) ) return false ;
34
- if ( a . length !== b . length ) return false ;
35
- for ( let i = 0 ; i < a . length ; i ++ ) {
36
- if ( ! deepEqual ( a [ i ] , b [ i ] ) ) return false ;
37
- }
38
- return true ;
39
- }
40
-
41
- // Plain objects
42
- const objA = a as Record < string , unknown > ;
43
- const objB = b as Record < string , unknown > ;
44
- const keysA = Object . keys ( objA ) . sort ( ) ;
45
- const keysB = Object . keys ( objB ) . sort ( ) ;
46
- if ( keysA . length !== keysB . length ) return false ;
47
- for ( let i = 0 ; i < keysA . length ; i ++ ) {
48
- if ( keysA [ i ] !== keysB [ i ] ) return false ;
49
- }
50
- for ( const key of keysA ) {
51
- if ( ! deepEqual ( objA [ key ] , objB [ key ] ) ) return false ;
52
- }
53
- return true ;
54
- } ;
55
-
56
20
type OriginalSchemas = Record < string , unknown > ;
57
21
58
22
type SplitSchemas = {
@@ -632,36 +596,6 @@ export const updateRefsInSpec = ({
632
596
} else if ( key === '$ref' && typeof value === 'string' ) {
633
597
// Prefer exact match first
634
598
const map = split . mapping [ value ] ;
635
- // if (!map && value.startsWith(schemasPointerNamespace)) {
636
- // // Handle nested refs like '#/components/schemas/Foo/properties/Bar'
637
- // // by remapping the base schema pointer and preserving the suffix.
638
- // const path = jsonPointerToPath(value);
639
- // // schemasPointerNamespace ends with trailing '/', so its segments length is:
640
- // const baseSegments = schemasPointerNamespace
641
- // .split('/')
642
- // .filter(Boolean).length;
643
- // if (path.length > baseSegments) {
644
- // const baseSchemaName = path[baseSegments - 1];
645
- // const baseOriginalPointer = `${schemasPointerNamespace}${baseSchemaName}`;
646
- // map = split.mapping[baseOriginalPointer];
647
- // if (map) {
648
- // const suffixSegments = path.slice(baseSegments);
649
- // const suffix = suffixSegments.length
650
- // ? `/${suffixSegments.join('/')}`
651
- // : '';
652
- // if (map.read && (!nextContext || nextContext === 'read')) {
653
- // (node as Record<string, unknown>)[key] =
654
- // `${map.read}${suffix}`;
655
- // } else if (
656
- // map.write &&
657
- // (!nextContext || nextContext === 'write')
658
- // ) {
659
- // (node as Record<string, unknown>)[key] =
660
- // `${map.write}${suffix}`;
661
- // }
662
- // }
663
- // }
664
- // } else
665
599
if ( map ) {
666
600
if ( map . read && ( ! nextContext || nextContext === 'read' ) ) {
667
601
( node as Record < string , unknown > ) [ key ] = map . read ;
0 commit comments