@@ -1385,5 +1385,156 @@ describe('enums', () => {
13851385
13861386 expect ( writeSwagger ( definitionMap , config ) ) . toEqual ( expectedSwagger ) ;
13871387 } ) ;
1388+ } ) ;
1389+
1390+ describe ( 'singleton resource support' , ( ) => {
1391+ it ( 'should generate swagger path without ID parameter for singleton resources' , ( ) => {
1392+ const definitionMap : DefinitionMap = new DefinitionMap ( ) ;
1393+ const entityMap : EntityMap = new Map < string , EntityType > ( ) ;
1394+
1395+ const adminEntity = new EntityType ( 'admin' , undefined , false , undefined , false , false , [ ] , [ ] ) ;
1396+ entityMap . set ( 'microsoft.graph.admin' , adminEntity ) ;
1397+
1398+ const entityTypes : Map < string , EntityTypeConfig > = new Map < string , EntityTypeConfig > ( ) ;
1399+ entityTypes . set ( 'microsoft.graph.admin' , {
1400+ Name : 'microsoft.graph.admin' ,
1401+ RootUri : '/admin' ,
1402+ Upsertable : true ,
1403+ IsSingleton : true ,
1404+ PathSegmentName : 'admin' ,
1405+ EntitySetPath : 'admin' ,
1406+ NavigationProperty : [ ]
1407+ } as EntityTypeConfig ) ;
1408+
1409+ const config = {
1410+ ExtensionVersion : "1.0.0" ,
1411+ EntityTypes : entityTypes ,
1412+ MetadataFilePath : 'https://example.com' ,
1413+ APIVersion : 'beta'
1414+ } as Config ;
1415+
1416+ definitionMap . EntityMap = entityMap ;
1417+ definitionMap . EnumMap = new Map ( ) ;
1418+
1419+ const result = writeSwagger ( definitionMap , config ) ;
1420+
1421+ // Check that the singleton path exists without ID parameter
1422+ expect ( result . paths [ '/{rootScope}/providers/Microsoft.Graph/admin' ] ) . toBeDefined ( ) ;
1423+
1424+ // Check that the operation exists
1425+ const adminPath = result . paths [ '/{rootScope}/providers/Microsoft.Graph/admin' ] ;
1426+ expect ( adminPath . put ) . toBeDefined ( ) ;
1427+
1428+ // Check that no ID parameter is included for singleton
1429+ if ( adminPath . put ) {
1430+ const parameters = adminPath . put . parameters ;
1431+ const idParameter = parameters . find ( p => p . name === 'adminId' ) ;
1432+ expect ( idParameter ) . toBeUndefined ( ) ;
1433+
1434+ // Should still have body parameter
1435+ const bodyParameter = parameters . find ( p => p . in === 'body' ) ;
1436+ expect ( bodyParameter ) . toBeDefined ( ) ;
1437+ }
1438+ } ) ;
13881439
1440+ it ( 'should generate swagger path with ID parameter for non-singleton resources' , ( ) => {
1441+ const definitionMap : DefinitionMap = new DefinitionMap ( ) ;
1442+ const entityMap : EntityMap = new Map < string , EntityType > ( ) ;
1443+
1444+ const userEntity = new EntityType ( 'user' , undefined , false , undefined , false , false , [ ] , [ ] ) ;
1445+ entityMap . set ( 'microsoft.graph.user' , userEntity ) ;
1446+
1447+ const entityTypes : Map < string , EntityTypeConfig > = new Map < string , EntityTypeConfig > ( ) ;
1448+ entityTypes . set ( 'microsoft.graph.user' , {
1449+ Name : 'microsoft.graph.user' ,
1450+ RootUri : '/users' ,
1451+ Upsertable : true ,
1452+ IsSingleton : false ,
1453+ NavigationProperty : [ ]
1454+ } as EntityTypeConfig ) ;
1455+
1456+ const config = {
1457+ ExtensionVersion : "1.0.0" ,
1458+ EntityTypes : entityTypes ,
1459+ MetadataFilePath : 'https://example.com' ,
1460+ APIVersion : 'beta'
1461+ } as Config ;
1462+
1463+ definitionMap . EntityMap = entityMap ;
1464+ definitionMap . EnumMap = new Map ( ) ;
1465+
1466+ const result = writeSwagger ( definitionMap , config ) ;
1467+
1468+ // Check that the regular path exists with ID parameter
1469+ expect ( result . paths [ '/{rootScope}/providers/Microsoft.Graph/users/{userId}' ] ) . toBeDefined ( ) ;
1470+
1471+ // Check that the operation exists
1472+ const userPath = result . paths [ '/{rootScope}/providers/Microsoft.Graph/users/{userId}' ] ;
1473+ expect ( userPath . put ) . toBeDefined ( ) ;
1474+
1475+ // Check that ID parameter is included for non-singleton
1476+ if ( userPath . put ) {
1477+ const parameters = userPath . put . parameters ;
1478+ const idParameter = parameters . find ( p => p . name === 'userId' ) ;
1479+ expect ( idParameter ) . toBeDefined ( ) ;
1480+ if ( idParameter ) {
1481+ expect ( idParameter . in ) . toBe ( 'path' ) ;
1482+ expect ( idParameter . required ) . toBe ( true ) ;
1483+ }
1484+ }
1485+ } ) ;
1486+
1487+ it ( 'should generate swagger for container singleton resources' , ( ) => {
1488+ const definitionMap : DefinitionMap = new DefinitionMap ( ) ;
1489+ const entityMap : EntityMap = new Map < string , EntityType > ( ) ;
1490+
1491+ const domainRegEntity = new EntityType ( 'domainRegistration' , undefined , false , undefined , false , false , [ ] , [ ] ) ;
1492+ entityMap . set ( 'microsoft.graph.domainRegistration' , domainRegEntity ) ;
1493+
1494+ const entityTypes : Map < string , EntityTypeConfig > = new Map < string , EntityTypeConfig > ( ) ;
1495+ entityTypes . set ( 'microsoft.graph.domainRegistration' , {
1496+ Name : 'microsoft.graph.domainRegistration' ,
1497+ RootUri : '/applications/domainRegistration' ,
1498+ Upsertable : true ,
1499+ IsSingleton : true ,
1500+ PathSegmentName : 'domainRegistration' ,
1501+ EntitySetPath : 'applications/domainRegistration' ,
1502+ ContainerEntitySet : 'applications' ,
1503+ NavigationProperty : [ ]
1504+ } as EntityTypeConfig ) ;
1505+
1506+ const config = {
1507+ ExtensionVersion : "1.0.0" ,
1508+ EntityTypes : entityTypes ,
1509+ MetadataFilePath : 'https://example.com' ,
1510+ APIVersion : 'beta'
1511+ } as Config ;
1512+
1513+ definitionMap . EntityMap = entityMap ;
1514+ definitionMap . EnumMap = new Map ( ) ;
1515+
1516+ const result = writeSwagger ( definitionMap , config ) ;
1517+
1518+ // Check that the container singleton path exists without ID parameter
1519+ expect ( result . paths [ '/{rootScope}/providers/Microsoft.Graph/applications/{applicationsId}/domainRegistration' ] ) . toBeDefined ( ) ;
1520+
1521+ // Check that the operation exists
1522+ const domainRegPath = result . paths [ '/{rootScope}/providers/Microsoft.Graph/applications/{applicationsId}/domainRegistration' ] ;
1523+ expect ( domainRegPath . put ) . toBeDefined ( ) ;
1524+
1525+ // Check that no ID parameter is included for the singleton itself
1526+ if ( domainRegPath . put ) {
1527+ const parameters = domainRegPath . put . parameters ;
1528+ const singletonIdParameter = parameters . find ( p => p . name === 'domainRegistrationId' ) ;
1529+ expect ( singletonIdParameter ) . toBeUndefined ( ) ;
1530+
1531+ // Should still have container ID parameter
1532+ const containerIdParameter = parameters . find ( p => p . name === 'applicationsId' ) ;
1533+ expect ( containerIdParameter ) . toBeDefined ( ) ;
1534+
1535+ // Should still have body parameter
1536+ const bodyParameter = parameters . find ( p => p . in === 'body' ) ;
1537+ expect ( bodyParameter ) . toBeDefined ( ) ;
1538+ }
1539+ } ) ;
13891540} ) ;
0 commit comments