1
1
/**
2
2
* Converts OData CSDL JSON to OpenAPI 3.0.2
3
3
*/
4
-
4
+ const cds = require ( '@sap/cds' ) ;
5
5
var pluralize = require ( 'pluralize' )
6
+ const DEBUG = cds . debug ( 'openapi' ) ; // Initialize cds.debug with the 'openapi'
7
+
6
8
7
9
//TODO
8
10
// - Core.Example for complex types
@@ -325,7 +327,7 @@ module.exports.csdl2openapi = function (
325
327
) ;
326
328
}
327
329
if ( ! element ) {
328
- console . warn ( `Invalid annotation target '${ target } '` ) ;
330
+ DEBUG ?. ( `Invalid annotation target '${ target } '` ) ;
329
331
} else if ( Array . isArray ( element ) ) {
330
332
//TODO: action or function:
331
333
//- loop over all overloads
@@ -348,12 +350,12 @@ module.exports.csdl2openapi = function (
348
350
if ( element [ segments [ 1 ] ] ) {
349
351
Object . assign ( element [ segments [ 1 ] ] , annotations ) ;
350
352
} else {
351
- // console.warn (`Invalid annotation target '${target}'`)
353
+ // DEBUG?. (`Invalid annotation target '${target}'`)
352
354
}
353
355
}
354
356
break ;
355
357
default :
356
- console . warn ( 'More than two annotation target path segments' ) ;
358
+ DEBUG ?. ( 'More than two annotation target path segments' ) ;
357
359
}
358
360
}
359
361
} ) ;
@@ -655,7 +657,7 @@ module.exports.csdl2openapi = function (
655
657
} else if ( child . $Function ) {
656
658
pathItemFunctionImport ( paths , name , child ) ;
657
659
} else {
658
- console . warn ( 'Unrecognized entity container child: ' + name ) ;
660
+ DEBUG ?. ( 'Unrecognized entity container child: ' + name ) ;
659
661
}
660
662
} )
661
663
if ( resources . length > 0 ) pathItemBatch ( paths , container ) ;
@@ -1148,7 +1150,7 @@ see [Expand](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-prot
1148
1150
const elementType = modelElement ( element . $Type ) ;
1149
1151
1150
1152
if ( ! elementType ) {
1151
- console . warn ( `Unknown type for element: ${ JSON . stringify ( element ) } ` ) ;
1153
+ DEBUG ?. ( `Unknown type for element: ${ JSON . stringify ( element ) } ` ) ;
1152
1154
return paths ;
1153
1155
}
1154
1156
@@ -1160,7 +1162,7 @@ see [Expand](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-prot
1160
1162
. filter ( entry => ! modelElement ( entry [ 1 ] . $Type ) ) ;
1161
1163
1162
1164
// Keep old logging
1163
- ignore . forEach ( entry => console . warn ( `Unknown type for element: ${ JSON . stringify ( entry ) } ` ) ) ;
1165
+ ignore . forEach ( entry => DEBUG ?. ( `Unknown type for element: ${ JSON . stringify ( entry ) } ` ) ) ;
1164
1166
1165
1167
const properties = Object . entries ( propsOfType )
1166
1168
. filter ( entry => entry [ 1 ] . $Kind !== 'NavigationProperty' )
@@ -1178,7 +1180,7 @@ see [Expand](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-prot
1178
1180
1179
1181
// Allow full cycle to be shown (0) times
1180
1182
if ( property . typeRefChain . filter ( _type => _type === typeRefChainTail ) . length > 1 ) {
1181
- console . warn ( `Cycle detected ${ property . typeRefChain . join ( '->' ) } ` ) ;
1183
+ DEBUG ?. ( `Cycle detected ${ property . typeRefChain . join ( '->' ) } ` ) ;
1182
1184
continue ;
1183
1185
}
1184
1186
@@ -2394,7 +2396,7 @@ see [Expand](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-prot
2394
2396
break ;
2395
2397
default :
2396
2398
if ( element . $Type . startsWith ( 'Edm.' ) ) {
2397
- console . warn ( 'Unknown type: ' + element . $Type ) ;
2399
+ DEBUG ?. ( 'Unknown type: ' + element . $Type ) ;
2398
2400
} else {
2399
2401
let type = modelElement ( element . $Type ) ;
2400
2402
let isStructured = type && [ 'ComplexType' , 'EntityType' ] . includes ( type . $Kind ) ;
@@ -2597,7 +2599,7 @@ see [Expand](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-prot
2597
2599
break ;
2598
2600
default :
2599
2601
unknown = true
2600
- console . warn ( 'Unknown Authorization type ' + qualifiedType ) ;
2602
+ DEBUG ?. ( 'Unknown Authorization type ' + qualifiedType ) ;
2601
2603
}
2602
2604
if ( ! unknown ) schemes [ auth . Name ] = scheme ;
2603
2605
} ) ;
@@ -2619,7 +2621,7 @@ see [Expand](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-prot
2619
2621
const securitySchemes = entityContainer && entityContainer [ voc . Authorization . SecuritySchemes ] ? entityContainer [ voc . Authorization . SecuritySchemes ] : [ ] ;
2620
2622
// check if securitySchemas exist if it does not exist then throw a warning
2621
2623
if ( securitySchemes . length === 0 ) {
2622
- console . warn ( 'No security schemes defined in the entity container' ) ;
2624
+ DEBUG ?. ( 'No security schemes defined in the entity container' ) ;
2623
2625
}
2624
2626
if ( securitySchemes . length > 0 ) openapi . security = [ ] ;
2625
2627
securitySchemes . forEach ( scheme => {
@@ -2661,5 +2663,5 @@ see [Expand](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-prot
2661
2663
function isIdentifier ( name ) {
2662
2664
return ! name . startsWith ( '$' ) && ! name . includes ( '@' ) ;
2663
2665
}
2664
-
2666
+
2665
2667
} ;
0 commit comments