8
8
getRegistryName ,
9
9
} from "./util.js" ;
10
10
import path from "path" ;
11
+ import { DiffClient } from "./diff-client.js" ;
11
12
12
13
/** The registry to look up the name within. */
13
14
export enum RegistryKind {
@@ -87,10 +88,10 @@ export class DefinitionRegistry {
87
88
private providedPaths = new Set < string > ( ) ;
88
89
private referenceStack : string [ ] = [ ] ;
89
90
private referenceMap = new Map < string , Set < string > > ( ) ;
90
- private currentPath : string | undefined ;
91
- private args : any ;
91
+ private currentPath : string [ ] ;
92
+ private client : DiffClient ;
92
93
93
- constructor ( map : Map < string , OpenAPIV2 . Document > , args : any ) {
94
+ constructor ( map : Map < string , OpenAPIV2 . Document > , client : DiffClient ) {
94
95
this . data = {
95
96
definitions : new CollectionRegistry (
96
97
map ,
@@ -116,9 +117,9 @@ export class DefinitionRegistry {
116
117
for ( const key of map . keys ( ) ) {
117
118
this . providedPaths . add ( path . normalize ( key ) ) ;
118
119
}
119
- this . currentPath ;
120
+ this . currentPath = [ ] ;
121
+ this . client = client ;
120
122
this . #gatherDefinitions( map ) ;
121
- this . args = args ;
122
123
this . #expandReferences( ) ;
123
124
}
124
125
@@ -131,7 +132,6 @@ export class DefinitionRegistry {
131
132
if ( ! refResult ) {
132
133
return item ;
133
134
}
134
- // FIXME: Need to proprogate suppressions here too
135
135
let match = this . get ( refResult ) ;
136
136
if ( match ) {
137
137
if ( this . referenceStack . includes ( refResult . name ) ) {
@@ -161,7 +161,9 @@ export class DefinitionRegistry {
161
161
this . #expandDerivedClasses( item ) ;
162
162
this . #expandAllOf( item ) ;
163
163
for ( const [ propName , propValue ] of toSorted ( Object . entries ( item ) ) ) {
164
+ this . currentPath . push ( propName ) ;
164
165
expanded [ propName ] = this . #expand( propValue ) ;
166
+ this . currentPath . pop ( ) ;
165
167
}
166
168
return expanded ;
167
169
}
@@ -218,7 +220,10 @@ export class DefinitionRegistry {
218
220
const itemVal = item [ key ] ;
219
221
switch ( key ) {
220
222
case "required" :
221
- base [ key ] = ( baseVal ?? [ ] ) . concat ( itemVal ?? [ ] ) ;
223
+ const mergedRequired = new Set (
224
+ ( baseVal ?? [ ] ) . concat ( itemVal ?? [ ] )
225
+ ) ;
226
+ base [ key ] = [ ...mergedRequired ] ;
222
227
break ;
223
228
case "properties" :
224
229
base [ key ] = { ...( baseVal ?? { } ) , ...( itemVal ?? { } ) } ;
@@ -296,10 +301,11 @@ export class DefinitionRegistry {
296
301
#expandReferencesForCollection( collection : CollectionRegistry ) {
297
302
this . referenceStack = [ ] ;
298
303
for ( const [ filepath , values ] of collection . data . entries ( ) ) {
299
- this . currentPath = filepath ;
300
304
for ( const [ key , value ] of values . entries ( ) ) {
305
+ this . currentPath . push ( key ) ;
301
306
let expanded = this . #expand( value , key , filepath ) ;
302
307
collection . data . get ( filepath ) ! . set ( key , expanded ) ;
308
+ this . currentPath . pop ( ) ;
303
309
}
304
310
}
305
311
// replace $derivedClasses with $anyOf that contains the expansions of the derived classes
@@ -312,10 +318,18 @@ export class DefinitionRegistry {
312
318
}
313
319
314
320
#expandReferences( ) {
321
+ this . currentPath . push ( "definitions" ) ;
315
322
this . #expandReferencesForCollection( this . data . definitions ) ;
323
+ this . currentPath . pop ( ) ;
324
+ this . currentPath . push ( "parameters" ) ;
316
325
this . #expandReferencesForCollection( this . data . parameters ) ;
326
+ this . currentPath . pop ( ) ;
327
+ this . currentPath . push ( "responses" ) ;
317
328
this . #expandReferencesForCollection( this . data . responses ) ;
329
+ this . currentPath . pop ( ) ;
330
+ this . currentPath . push ( "securityDefinitions" ) ;
318
331
this . #expandReferencesForCollection( this . data . securityDefinitions ) ;
332
+ this . currentPath . pop ( ) ;
319
333
}
320
334
321
335
/**
0 commit comments