File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -490,6 +490,38 @@ describe('bundle', () => {
490490 expect ( problems ) . toHaveLength ( 0 ) ;
491491 expect ( res . parsed ) . toMatchSnapshot ( ) ;
492492 } ) ;
493+
494+ it ( 'should bundle discriminator with defaultMapping and mapping as component names to the same document' , async ( ) => {
495+ const document = outdent `
496+ openapi: 3.2.0
497+ components:
498+ schemas:
499+ Pet:
500+ type: object
501+ discriminator:
502+ propertyName: kind
503+ defaultMapping: Cat
504+ mapping:
505+ cat: Cat
506+ Cat:
507+ type: object
508+ properties:
509+ kind:
510+ type: string
511+
512+ ` ;
513+
514+ const {
515+ bundle : { parsed } ,
516+ problems,
517+ } = await bundleFromString ( {
518+ source : document ,
519+ config : await createConfig ( { } ) ,
520+ } ) ;
521+
522+ expect ( problems ) . toMatchInlineSnapshot ( `[]` ) ;
523+ expect ( parsed ) . toMatchInlineSnapshot ( document ) ;
524+ } ) ;
493525} ) ;
494526
495527describe ( 'bundleFromString' , ( ) => {
Original file line number Diff line number Diff line change 77 isRef ,
88 refBaseName ,
99 type Location ,
10+ isMappingRef ,
1011} from '../ref-utils.js' ;
1112import { type ResolvedRefMap , type Document } from '../resolve.js' ;
1213import { reportUnresolvedRef } from '../rules/common/no-unresolved-refs.js' ;
@@ -208,7 +209,12 @@ export function makeBundleVisitor({
208209 const componentType = mapTypeToComponent ( 'Schema' , version ) ! ;
209210 visitor . Discriminator = {
210211 leave ( discriminator : Oas3Discriminator , ctx : UserContext ) {
211- if ( typeof discriminator . defaultMapping !== 'string' ) return ;
212+ if (
213+ typeof discriminator . defaultMapping !== 'string' ||
214+ ! isMappingRef ( discriminator . defaultMapping )
215+ ) {
216+ return ;
217+ }
212218
213219 const resolved = ctx . resolve ( { $ref : discriminator . defaultMapping } ) ;
214220 if ( ! resolved . location || resolved . node === undefined ) {
@@ -222,6 +228,9 @@ export function makeBundleVisitor({
222228 leave ( mapping , ctx ) {
223229 for ( const name of Object . keys ( mapping ) ) {
224230 const $ref = mapping [ name ] ;
231+ if ( ! isMappingRef ( $ref ) ) {
232+ continue ;
233+ }
225234 const resolved = ctx . resolve ( { $ref } ) ;
226235 if ( ! resolved . location || resolved . node === undefined ) {
227236 reportUnresolvedRef ( resolved , ctx . report , ctx . location . child ( name ) ) ;
You can’t perform that action at this time.
0 commit comments