@@ -10,7 +10,7 @@ import {
1010} from '../ref-utils.js' ;
1111import { type ResolvedRefMap , type Document } from '../resolve.js' ;
1212import { reportUnresolvedRef } from '../rules/common/no-unresolved-refs.js' ;
13- import { type OasRef } from '../typings/openapi.js' ;
13+ import { type OasRef , type Oas3Discriminator } from '../typings/openapi.js' ;
1414import { dequal } from '../utils/dequal.js' ;
1515import { isTruthy } from '../utils/is-truthy.js' ;
1616import { makeRefId } from '../utils/make-ref-id.js' ;
@@ -205,19 +205,32 @@ export function makeBundleVisitor({
205205 } ;
206206
207207 if ( version === 'oas3' ) {
208- visitor . DiscriminatorMapping = {
209- leave ( mapping : Record < string , string > , ctx : UserContext ) {
210- for ( const name of Object . keys ( mapping ) ) {
211- const $ref = mapping [ name ] ;
212- const resolved = ctx . resolve ( { $ref } ) ;
213- if ( ! resolved . location || resolved . node === undefined ) {
214- reportUnresolvedRef ( resolved , ctx . report , ctx . location . child ( name ) ) ;
215- return ;
216- }
208+ const componentType = mapTypeToComponent ( 'Schema' , version ) ! ;
209+ visitor . Discriminator = {
210+ leave ( discriminator : Oas3Discriminator , ctx : UserContext ) {
211+ if ( typeof discriminator . defaultMapping !== 'string' ) return ;
217212
218- const componentType = mapTypeToComponent ( 'Schema' , version ) ! ;
219- mapping [ name ] = saveComponent ( componentType , resolved , ctx ) ;
213+ const resolved = ctx . resolve ( { $ref : discriminator . defaultMapping } ) ;
214+ if ( ! resolved . location || resolved . node === undefined ) {
215+ reportUnresolvedRef ( resolved , ctx . report , ctx . location . child ( 'defaultMapping' ) ) ;
216+ return ;
220217 }
218+
219+ discriminator . defaultMapping = saveComponent ( componentType , resolved , ctx ) ;
220+ } ,
221+ DiscriminatorMapping : {
222+ leave ( mapping , ctx ) {
223+ for ( const name of Object . keys ( mapping ) ) {
224+ const $ref = mapping [ name ] ;
225+ const resolved = ctx . resolve ( { $ref } ) ;
226+ if ( ! resolved . location || resolved . node === undefined ) {
227+ reportUnresolvedRef ( resolved , ctx . report , ctx . location . child ( name ) ) ;
228+ return ;
229+ }
230+
231+ mapping [ name ] = saveComponent ( componentType , resolved , ctx ) ;
232+ }
233+ } ,
221234 } ,
222235 } ;
223236 }
0 commit comments