File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -357,6 +357,12 @@ export class GenericsContext {
357
357
) : IParamValueConflict | undefined {
358
358
const genericTypeParameters = component . properties . genericTypeParameters ;
359
359
360
+ // Populate generic type instances with default generic values if applicable
361
+ while ( genericTypeInstances . length < genericTypeParameters . length &&
362
+ genericTypeParameters [ genericTypeInstances . length ] . property . default ) {
363
+ genericTypeInstances . push ( genericTypeParameters [ genericTypeInstances . length ] . property . default ) ;
364
+ }
365
+
360
366
// Don't do anything if no generic type instances are passed.
361
367
if ( genericTypeInstances . length === 0 ) {
362
368
return {
Original file line number Diff line number Diff line change @@ -1367,6 +1367,34 @@ describe('GenericsContext', () => {
1367
1367
. toEqual ( objectLoader . createCompactedResource ( 'xsd:number' ) ) ;
1368
1368
} ) ;
1369
1369
1370
+ it ( 'should handle missing instances that have default values' , ( ) => {
1371
+ genericsContext . bindGenericTypeToRange ( 'ex:Component__generic_T' , objectLoader
1372
+ . createCompactedResource ( 'xsd:string' ) , typeTypeValidatorAlwaysFalse ) ;
1373
+
1374
+ expect ( genericsContext . bindComponentGenericTypes (
1375
+ objectLoader . createCompactedResource ( {
1376
+ '@id' : 'ex:Component' ,
1377
+ genericTypeParameters : [
1378
+ 'ex:Component__generic_T' ,
1379
+ {
1380
+ '@id' : 'ex:Component__generic_U' ,
1381
+ default : 'xsd:number' ,
1382
+ } ,
1383
+ ] ,
1384
+ } ) ,
1385
+ [
1386
+ objectLoader . createCompactedResource ( {
1387
+ parameterRangeGenericBindings : 'xsd:string' ,
1388
+ } ) ,
1389
+ ] ,
1390
+ { } ,
1391
+ typeTypeValidatorOnlyIdentical ,
1392
+ ) ) . toBeUndefined ( ) ;
1393
+
1394
+ expect ( genericsContext . bindings [ 'ex:Component__generic_T' ] )
1395
+ . toEqual ( objectLoader . createCompactedResource ( 'xsd:string' ) ) ;
1396
+ } ) ;
1397
+
1370
1398
it ( 'should not handle instances that do not match' , ( ) => {
1371
1399
genericsContext . bindGenericTypeToRange ( 'ex:Component__generic_T' , objectLoader
1372
1400
. createCompactedResource ( 'xsd:boolean' ) , typeTypeValidatorAlwaysFalse ) ;
You can’t perform that action at this time.
0 commit comments