1
- /*
1
+ /**
2
2
* Node script to preprocess api.json files for use in the UI5 SDKs.
3
3
*
4
4
* (c) Copyright 2009-2024 SAP SE or an SAP affiliate company.
@@ -43,7 +43,7 @@ function fnCreateTypesArr(sTypes) {
43
43
} ) ;
44
44
}
45
45
46
- /*
46
+ /**
47
47
* Transforms the api.json as created by the JSDoc build into a pre-processed api.json file suitable for the SDK.
48
48
*
49
49
* The pre-processing includes formatting of type references, rewriting of links and other time consuming calculations.
@@ -121,8 +121,66 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
121
121
* @param {object } oChainObject chain object
122
122
*/
123
123
let transformApiJson = function ( oChainObject ) {
124
+ /**
125
+ * Check if a type is a built-in type, handling both simple
126
+ * and compound types gracefully.
127
+ *
128
+ * @param {string } type A type to check
129
+ * @returns {boolean } true if the type is built-in, otherwise false
130
+ */
124
131
function isBuiltInType ( type ) {
125
- return formatters . _baseTypes . indexOf ( type ) >= 0 ;
132
+ const builtInTypes = formatters . _baseTypes ;
133
+
134
+ // Early return if the type is directly in baseTypes
135
+ if ( builtInTypes . includes ( type ) ) {
136
+ return true ;
137
+ }
138
+
139
+ // Handle array notation directly
140
+ if ( type . endsWith ( "[]" ) ) {
141
+ return builtInTypes . includes ( type . slice ( 0 , - 2 ) ) ;
142
+ }
143
+
144
+ // Check if the type is a union type
145
+ if ( type . includes ( "|" ) ) {
146
+ const unionParts = type . split ( "|" ) . map ( part => part . trim ( ) ) ;
147
+ return unionParts . every ( part => isBuiltInType ( part ) ) ;
148
+ }
149
+
150
+ // Predefined regex patterns for reuse
151
+ const arrayRegex = / A r r a y < ( .+ ) > / ;
152
+ const arrayDotRegex = / A r r a y \. < ( .+ ) > / ;
153
+ const objectRegex = / O b j e c t < ( [ ^ , ] + ) , ( [ ^ > ] + ) > / ;
154
+ const objectDotRegex = / O b j e c t \. < ( [ ^ , ] + ) , ( [ ^ > ] + ) > / ;
155
+
156
+ // Check if the type is a generic Array type
157
+ const arrayMatch = arrayRegex . exec ( type ) ;
158
+ if ( arrayMatch ) {
159
+ const innerType = arrayMatch [ 1 ] ;
160
+ return isBuiltInType ( innerType ) ;
161
+ }
162
+
163
+ const arrayDotMatch = arrayDotRegex . exec ( type ) ;
164
+ if ( arrayDotMatch ) {
165
+ const innerType = arrayDotMatch [ 1 ] ;
166
+ return isBuiltInType ( innerType ) ;
167
+ }
168
+
169
+ // Check if the type is a generic Object type
170
+ const objectMatch = objectRegex . exec ( type ) ;
171
+ if ( objectMatch ) {
172
+ const innerTypes = [ objectMatch [ 1 ] , objectMatch [ 2 ] ] . map ( t => t . trim ( ) ) ;
173
+ return innerTypes . every ( innerType => isBuiltInType ( innerType ) ) ;
174
+ }
175
+
176
+ const objectDotMatch = objectDotRegex . exec ( type ) ;
177
+ if ( objectDotMatch ) {
178
+ const innerTypes = [ objectDotMatch [ 1 ] , objectDotMatch [ 2 ] ] . map ( t => t . trim ( ) ) ;
179
+ return innerTypes . every ( innerType => isBuiltInType ( innerType ) ) ;
180
+ }
181
+
182
+ // Fallback case: if none of the above matched, return false
183
+ return false ;
126
184
}
127
185
128
186
/**
@@ -1106,32 +1164,28 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
1106
1164
} ) ;
1107
1165
}
1108
1166
1109
- /*
1167
+ /**
1110
1168
* =====================================================================================================================
1111
1169
* IMPORTANT NOTE: Formatter code is a copy from APIDetail.controller.js with a very little modification and mocking and
1112
1170
* code can be significantly improved
1113
1171
* =====================================================================================================================
1114
1172
*/
1115
1173
let formatters = {
1116
-
1117
1174
_sTopicId : "" ,
1118
1175
_oTopicData : { } ,
1119
1176
_baseTypes : [
1120
- // TODO this list URGENTLY needs to be replaced by the Type parser and a much smaller list
1121
1177
"sap.ui.core.any" ,
1122
1178
"sap.ui.core.object" ,
1123
1179
"sap.ui.core.function" ,
1124
- "sap.ui.core.number" , // TODO discuss with Thomas, type does not exist
1180
+ "sap.ui.core.number" ,
1125
1181
"sap.ui.core.float" ,
1126
1182
"sap.ui.core.int" ,
1127
1183
"sap.ui.core.boolean" ,
1128
1184
"sap.ui.core.string" ,
1129
1185
"sap.ui.core.void" ,
1130
1186
"null" ,
1131
1187
"any" ,
1132
- "any[]" ,
1133
1188
"Error" ,
1134
- "Error[]" ,
1135
1189
"array" ,
1136
1190
"element" ,
1137
1191
"Element" ,
@@ -1141,19 +1195,11 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
1141
1195
"QUnit.Assert" ,
1142
1196
"object" ,
1143
1197
"Object" ,
1144
- "object[]" ,
1145
- "object|object[]" ,
1146
- "[object Object][]" ,
1147
- "Array<[object Object]>" ,
1148
- "Array.<[object Object]>" ,
1149
- "Object<string,string>" ,
1150
- "Object.<string,string>" ,
1151
1198
"function" ,
1152
1199
"float" ,
1153
1200
"int" ,
1154
1201
"boolean" ,
1155
1202
"string" ,
1156
- "string[]" ,
1157
1203
"number" ,
1158
1204
"map" ,
1159
1205
"promise" ,
@@ -1163,7 +1209,8 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
1163
1209
"Touch" ,
1164
1210
"TouchList" ,
1165
1211
"undefined" ,
1166
- "this"
1212
+ "this" ,
1213
+ "[object Object]"
1167
1214
] ,
1168
1215
ANNOTATIONS_LINK : 'http://docs.oasis-open.org/odata/odata/v4.0/odata-v4.0-part3-csdl.html' ,
1169
1216
ANNOTATIONS_NAMESPACE_LINK : 'http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/vocabularies/' ,
0 commit comments