ng-openapi 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.cjs +69 -11
- package/index.js +69 -11
- package/package.json +1 -1
package/cli.cjs
CHANGED
|
@@ -767,10 +767,6 @@ function camelCase(str) {
|
|
|
767
767
|
return cleaned.charAt(0).toLowerCase() + cleaned.slice(1);
|
|
768
768
|
}
|
|
769
769
|
__name(camelCase, "camelCase");
|
|
770
|
-
function kebabCase(str) {
|
|
771
|
-
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
772
|
-
}
|
|
773
|
-
__name(kebabCase, "kebabCase");
|
|
774
770
|
function pascalCase(str) {
|
|
775
771
|
return str.replace(/(?:^|[-_])([a-z])/g, (_, char) => char.toUpperCase());
|
|
776
772
|
}
|
|
@@ -907,20 +903,51 @@ var ServiceMethodBodyGenerator = class {
|
|
|
907
903
|
});
|
|
908
904
|
continue;
|
|
909
905
|
}
|
|
906
|
+
const isPrimitive = this.isPrimitiveType(schema);
|
|
910
907
|
const inferredType = this.inferResponseTypeFromContentType(contentType);
|
|
911
908
|
let priority = 3;
|
|
912
|
-
|
|
909
|
+
let finalType = inferredType;
|
|
910
|
+
if (inferredType === "json" && isPrimitive) {
|
|
911
|
+
finalType = "text";
|
|
912
|
+
priority = 2;
|
|
913
|
+
} else if (inferredType === "json") {
|
|
913
914
|
priority = 2;
|
|
914
915
|
}
|
|
915
916
|
responseTypes.push({
|
|
916
|
-
type:
|
|
917
|
+
type: finalType,
|
|
917
918
|
priority,
|
|
918
|
-
contentType
|
|
919
|
+
contentType,
|
|
920
|
+
isPrimitive
|
|
919
921
|
});
|
|
920
922
|
}
|
|
921
923
|
responseTypes.sort((a, b) => a.priority - b.priority);
|
|
922
924
|
return responseTypes[0]?.type || "json";
|
|
923
925
|
}
|
|
926
|
+
isPrimitiveType(schema) {
|
|
927
|
+
if (!schema) return false;
|
|
928
|
+
const primitiveTypes = [
|
|
929
|
+
"string",
|
|
930
|
+
"number",
|
|
931
|
+
"integer",
|
|
932
|
+
"boolean"
|
|
933
|
+
];
|
|
934
|
+
if (primitiveTypes.includes(schema.type)) {
|
|
935
|
+
return true;
|
|
936
|
+
}
|
|
937
|
+
if (schema.type === "array") {
|
|
938
|
+
return false;
|
|
939
|
+
}
|
|
940
|
+
if (schema.type === "object" || schema.properties) {
|
|
941
|
+
return false;
|
|
942
|
+
}
|
|
943
|
+
if (schema.$ref) {
|
|
944
|
+
return false;
|
|
945
|
+
}
|
|
946
|
+
if (schema.allOf || schema.oneOf || schema.anyOf) {
|
|
947
|
+
return false;
|
|
948
|
+
}
|
|
949
|
+
return false;
|
|
950
|
+
}
|
|
924
951
|
createGenerationContext(operation) {
|
|
925
952
|
return {
|
|
926
953
|
pathParams: operation.parameters?.filter((p) => p.in === "path") || [],
|
|
@@ -1331,20 +1358,51 @@ var ServiceMethodOverloadsGenerator = class {
|
|
|
1331
1358
|
});
|
|
1332
1359
|
continue;
|
|
1333
1360
|
}
|
|
1361
|
+
const isPrimitive = this.isPrimitiveType(schema);
|
|
1334
1362
|
const inferredType = this.inferResponseTypeFromContentType(contentType);
|
|
1335
1363
|
let priority = 3;
|
|
1336
|
-
|
|
1364
|
+
let finalType = inferredType;
|
|
1365
|
+
if (inferredType === "json" && isPrimitive) {
|
|
1366
|
+
finalType = "text";
|
|
1367
|
+
priority = 2;
|
|
1368
|
+
} else if (inferredType === "json") {
|
|
1337
1369
|
priority = 2;
|
|
1338
1370
|
}
|
|
1339
1371
|
responseTypes.push({
|
|
1340
|
-
type:
|
|
1372
|
+
type: finalType,
|
|
1341
1373
|
priority,
|
|
1342
|
-
contentType
|
|
1374
|
+
contentType,
|
|
1375
|
+
isPrimitive
|
|
1343
1376
|
});
|
|
1344
1377
|
}
|
|
1345
1378
|
responseTypes.sort((a, b) => a.priority - b.priority);
|
|
1346
1379
|
return responseTypes[0]?.type || "json";
|
|
1347
1380
|
}
|
|
1381
|
+
isPrimitiveType(schema) {
|
|
1382
|
+
if (!schema) return false;
|
|
1383
|
+
const primitiveTypes = [
|
|
1384
|
+
"string",
|
|
1385
|
+
"number",
|
|
1386
|
+
"integer",
|
|
1387
|
+
"boolean"
|
|
1388
|
+
];
|
|
1389
|
+
if (primitiveTypes.includes(schema.type)) {
|
|
1390
|
+
return true;
|
|
1391
|
+
}
|
|
1392
|
+
if (schema.type === "array") {
|
|
1393
|
+
return false;
|
|
1394
|
+
}
|
|
1395
|
+
if (schema.type === "object" || schema.properties) {
|
|
1396
|
+
return false;
|
|
1397
|
+
}
|
|
1398
|
+
if (schema.$ref) {
|
|
1399
|
+
return false;
|
|
1400
|
+
}
|
|
1401
|
+
if (schema.allOf || schema.oneOf || schema.anyOf) {
|
|
1402
|
+
return false;
|
|
1403
|
+
}
|
|
1404
|
+
return false;
|
|
1405
|
+
}
|
|
1348
1406
|
getResponseType(response) {
|
|
1349
1407
|
const responseType = this.getResponseTypeFromResponse(response);
|
|
1350
1408
|
switch (responseType) {
|
|
@@ -1561,7 +1619,7 @@ var ServiceGenerator = class {
|
|
|
1561
1619
|
return groups;
|
|
1562
1620
|
}
|
|
1563
1621
|
generateServiceFile(controllerName, operations, outputDir) {
|
|
1564
|
-
const fileName = `${
|
|
1622
|
+
const fileName = `${camelCase(controllerName)}.service.ts`;
|
|
1565
1623
|
const filePath = path5.join(outputDir, fileName);
|
|
1566
1624
|
const sourceFile = this.project.createSourceFile(filePath, "", {
|
|
1567
1625
|
overwrite: true
|
package/index.js
CHANGED
|
@@ -806,10 +806,6 @@ function camelCase(str) {
|
|
|
806
806
|
return cleaned.charAt(0).toLowerCase() + cleaned.slice(1);
|
|
807
807
|
}
|
|
808
808
|
__name(camelCase, "camelCase");
|
|
809
|
-
function kebabCase(str) {
|
|
810
|
-
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
811
|
-
}
|
|
812
|
-
__name(kebabCase, "kebabCase");
|
|
813
809
|
function pascalCase(str) {
|
|
814
810
|
return str.replace(/(?:^|[-_])([a-z])/g, (_, char) => char.toUpperCase());
|
|
815
811
|
}
|
|
@@ -946,20 +942,51 @@ var _ServiceMethodBodyGenerator = class _ServiceMethodBodyGenerator {
|
|
|
946
942
|
});
|
|
947
943
|
continue;
|
|
948
944
|
}
|
|
945
|
+
const isPrimitive = this.isPrimitiveType(schema);
|
|
949
946
|
const inferredType = this.inferResponseTypeFromContentType(contentType);
|
|
950
947
|
let priority = 3;
|
|
951
|
-
|
|
948
|
+
let finalType = inferredType;
|
|
949
|
+
if (inferredType === "json" && isPrimitive) {
|
|
950
|
+
finalType = "text";
|
|
951
|
+
priority = 2;
|
|
952
|
+
} else if (inferredType === "json") {
|
|
952
953
|
priority = 2;
|
|
953
954
|
}
|
|
954
955
|
responseTypes.push({
|
|
955
|
-
type:
|
|
956
|
+
type: finalType,
|
|
956
957
|
priority,
|
|
957
|
-
contentType
|
|
958
|
+
contentType,
|
|
959
|
+
isPrimitive
|
|
958
960
|
});
|
|
959
961
|
}
|
|
960
962
|
responseTypes.sort((a, b) => a.priority - b.priority);
|
|
961
963
|
return ((_c = responseTypes[0]) == null ? void 0 : _c.type) || "json";
|
|
962
964
|
}
|
|
965
|
+
isPrimitiveType(schema) {
|
|
966
|
+
if (!schema) return false;
|
|
967
|
+
const primitiveTypes = [
|
|
968
|
+
"string",
|
|
969
|
+
"number",
|
|
970
|
+
"integer",
|
|
971
|
+
"boolean"
|
|
972
|
+
];
|
|
973
|
+
if (primitiveTypes.includes(schema.type)) {
|
|
974
|
+
return true;
|
|
975
|
+
}
|
|
976
|
+
if (schema.type === "array") {
|
|
977
|
+
return false;
|
|
978
|
+
}
|
|
979
|
+
if (schema.type === "object" || schema.properties) {
|
|
980
|
+
return false;
|
|
981
|
+
}
|
|
982
|
+
if (schema.$ref) {
|
|
983
|
+
return false;
|
|
984
|
+
}
|
|
985
|
+
if (schema.allOf || schema.oneOf || schema.anyOf) {
|
|
986
|
+
return false;
|
|
987
|
+
}
|
|
988
|
+
return false;
|
|
989
|
+
}
|
|
963
990
|
createGenerationContext(operation) {
|
|
964
991
|
var _a, _b;
|
|
965
992
|
return {
|
|
@@ -1375,20 +1402,51 @@ var _ServiceMethodOverloadsGenerator = class _ServiceMethodOverloadsGenerator {
|
|
|
1375
1402
|
});
|
|
1376
1403
|
continue;
|
|
1377
1404
|
}
|
|
1405
|
+
const isPrimitive = this.isPrimitiveType(schema);
|
|
1378
1406
|
const inferredType = this.inferResponseTypeFromContentType(contentType);
|
|
1379
1407
|
let priority = 3;
|
|
1380
|
-
|
|
1408
|
+
let finalType = inferredType;
|
|
1409
|
+
if (inferredType === "json" && isPrimitive) {
|
|
1410
|
+
finalType = "text";
|
|
1411
|
+
priority = 2;
|
|
1412
|
+
} else if (inferredType === "json") {
|
|
1381
1413
|
priority = 2;
|
|
1382
1414
|
}
|
|
1383
1415
|
responseTypes.push({
|
|
1384
|
-
type:
|
|
1416
|
+
type: finalType,
|
|
1385
1417
|
priority,
|
|
1386
|
-
contentType
|
|
1418
|
+
contentType,
|
|
1419
|
+
isPrimitive
|
|
1387
1420
|
});
|
|
1388
1421
|
}
|
|
1389
1422
|
responseTypes.sort((a, b) => a.priority - b.priority);
|
|
1390
1423
|
return ((_c = responseTypes[0]) == null ? void 0 : _c.type) || "json";
|
|
1391
1424
|
}
|
|
1425
|
+
isPrimitiveType(schema) {
|
|
1426
|
+
if (!schema) return false;
|
|
1427
|
+
const primitiveTypes = [
|
|
1428
|
+
"string",
|
|
1429
|
+
"number",
|
|
1430
|
+
"integer",
|
|
1431
|
+
"boolean"
|
|
1432
|
+
];
|
|
1433
|
+
if (primitiveTypes.includes(schema.type)) {
|
|
1434
|
+
return true;
|
|
1435
|
+
}
|
|
1436
|
+
if (schema.type === "array") {
|
|
1437
|
+
return false;
|
|
1438
|
+
}
|
|
1439
|
+
if (schema.type === "object" || schema.properties) {
|
|
1440
|
+
return false;
|
|
1441
|
+
}
|
|
1442
|
+
if (schema.$ref) {
|
|
1443
|
+
return false;
|
|
1444
|
+
}
|
|
1445
|
+
if (schema.allOf || schema.oneOf || schema.anyOf) {
|
|
1446
|
+
return false;
|
|
1447
|
+
}
|
|
1448
|
+
return false;
|
|
1449
|
+
}
|
|
1392
1450
|
getResponseType(response) {
|
|
1393
1451
|
const responseType = this.getResponseTypeFromResponse(response);
|
|
1394
1452
|
switch (responseType) {
|
|
@@ -1604,7 +1662,7 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
1604
1662
|
return groups;
|
|
1605
1663
|
}
|
|
1606
1664
|
generateServiceFile(controllerName, operations, outputDir) {
|
|
1607
|
-
const fileName = `${
|
|
1665
|
+
const fileName = `${camelCase(controllerName)}.service.ts`;
|
|
1608
1666
|
const filePath = path5.join(outputDir, fileName);
|
|
1609
1667
|
const sourceFile = this.project.createSourceFile(filePath, "", {
|
|
1610
1668
|
overwrite: true
|