ng-openapi 0.0.25-alpha.0 → 0.0.25-alpha.2
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 +357 -220
- package/index.js +362 -216
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -7,6 +7,9 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __typeError = (msg) => {
|
|
11
|
+
throw TypeError(msg);
|
|
12
|
+
};
|
|
10
13
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
14
|
var __spreadValues = (a, b) => {
|
|
12
15
|
for (var prop in b || (b = {}))
|
|
@@ -42,6 +45,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
42
45
|
));
|
|
43
46
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
44
47
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
48
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
49
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
50
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
51
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
45
52
|
var __async = (__this, __arguments, generator) => {
|
|
46
53
|
return new Promise((resolve, reject) => {
|
|
47
54
|
var fulfilled = (value) => {
|
|
@@ -100,7 +107,7 @@ __name(_SwaggerParser, "SwaggerParser");
|
|
|
100
107
|
var SwaggerParser = _SwaggerParser;
|
|
101
108
|
|
|
102
109
|
// src/lib/core/generator.ts
|
|
103
|
-
var
|
|
110
|
+
var import_ts_morph5 = require("ts-morph");
|
|
104
111
|
|
|
105
112
|
// src/lib/generators/type/type.generator.ts
|
|
106
113
|
var import_ts_morph = require("ts-morph");
|
|
@@ -135,6 +142,10 @@ var PROVIDER_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated prov
|
|
|
135
142
|
* Do not edit this file manually
|
|
136
143
|
*/
|
|
137
144
|
`;
|
|
145
|
+
var BASE_INTERCEPTOR_HEADER_COMMENT = /* @__PURE__ */ __name((clientName) => defaultHeaderComment + `* Generated Base Interceptor for client ${clientName}
|
|
146
|
+
* Do not edit this file manually
|
|
147
|
+
*/
|
|
148
|
+
`, "BASE_INTERCEPTOR_HEADER_COMMENT");
|
|
138
149
|
|
|
139
150
|
// src/lib/generators/type/type.generator.ts
|
|
140
151
|
var _TypeGenerator = class _TypeGenerator {
|
|
@@ -842,9 +853,333 @@ var _MainIndexGenerator = class _MainIndexGenerator {
|
|
|
842
853
|
__name(_MainIndexGenerator, "MainIndexGenerator");
|
|
843
854
|
var MainIndexGenerator = _MainIndexGenerator;
|
|
844
855
|
|
|
845
|
-
// src/lib/generators/
|
|
846
|
-
var import_ts_morph3 = require("ts-morph");
|
|
856
|
+
// src/lib/generators/utility/provider.generator.ts
|
|
847
857
|
var path5 = __toESM(require("path"));
|
|
858
|
+
var _ProviderGenerator = class _ProviderGenerator {
|
|
859
|
+
constructor(project, config) {
|
|
860
|
+
__publicField(this, "project");
|
|
861
|
+
__publicField(this, "config");
|
|
862
|
+
__publicField(this, "clientName");
|
|
863
|
+
this.project = project;
|
|
864
|
+
this.config = config;
|
|
865
|
+
this.clientName = config.clientName || "default";
|
|
866
|
+
}
|
|
867
|
+
generate(outputDir) {
|
|
868
|
+
const filePath = path5.join(outputDir, "providers.ts");
|
|
869
|
+
const sourceFile = this.project.createSourceFile(filePath, "", {
|
|
870
|
+
overwrite: true
|
|
871
|
+
});
|
|
872
|
+
sourceFile.insertText(0, PROVIDER_GENERATOR_HEADER_COMMENT);
|
|
873
|
+
const basePathTokenName = this.getBasePathTokenName();
|
|
874
|
+
const interceptorsTokenName = this.getInterceptorsTokenName();
|
|
875
|
+
const baseInterceptorClassName = `${this.capitalizeFirst(this.clientName)}BaseInterceptor`;
|
|
876
|
+
sourceFile.addImportDeclarations([
|
|
877
|
+
{
|
|
878
|
+
namedImports: [
|
|
879
|
+
"EnvironmentProviders",
|
|
880
|
+
"Provider",
|
|
881
|
+
"makeEnvironmentProviders"
|
|
882
|
+
],
|
|
883
|
+
moduleSpecifier: "@angular/core"
|
|
884
|
+
},
|
|
885
|
+
{
|
|
886
|
+
namedImports: [
|
|
887
|
+
"HTTP_INTERCEPTORS",
|
|
888
|
+
"HttpInterceptor"
|
|
889
|
+
],
|
|
890
|
+
moduleSpecifier: "@angular/common/http"
|
|
891
|
+
},
|
|
892
|
+
{
|
|
893
|
+
namedImports: [
|
|
894
|
+
basePathTokenName,
|
|
895
|
+
interceptorsTokenName
|
|
896
|
+
],
|
|
897
|
+
moduleSpecifier: "./tokens"
|
|
898
|
+
},
|
|
899
|
+
{
|
|
900
|
+
namedImports: [
|
|
901
|
+
baseInterceptorClassName
|
|
902
|
+
],
|
|
903
|
+
moduleSpecifier: "./utils/base-interceptor"
|
|
904
|
+
}
|
|
905
|
+
]);
|
|
906
|
+
if (this.config.options.dateType === "Date") {
|
|
907
|
+
sourceFile.addImportDeclaration({
|
|
908
|
+
namedImports: [
|
|
909
|
+
"DateInterceptor"
|
|
910
|
+
],
|
|
911
|
+
moduleSpecifier: "./utils/date-transformer"
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
sourceFile.addInterface({
|
|
915
|
+
name: `${this.capitalizeFirst(this.clientName)}Config`,
|
|
916
|
+
isExported: true,
|
|
917
|
+
docs: [
|
|
918
|
+
`Configuration options for ${this.clientName} client`
|
|
919
|
+
],
|
|
920
|
+
properties: [
|
|
921
|
+
{
|
|
922
|
+
name: "basePath",
|
|
923
|
+
type: "string",
|
|
924
|
+
docs: [
|
|
925
|
+
"Base API URL"
|
|
926
|
+
]
|
|
927
|
+
},
|
|
928
|
+
{
|
|
929
|
+
name: "enableDateTransform",
|
|
930
|
+
type: "boolean",
|
|
931
|
+
hasQuestionToken: true,
|
|
932
|
+
docs: [
|
|
933
|
+
"Enable automatic date transformation (default: true)"
|
|
934
|
+
]
|
|
935
|
+
},
|
|
936
|
+
{
|
|
937
|
+
name: "interceptors",
|
|
938
|
+
type: "HttpInterceptor[]",
|
|
939
|
+
hasQuestionToken: true,
|
|
940
|
+
docs: [
|
|
941
|
+
"Array of HTTP interceptors to apply to this client"
|
|
942
|
+
]
|
|
943
|
+
}
|
|
944
|
+
]
|
|
945
|
+
});
|
|
946
|
+
this.addMainProviderFunction(sourceFile, basePathTokenName, interceptorsTokenName, baseInterceptorClassName);
|
|
947
|
+
sourceFile.saveSync();
|
|
948
|
+
}
|
|
949
|
+
addMainProviderFunction(sourceFile, basePathTokenName, interceptorsTokenName, baseInterceptorClassName) {
|
|
950
|
+
const hasDateInterceptor = this.config.options.dateType === "Date";
|
|
951
|
+
const functionName = `provide${this.capitalizeFirst(this.clientName)}Client`;
|
|
952
|
+
const configTypeName = `${this.capitalizeFirst(this.clientName)}Config`;
|
|
953
|
+
const functionBody = `
|
|
954
|
+
const providers: Provider[] = [
|
|
955
|
+
// Base path token for this client
|
|
956
|
+
{
|
|
957
|
+
provide: ${basePathTokenName},
|
|
958
|
+
useValue: config.basePath
|
|
959
|
+
},
|
|
960
|
+
// Client-specific interceptors token
|
|
961
|
+
{
|
|
962
|
+
provide: ${interceptorsTokenName},
|
|
963
|
+
useValue: config.interceptors || []
|
|
964
|
+
},
|
|
965
|
+
// Base interceptor that handles client-specific interceptors
|
|
966
|
+
{
|
|
967
|
+
provide: HTTP_INTERCEPTORS,
|
|
968
|
+
useClass: ${baseInterceptorClassName},
|
|
969
|
+
multi: true
|
|
970
|
+
}
|
|
971
|
+
];
|
|
972
|
+
|
|
973
|
+
${hasDateInterceptor ? `// Add date interceptor to client-specific interceptors if enabled
|
|
974
|
+
if (config.enableDateTransform !== false) {
|
|
975
|
+
const currentInterceptors = config.interceptors || [];
|
|
976
|
+
providers.push({
|
|
977
|
+
provide: ${interceptorsTokenName},
|
|
978
|
+
useValue: [new DateInterceptor(), ...currentInterceptors]
|
|
979
|
+
});
|
|
980
|
+
}` : `// Date transformation not available (dateType: 'string' was used in generation)`}
|
|
981
|
+
|
|
982
|
+
return makeEnvironmentProviders(providers);`;
|
|
983
|
+
sourceFile.addFunction({
|
|
984
|
+
name: functionName,
|
|
985
|
+
isExported: true,
|
|
986
|
+
docs: [
|
|
987
|
+
`Provides configuration for ${this.clientName} client`,
|
|
988
|
+
"",
|
|
989
|
+
"@example",
|
|
990
|
+
"```typescript",
|
|
991
|
+
"// In your app.config.ts",
|
|
992
|
+
`import { ${functionName} } from './api/providers';`,
|
|
993
|
+
"",
|
|
994
|
+
"export const appConfig: ApplicationConfig = {",
|
|
995
|
+
" providers: [",
|
|
996
|
+
` ${functionName}({`,
|
|
997
|
+
" basePath: 'https://api.example.com',",
|
|
998
|
+
" interceptors: [new LoggingInterceptor(), new AuthInterceptor()]",
|
|
999
|
+
" }),",
|
|
1000
|
+
" // other providers...",
|
|
1001
|
+
" ]",
|
|
1002
|
+
"};",
|
|
1003
|
+
"```"
|
|
1004
|
+
],
|
|
1005
|
+
parameters: [
|
|
1006
|
+
{
|
|
1007
|
+
name: "config",
|
|
1008
|
+
type: configTypeName
|
|
1009
|
+
}
|
|
1010
|
+
],
|
|
1011
|
+
returnType: "EnvironmentProviders",
|
|
1012
|
+
statements: functionBody
|
|
1013
|
+
});
|
|
1014
|
+
if (this.clientName === "default") {
|
|
1015
|
+
sourceFile.addFunction({
|
|
1016
|
+
name: "provideNgOpenapi",
|
|
1017
|
+
isExported: true,
|
|
1018
|
+
docs: [
|
|
1019
|
+
"@deprecated Use provideDefaultClient instead for better clarity",
|
|
1020
|
+
"Provides configuration for the default client"
|
|
1021
|
+
],
|
|
1022
|
+
parameters: [
|
|
1023
|
+
{
|
|
1024
|
+
name: "config",
|
|
1025
|
+
type: configTypeName
|
|
1026
|
+
}
|
|
1027
|
+
],
|
|
1028
|
+
returnType: "EnvironmentProviders",
|
|
1029
|
+
statements: `return ${functionName}(config);`
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
getBasePathTokenName() {
|
|
1034
|
+
const clientSuffix = this.clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
1035
|
+
return `BASE_PATH_${clientSuffix}`;
|
|
1036
|
+
}
|
|
1037
|
+
getInterceptorsTokenName() {
|
|
1038
|
+
const clientSuffix = this.clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
1039
|
+
return `HTTP_INTERCEPTORS_${clientSuffix}`;
|
|
1040
|
+
}
|
|
1041
|
+
capitalizeFirst(str) {
|
|
1042
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
__name(_ProviderGenerator, "ProviderGenerator");
|
|
1046
|
+
var ProviderGenerator = _ProviderGenerator;
|
|
1047
|
+
|
|
1048
|
+
// src/lib/generators/utility/base-interceptor.generator.ts
|
|
1049
|
+
var import_ts_morph3 = require("ts-morph");
|
|
1050
|
+
var path6 = __toESM(require("path"));
|
|
1051
|
+
var _project, _clientName;
|
|
1052
|
+
var _BaseInterceptorGenerator = class _BaseInterceptorGenerator {
|
|
1053
|
+
constructor(project, clientName = "default") {
|
|
1054
|
+
__privateAdd(this, _project);
|
|
1055
|
+
__privateAdd(this, _clientName);
|
|
1056
|
+
__privateSet(this, _project, project);
|
|
1057
|
+
__privateSet(this, _clientName, clientName);
|
|
1058
|
+
}
|
|
1059
|
+
generate(outputDir) {
|
|
1060
|
+
const utilsDir = path6.join(outputDir, "utils");
|
|
1061
|
+
const filePath = path6.join(utilsDir, "base-interceptor.ts");
|
|
1062
|
+
const sourceFile = __privateGet(this, _project).createSourceFile(filePath, "", {
|
|
1063
|
+
overwrite: true
|
|
1064
|
+
});
|
|
1065
|
+
sourceFile.insertText(0, BASE_INTERCEPTOR_HEADER_COMMENT(__privateGet(this, _clientName)));
|
|
1066
|
+
const basePathTokenName = this.getBasePathTokenName();
|
|
1067
|
+
const interceptorsTokenName = this.getInterceptorsTokenName();
|
|
1068
|
+
sourceFile.addImportDeclarations([
|
|
1069
|
+
{
|
|
1070
|
+
namedImports: [
|
|
1071
|
+
"HttpEvent",
|
|
1072
|
+
"HttpHandler",
|
|
1073
|
+
"HttpInterceptor",
|
|
1074
|
+
"HttpRequest"
|
|
1075
|
+
],
|
|
1076
|
+
moduleSpecifier: "@angular/common/http"
|
|
1077
|
+
},
|
|
1078
|
+
{
|
|
1079
|
+
namedImports: [
|
|
1080
|
+
"inject",
|
|
1081
|
+
"Injectable"
|
|
1082
|
+
],
|
|
1083
|
+
moduleSpecifier: "@angular/core"
|
|
1084
|
+
},
|
|
1085
|
+
{
|
|
1086
|
+
namedImports: [
|
|
1087
|
+
"Observable"
|
|
1088
|
+
],
|
|
1089
|
+
moduleSpecifier: "rxjs"
|
|
1090
|
+
},
|
|
1091
|
+
{
|
|
1092
|
+
namedImports: [
|
|
1093
|
+
basePathTokenName,
|
|
1094
|
+
interceptorsTokenName
|
|
1095
|
+
],
|
|
1096
|
+
moduleSpecifier: "../tokens"
|
|
1097
|
+
}
|
|
1098
|
+
]);
|
|
1099
|
+
sourceFile.addClass({
|
|
1100
|
+
name: `${this.capitalizeFirst(__privateGet(this, _clientName))}BaseInterceptor`,
|
|
1101
|
+
isExported: true,
|
|
1102
|
+
decorators: [
|
|
1103
|
+
{
|
|
1104
|
+
name: "Injectable",
|
|
1105
|
+
arguments: []
|
|
1106
|
+
}
|
|
1107
|
+
],
|
|
1108
|
+
implements: [
|
|
1109
|
+
"HttpInterceptor"
|
|
1110
|
+
],
|
|
1111
|
+
properties: [
|
|
1112
|
+
{
|
|
1113
|
+
name: "basePath",
|
|
1114
|
+
type: "string",
|
|
1115
|
+
scope: import_ts_morph3.Scope.Private,
|
|
1116
|
+
isReadonly: true,
|
|
1117
|
+
initializer: `inject(${basePathTokenName})`
|
|
1118
|
+
},
|
|
1119
|
+
{
|
|
1120
|
+
name: "httpInterceptors",
|
|
1121
|
+
type: "HttpInterceptor[]",
|
|
1122
|
+
scope: import_ts_morph3.Scope.Private,
|
|
1123
|
+
isReadonly: true,
|
|
1124
|
+
initializer: `inject(${interceptorsTokenName})`
|
|
1125
|
+
}
|
|
1126
|
+
],
|
|
1127
|
+
methods: [
|
|
1128
|
+
{
|
|
1129
|
+
name: "intercept",
|
|
1130
|
+
parameters: [
|
|
1131
|
+
{
|
|
1132
|
+
name: "req",
|
|
1133
|
+
type: "HttpRequest<any>"
|
|
1134
|
+
},
|
|
1135
|
+
{
|
|
1136
|
+
name: "next",
|
|
1137
|
+
type: "HttpHandler"
|
|
1138
|
+
}
|
|
1139
|
+
],
|
|
1140
|
+
returnType: "Observable<HttpEvent<any>>",
|
|
1141
|
+
statements: `
|
|
1142
|
+
// Only intercept requests to this client's base path
|
|
1143
|
+
if (!req.url.startsWith(this.basePath)) {
|
|
1144
|
+
return next.handle(req);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
// Apply client-specific interceptors in reverse order
|
|
1148
|
+
let handler = next;
|
|
1149
|
+
|
|
1150
|
+
handler = this.httpInterceptors.reduceRight(
|
|
1151
|
+
(next, interceptor) => ({
|
|
1152
|
+
handle: (request: HttpRequest<any>) => interceptor.intercept(request, next)
|
|
1153
|
+
}),
|
|
1154
|
+
handler
|
|
1155
|
+
);
|
|
1156
|
+
|
|
1157
|
+
return handler.handle(req);`
|
|
1158
|
+
}
|
|
1159
|
+
]
|
|
1160
|
+
});
|
|
1161
|
+
sourceFile.saveSync();
|
|
1162
|
+
}
|
|
1163
|
+
getBasePathTokenName() {
|
|
1164
|
+
const clientSuffix = __privateGet(this, _clientName).toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
1165
|
+
return `BASE_PATH_${clientSuffix}`;
|
|
1166
|
+
}
|
|
1167
|
+
getInterceptorsTokenName() {
|
|
1168
|
+
const clientSuffix = __privateGet(this, _clientName).toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
1169
|
+
return `HTTP_INTERCEPTORS_${clientSuffix}`;
|
|
1170
|
+
}
|
|
1171
|
+
capitalizeFirst(str) {
|
|
1172
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1173
|
+
}
|
|
1174
|
+
};
|
|
1175
|
+
_project = new WeakMap();
|
|
1176
|
+
_clientName = new WeakMap();
|
|
1177
|
+
__name(_BaseInterceptorGenerator, "BaseInterceptorGenerator");
|
|
1178
|
+
var BaseInterceptorGenerator = _BaseInterceptorGenerator;
|
|
1179
|
+
|
|
1180
|
+
// src/lib/generators/service/service.generator.ts
|
|
1181
|
+
var import_ts_morph4 = require("ts-morph");
|
|
1182
|
+
var path7 = __toESM(require("path"));
|
|
848
1183
|
|
|
849
1184
|
// src/lib/utils/string.utils.ts
|
|
850
1185
|
function camelCase(str) {
|
|
@@ -1640,7 +1975,7 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
1640
1975
|
this.methodGenerator = new ServiceMethodGenerator(config);
|
|
1641
1976
|
}
|
|
1642
1977
|
generate(outputRoot) {
|
|
1643
|
-
const outputDir =
|
|
1978
|
+
const outputDir = path7.join(outputRoot, "services");
|
|
1644
1979
|
const paths = this.extractPaths();
|
|
1645
1980
|
const controllerGroups = this.groupPathsByController(paths);
|
|
1646
1981
|
Object.entries(controllerGroups).forEach(([controllerName, operations]) => {
|
|
@@ -1650,7 +1985,7 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
1650
1985
|
extractPaths() {
|
|
1651
1986
|
const paths = [];
|
|
1652
1987
|
const swaggerPaths = this.spec.paths || {};
|
|
1653
|
-
Object.entries(swaggerPaths).forEach(([
|
|
1988
|
+
Object.entries(swaggerPaths).forEach(([path9, pathItem]) => {
|
|
1654
1989
|
const methods = [
|
|
1655
1990
|
"get",
|
|
1656
1991
|
"post",
|
|
@@ -1664,7 +1999,7 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
1664
1999
|
if (pathItem[method]) {
|
|
1665
2000
|
const operation = pathItem[method];
|
|
1666
2001
|
paths.push({
|
|
1667
|
-
path:
|
|
2002
|
+
path: path9,
|
|
1668
2003
|
method: method.toUpperCase(),
|
|
1669
2004
|
operationId: operation.operationId,
|
|
1670
2005
|
summary: operation.summary,
|
|
@@ -1696,12 +2031,12 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
1696
2031
|
}
|
|
1697
2032
|
groupPathsByController(paths) {
|
|
1698
2033
|
const groups = {};
|
|
1699
|
-
paths.forEach((
|
|
2034
|
+
paths.forEach((path9) => {
|
|
1700
2035
|
let controllerName = "Default";
|
|
1701
|
-
if (
|
|
1702
|
-
controllerName =
|
|
2036
|
+
if (path9.tags && path9.tags.length > 0) {
|
|
2037
|
+
controllerName = path9.tags[0];
|
|
1703
2038
|
} else {
|
|
1704
|
-
const pathParts =
|
|
2039
|
+
const pathParts = path9.path.split("/").filter((p) => p && !p.startsWith("{"));
|
|
1705
2040
|
if (pathParts.length > 1) {
|
|
1706
2041
|
controllerName = pascalCase(pathParts[1]);
|
|
1707
2042
|
}
|
|
@@ -1710,13 +2045,13 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
1710
2045
|
if (!groups[controllerName]) {
|
|
1711
2046
|
groups[controllerName] = [];
|
|
1712
2047
|
}
|
|
1713
|
-
groups[controllerName].push(
|
|
2048
|
+
groups[controllerName].push(path9);
|
|
1714
2049
|
});
|
|
1715
2050
|
return groups;
|
|
1716
2051
|
}
|
|
1717
2052
|
generateServiceFile(controllerName, operations, outputDir) {
|
|
1718
2053
|
const fileName = `${camelCase(controllerName)}.service.ts`;
|
|
1719
|
-
const filePath =
|
|
2054
|
+
const filePath = path7.join(outputDir, fileName);
|
|
1720
2055
|
const sourceFile = this.project.createSourceFile(filePath, "", {
|
|
1721
2056
|
overwrite: true
|
|
1722
2057
|
});
|
|
@@ -1851,14 +2186,14 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
1851
2186
|
serviceClass.addProperty({
|
|
1852
2187
|
name: "httpClient",
|
|
1853
2188
|
type: "HttpClient",
|
|
1854
|
-
scope:
|
|
2189
|
+
scope: import_ts_morph4.Scope.Private,
|
|
1855
2190
|
isReadonly: true,
|
|
1856
2191
|
initializer: "inject(HttpClient)"
|
|
1857
2192
|
});
|
|
1858
2193
|
serviceClass.addProperty({
|
|
1859
2194
|
name: "basePath",
|
|
1860
2195
|
type: "string",
|
|
1861
|
-
scope:
|
|
2196
|
+
scope: import_ts_morph4.Scope.Private,
|
|
1862
2197
|
isReadonly: true,
|
|
1863
2198
|
initializer: `inject(${basePathTokenName})`
|
|
1864
2199
|
});
|
|
@@ -1883,15 +2218,15 @@ var ServiceGenerator = _ServiceGenerator;
|
|
|
1883
2218
|
|
|
1884
2219
|
// src/lib/generators/service/service-index.generator.ts
|
|
1885
2220
|
var fs2 = __toESM(require("fs"));
|
|
1886
|
-
var
|
|
2221
|
+
var path8 = __toESM(require("path"));
|
|
1887
2222
|
var _ServiceIndexGenerator = class _ServiceIndexGenerator {
|
|
1888
2223
|
constructor(project) {
|
|
1889
2224
|
__publicField(this, "project");
|
|
1890
2225
|
this.project = project;
|
|
1891
2226
|
}
|
|
1892
2227
|
generateIndex(outputRoot) {
|
|
1893
|
-
const servicesDir =
|
|
1894
|
-
const indexPath =
|
|
2228
|
+
const servicesDir = path8.join(outputRoot, "services");
|
|
2229
|
+
const indexPath = path8.join(servicesDir, "index.ts");
|
|
1895
2230
|
const sourceFile = this.project.createSourceFile(indexPath, "", {
|
|
1896
2231
|
overwrite: true
|
|
1897
2232
|
});
|
|
@@ -1912,198 +2247,6 @@ var _ServiceIndexGenerator = class _ServiceIndexGenerator {
|
|
|
1912
2247
|
__name(_ServiceIndexGenerator, "ServiceIndexGenerator");
|
|
1913
2248
|
var ServiceIndexGenerator = _ServiceIndexGenerator;
|
|
1914
2249
|
|
|
1915
|
-
// src/lib/generators/utility/provider.generator.ts
|
|
1916
|
-
var path7 = __toESM(require("path"));
|
|
1917
|
-
var _ProviderGenerator = class _ProviderGenerator {
|
|
1918
|
-
constructor(project, config) {
|
|
1919
|
-
__publicField(this, "project");
|
|
1920
|
-
__publicField(this, "config");
|
|
1921
|
-
__publicField(this, "clientName");
|
|
1922
|
-
this.project = project;
|
|
1923
|
-
this.config = config;
|
|
1924
|
-
this.clientName = config.clientName || "default";
|
|
1925
|
-
}
|
|
1926
|
-
generate(outputDir) {
|
|
1927
|
-
const filePath = path7.join(outputDir, "providers.ts");
|
|
1928
|
-
const sourceFile = this.project.createSourceFile(filePath, "", {
|
|
1929
|
-
overwrite: true
|
|
1930
|
-
});
|
|
1931
|
-
sourceFile.insertText(0, PROVIDER_GENERATOR_HEADER_COMMENT);
|
|
1932
|
-
const basePathTokenName = this.getBasePathTokenName();
|
|
1933
|
-
const interceptorsTokenName = this.getInterceptorsTokenName();
|
|
1934
|
-
const baseInterceptorClassName = `${this.capitalizeFirst(this.clientName)}BaseInterceptor`;
|
|
1935
|
-
sourceFile.addImportDeclarations([
|
|
1936
|
-
{
|
|
1937
|
-
namedImports: [
|
|
1938
|
-
"EnvironmentProviders",
|
|
1939
|
-
"Provider",
|
|
1940
|
-
"makeEnvironmentProviders"
|
|
1941
|
-
],
|
|
1942
|
-
moduleSpecifier: "@angular/core"
|
|
1943
|
-
},
|
|
1944
|
-
{
|
|
1945
|
-
namedImports: [
|
|
1946
|
-
"HTTP_INTERCEPTORS",
|
|
1947
|
-
"HttpInterceptor"
|
|
1948
|
-
],
|
|
1949
|
-
moduleSpecifier: "@angular/common/http"
|
|
1950
|
-
},
|
|
1951
|
-
{
|
|
1952
|
-
namedImports: [
|
|
1953
|
-
basePathTokenName,
|
|
1954
|
-
interceptorsTokenName
|
|
1955
|
-
],
|
|
1956
|
-
moduleSpecifier: "./tokens"
|
|
1957
|
-
},
|
|
1958
|
-
{
|
|
1959
|
-
namedImports: [
|
|
1960
|
-
baseInterceptorClassName
|
|
1961
|
-
],
|
|
1962
|
-
moduleSpecifier: "./utils/base-interceptor"
|
|
1963
|
-
}
|
|
1964
|
-
]);
|
|
1965
|
-
if (this.config.options.dateType === "Date") {
|
|
1966
|
-
sourceFile.addImportDeclaration({
|
|
1967
|
-
namedImports: [
|
|
1968
|
-
"DateInterceptor"
|
|
1969
|
-
],
|
|
1970
|
-
moduleSpecifier: "./utils/date-transformer"
|
|
1971
|
-
});
|
|
1972
|
-
}
|
|
1973
|
-
sourceFile.addInterface({
|
|
1974
|
-
name: `${this.capitalizeFirst(this.clientName)}Config`,
|
|
1975
|
-
isExported: true,
|
|
1976
|
-
docs: [
|
|
1977
|
-
`Configuration options for ${this.clientName} client`
|
|
1978
|
-
],
|
|
1979
|
-
properties: [
|
|
1980
|
-
{
|
|
1981
|
-
name: "basePath",
|
|
1982
|
-
type: "string",
|
|
1983
|
-
docs: [
|
|
1984
|
-
"Base API URL"
|
|
1985
|
-
]
|
|
1986
|
-
},
|
|
1987
|
-
{
|
|
1988
|
-
name: "enableDateTransform",
|
|
1989
|
-
type: "boolean",
|
|
1990
|
-
hasQuestionToken: true,
|
|
1991
|
-
docs: [
|
|
1992
|
-
"Enable automatic date transformation (default: true)"
|
|
1993
|
-
]
|
|
1994
|
-
},
|
|
1995
|
-
{
|
|
1996
|
-
name: "interceptors",
|
|
1997
|
-
type: "HttpInterceptor[]",
|
|
1998
|
-
hasQuestionToken: true,
|
|
1999
|
-
docs: [
|
|
2000
|
-
"Array of HTTP interceptors to apply to this client"
|
|
2001
|
-
]
|
|
2002
|
-
}
|
|
2003
|
-
]
|
|
2004
|
-
});
|
|
2005
|
-
this.addMainProviderFunction(sourceFile, basePathTokenName, interceptorsTokenName, baseInterceptorClassName);
|
|
2006
|
-
sourceFile.saveSync();
|
|
2007
|
-
}
|
|
2008
|
-
addMainProviderFunction(sourceFile, basePathTokenName, interceptorsTokenName, baseInterceptorClassName) {
|
|
2009
|
-
const hasDateInterceptor = this.config.options.dateType === "Date";
|
|
2010
|
-
const functionName = `provide${this.capitalizeFirst(this.clientName)}Client`;
|
|
2011
|
-
const configTypeName = `${this.capitalizeFirst(this.clientName)}Config`;
|
|
2012
|
-
const functionBody = `
|
|
2013
|
-
const providers: Provider[] = [
|
|
2014
|
-
// Base path token for this client
|
|
2015
|
-
{
|
|
2016
|
-
provide: ${basePathTokenName},
|
|
2017
|
-
useValue: config.basePath
|
|
2018
|
-
},
|
|
2019
|
-
// Client-specific interceptors token
|
|
2020
|
-
{
|
|
2021
|
-
provide: ${interceptorsTokenName},
|
|
2022
|
-
useValue: config.interceptors || []
|
|
2023
|
-
},
|
|
2024
|
-
// Base interceptor that handles client-specific interceptors
|
|
2025
|
-
{
|
|
2026
|
-
provide: HTTP_INTERCEPTORS,
|
|
2027
|
-
useClass: ${baseInterceptorClassName},
|
|
2028
|
-
multi: true
|
|
2029
|
-
}
|
|
2030
|
-
];
|
|
2031
|
-
|
|
2032
|
-
${hasDateInterceptor ? `// Add date interceptor to client-specific interceptors if enabled
|
|
2033
|
-
if (config.enableDateTransform !== false) {
|
|
2034
|
-
const currentInterceptors = config.interceptors || [];
|
|
2035
|
-
providers.push({
|
|
2036
|
-
provide: ${interceptorsTokenName},
|
|
2037
|
-
useValue: [new DateInterceptor(), ...currentInterceptors]
|
|
2038
|
-
});
|
|
2039
|
-
}` : `// Date transformation not available (dateType: 'string' was used in generation)`}
|
|
2040
|
-
|
|
2041
|
-
return makeEnvironmentProviders(providers);`;
|
|
2042
|
-
sourceFile.addFunction({
|
|
2043
|
-
name: functionName,
|
|
2044
|
-
isExported: true,
|
|
2045
|
-
docs: [
|
|
2046
|
-
`Provides configuration for ${this.clientName} client`,
|
|
2047
|
-
"",
|
|
2048
|
-
"@example",
|
|
2049
|
-
"```typescript",
|
|
2050
|
-
"// In your app.config.ts",
|
|
2051
|
-
`import { ${functionName} } from './api/providers';`,
|
|
2052
|
-
"",
|
|
2053
|
-
"export const appConfig: ApplicationConfig = {",
|
|
2054
|
-
" providers: [",
|
|
2055
|
-
` ${functionName}({`,
|
|
2056
|
-
" basePath: 'https://api.example.com',",
|
|
2057
|
-
" interceptors: [new LoggingInterceptor(), new AuthInterceptor()]",
|
|
2058
|
-
" }),",
|
|
2059
|
-
" // other providers...",
|
|
2060
|
-
" ]",
|
|
2061
|
-
"};",
|
|
2062
|
-
"```"
|
|
2063
|
-
],
|
|
2064
|
-
parameters: [
|
|
2065
|
-
{
|
|
2066
|
-
name: "config",
|
|
2067
|
-
type: configTypeName
|
|
2068
|
-
}
|
|
2069
|
-
],
|
|
2070
|
-
returnType: "EnvironmentProviders",
|
|
2071
|
-
statements: functionBody
|
|
2072
|
-
});
|
|
2073
|
-
if (this.clientName === "default") {
|
|
2074
|
-
sourceFile.addFunction({
|
|
2075
|
-
name: "provideNgOpenapi",
|
|
2076
|
-
isExported: true,
|
|
2077
|
-
docs: [
|
|
2078
|
-
"@deprecated Use provideDefaultClient instead for better clarity",
|
|
2079
|
-
"Provides configuration for the default client"
|
|
2080
|
-
],
|
|
2081
|
-
parameters: [
|
|
2082
|
-
{
|
|
2083
|
-
name: "config",
|
|
2084
|
-
type: configTypeName
|
|
2085
|
-
}
|
|
2086
|
-
],
|
|
2087
|
-
returnType: "EnvironmentProviders",
|
|
2088
|
-
statements: `return ${functionName}(config);`
|
|
2089
|
-
});
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2092
|
-
getBasePathTokenName() {
|
|
2093
|
-
const clientSuffix = this.clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
2094
|
-
return `BASE_PATH_${clientSuffix}`;
|
|
2095
|
-
}
|
|
2096
|
-
getInterceptorsTokenName() {
|
|
2097
|
-
const clientSuffix = this.clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
2098
|
-
return `HTTP_INTERCEPTORS_${clientSuffix}`;
|
|
2099
|
-
}
|
|
2100
|
-
capitalizeFirst(str) {
|
|
2101
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
2102
|
-
}
|
|
2103
|
-
};
|
|
2104
|
-
__name(_ProviderGenerator, "ProviderGenerator");
|
|
2105
|
-
var ProviderGenerator = _ProviderGenerator;
|
|
2106
|
-
|
|
2107
2250
|
// src/lib/core/generator.ts
|
|
2108
2251
|
var fs3 = __toESM(require("fs"));
|
|
2109
2252
|
function generateFromConfig(config) {
|
|
@@ -2120,11 +2263,11 @@ function generateFromConfig(config) {
|
|
|
2120
2263
|
});
|
|
2121
2264
|
}
|
|
2122
2265
|
try {
|
|
2123
|
-
const project = new
|
|
2266
|
+
const project = new import_ts_morph5.Project({
|
|
2124
2267
|
compilerOptions: __spreadValues({
|
|
2125
2268
|
declaration: true,
|
|
2126
|
-
target:
|
|
2127
|
-
module:
|
|
2269
|
+
target: import_ts_morph5.ScriptTarget.ES2022,
|
|
2270
|
+
module: import_ts_morph5.ModuleKind.Preserve,
|
|
2128
2271
|
strict: true
|
|
2129
2272
|
}, config.compilerOptions)
|
|
2130
2273
|
});
|
|
@@ -2137,11 +2280,9 @@ function generateFromConfig(config) {
|
|
|
2137
2280
|
if (config.options.dateType === "Date") {
|
|
2138
2281
|
const dateTransformer = new DateTransformerGenerator(project);
|
|
2139
2282
|
dateTransformer.generate(outputPath);
|
|
2140
|
-
console.log(`\u2705 Date transformer generated`);
|
|
2141
2283
|
}
|
|
2142
2284
|
const fileDownloadHelper = new FileDownloadGenerator(project);
|
|
2143
2285
|
fileDownloadHelper.generate(outputPath);
|
|
2144
|
-
console.log(`\u2705 File download helper generated`);
|
|
2145
2286
|
const serviceGenerator = new ServiceGenerator(config.input, project, config);
|
|
2146
2287
|
serviceGenerator.generate(outputPath);
|
|
2147
2288
|
const indexGenerator = new ServiceIndexGenerator(project);
|
|
@@ -2149,11 +2290,16 @@ function generateFromConfig(config) {
|
|
|
2149
2290
|
console.log(`\u2705 Angular services generated`);
|
|
2150
2291
|
const providerGenerator = new ProviderGenerator(project, config);
|
|
2151
2292
|
providerGenerator.generate(outputPath);
|
|
2152
|
-
|
|
2293
|
+
const baseInterceptorGenerator = new BaseInterceptorGenerator(project, config.clientName);
|
|
2294
|
+
baseInterceptorGenerator.generate(outputPath);
|
|
2153
2295
|
}
|
|
2154
2296
|
const mainIndexGenerator = new MainIndexGenerator(project, config);
|
|
2155
2297
|
mainIndexGenerator.generateMainIndex(outputPath);
|
|
2156
|
-
|
|
2298
|
+
if (config.clientName) {
|
|
2299
|
+
console.log(`\u{1F389} ${config.clientName} Generation completed successfully at: ${outputPath}`);
|
|
2300
|
+
} else {
|
|
2301
|
+
console.log("\u{1F389} Generation completed successfully at:", outputPath);
|
|
2302
|
+
}
|
|
2157
2303
|
} catch (error) {
|
|
2158
2304
|
if (error instanceof Error) {
|
|
2159
2305
|
console.error("\u274C Error during generation:", error.message);
|