File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -555,6 +555,38 @@ describe('bundle', () => {
555555 expect ( problems ) . toHaveLength ( 0 ) ;
556556 expect ( res . parsed ) . toMatchSnapshot ( ) ;
557557 } ) ;
558+
559+ it ( 'should bundle discriminator with defaultMapping and mapping as component names to the same document' , async ( ) => {
560+ const document = outdent `
561+ openapi: 3.2.0
562+ components:
563+ schemas:
564+ Pet:
565+ type: object
566+ discriminator:
567+ propertyName: kind
568+ defaultMapping: Cat
569+ mapping:
570+ cat: Cat
571+ Cat:
572+ type: object
573+ properties:
574+ kind:
575+ type: string
576+
577+ ` ;
578+
579+ const {
580+ bundle : { parsed } ,
581+ problems,
582+ } = await bundleFromString ( {
583+ source : document ,
584+ config : await createConfig ( { } ) ,
585+ } ) ;
586+
587+ expect ( problems ) . toMatchInlineSnapshot ( `[]` ) ;
588+ expect ( parsed ) . toMatchInlineSnapshot ( document ) ;
589+ } ) ;
558590} ) ;
559591
560592describe ( 'bundleFromString' , ( ) => {
Original file line number Diff line number Diff line change 88 pointerBaseName ,
99 refBaseName ,
1010 type Location ,
11+ isMappingRef ,
1112} from '../ref-utils.js' ;
1213import { type ResolvedRefMap , type Document } from '../resolve.js' ;
1314import { 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