ng-openapi 0.0.25-alpha.2 → 0.0.25-alpha.4

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.
Files changed (4) hide show
  1. package/cli.cjs +34 -16
  2. package/index.d.ts +1 -1
  3. package/index.js +34 -16
  4. package/package.json +1 -1
package/cli.cjs CHANGED
@@ -419,11 +419,16 @@ var TokenGenerator = class {
419
419
  });
420
420
  sourceFile.addImportDeclaration({
421
421
  namedImports: [
422
- "InjectionToken",
423
- "HttpInterceptor"
422
+ "InjectionToken"
424
423
  ],
425
424
  moduleSpecifier: "@angular/core"
426
425
  });
426
+ sourceFile.addImportDeclaration({
427
+ namedImports: [
428
+ "HttpInterceptor"
429
+ ],
430
+ moduleSpecifier: "@angular/common/http"
431
+ });
427
432
  const basePathTokenName = this.getBasePathTokenName();
428
433
  const interceptorsTokenName = this.getInterceptorsTokenName();
429
434
  sourceFile.addVariableStatement({
@@ -456,7 +461,7 @@ var TokenGenerator = class {
456
461
  }
457
462
  ],
458
463
  leadingTrivia: `/**
459
- * Injection token for the ${this.clientName} client HTTP interceptors
464
+ * Injection token for the ${this.clientName} client HTTP interceptor instances
460
465
  */
461
466
  `
462
467
  });
@@ -892,10 +897,10 @@ var ProviderGenerator = class {
892
897
  },
893
898
  {
894
899
  name: "interceptors",
895
- type: "HttpInterceptor[]",
900
+ type: "(new (...args: HttpInterceptor[]) => HttpInterceptor)[]",
896
901
  hasQuestionToken: true,
897
902
  docs: [
898
- "Array of HTTP interceptors to apply to this client"
903
+ "Array of HTTP interceptor classes to apply to this client"
899
904
  ]
900
905
  }
901
906
  ]
@@ -914,11 +919,6 @@ const providers: Provider[] = [
914
919
  provide: ${basePathTokenName},
915
920
  useValue: config.basePath
916
921
  },
917
- // Client-specific interceptors token
918
- {
919
- provide: ${interceptorsTokenName},
920
- useValue: config.interceptors || []
921
- },
922
922
  // Base interceptor that handles client-specific interceptors
923
923
  {
924
924
  provide: HTTP_INTERCEPTORS,
@@ -927,14 +927,32 @@ const providers: Provider[] = [
927
927
  }
928
928
  ];
929
929
 
930
- ${hasDateInterceptor ? `// Add date interceptor to client-specific interceptors if enabled
931
- if (config.enableDateTransform !== false) {
932
- const currentInterceptors = config.interceptors || [];
930
+ // Add client-specific interceptor instances
931
+ if (config.interceptors && config.interceptors.length > 0) {
932
+ const interceptorInstances = config.interceptors.map(InterceptorClass => new InterceptorClass());
933
+
934
+ ${hasDateInterceptor ? `// Add date interceptor if enabled (default: true)
935
+ if (config.enableDateTransform !== false) {
936
+ interceptorInstances.unshift(new DateInterceptor());
937
+ }` : `// Date transformation not available (dateType: 'string' was used in generation)`}
938
+
939
+ providers.push({
940
+ provide: ${interceptorsTokenName},
941
+ useValue: interceptorInstances
942
+ });
943
+ } ${hasDateInterceptor ? `else if (config.enableDateTransform !== false) {
944
+ // Only date interceptor enabled
933
945
  providers.push({
934
946
  provide: ${interceptorsTokenName},
935
- useValue: [new DateInterceptor(), ...currentInterceptors]
947
+ useValue: [new DateInterceptor()]
936
948
  });
937
- }` : `// Date transformation not available (dateType: 'string' was used in generation)`}
949
+ }` : ``} else {
950
+ // No interceptors
951
+ providers.push({
952
+ provide: ${interceptorsTokenName},
953
+ useValue: []
954
+ });
955
+ }
938
956
 
939
957
  return makeEnvironmentProviders(providers);`;
940
958
  sourceFile.addFunction({
@@ -952,7 +970,7 @@ return makeEnvironmentProviders(providers);`;
952
970
  " providers: [",
953
971
  ` ${functionName}({`,
954
972
  " basePath: 'https://api.example.com',",
955
- " interceptors: [new LoggingInterceptor(), new AuthInterceptor()]",
973
+ " interceptors: [AuthInterceptor, LoggingInterceptor] // Classes, not instances",
956
974
  " }),",
957
975
  " // other providers...",
958
976
  " ]",
package/index.d.ts CHANGED
@@ -52,7 +52,7 @@ interface NgOpenapiClientConfig {
52
52
  clientName: string;
53
53
  basePath: string;
54
54
  enableDateTransform?: boolean;
55
- interceptors?: HttpInterceptor[];
55
+ interceptors?: (new (...args: HttpInterceptor[]) => HttpInterceptor)[];
56
56
  }
57
57
 
58
58
  interface Parameter {
package/index.js CHANGED
@@ -466,11 +466,16 @@ var _TokenGenerator = class _TokenGenerator {
466
466
  });
467
467
  sourceFile.addImportDeclaration({
468
468
  namedImports: [
469
- "InjectionToken",
470
- "HttpInterceptor"
469
+ "InjectionToken"
471
470
  ],
472
471
  moduleSpecifier: "@angular/core"
473
472
  });
473
+ sourceFile.addImportDeclaration({
474
+ namedImports: [
475
+ "HttpInterceptor"
476
+ ],
477
+ moduleSpecifier: "@angular/common/http"
478
+ });
474
479
  const basePathTokenName = this.getBasePathTokenName();
475
480
  const interceptorsTokenName = this.getInterceptorsTokenName();
476
481
  sourceFile.addVariableStatement({
@@ -503,7 +508,7 @@ var _TokenGenerator = class _TokenGenerator {
503
508
  }
504
509
  ],
505
510
  leadingTrivia: `/**
506
- * Injection token for the ${this.clientName} client HTTP interceptors
511
+ * Injection token for the ${this.clientName} client HTTP interceptor instances
507
512
  */
508
513
  `
509
514
  });
@@ -935,10 +940,10 @@ var _ProviderGenerator = class _ProviderGenerator {
935
940
  },
936
941
  {
937
942
  name: "interceptors",
938
- type: "HttpInterceptor[]",
943
+ type: "(new (...args: HttpInterceptor[]) => HttpInterceptor)[]",
939
944
  hasQuestionToken: true,
940
945
  docs: [
941
- "Array of HTTP interceptors to apply to this client"
946
+ "Array of HTTP interceptor classes to apply to this client"
942
947
  ]
943
948
  }
944
949
  ]
@@ -957,11 +962,6 @@ const providers: Provider[] = [
957
962
  provide: ${basePathTokenName},
958
963
  useValue: config.basePath
959
964
  },
960
- // Client-specific interceptors token
961
- {
962
- provide: ${interceptorsTokenName},
963
- useValue: config.interceptors || []
964
- },
965
965
  // Base interceptor that handles client-specific interceptors
966
966
  {
967
967
  provide: HTTP_INTERCEPTORS,
@@ -970,14 +970,32 @@ const providers: Provider[] = [
970
970
  }
971
971
  ];
972
972
 
973
- ${hasDateInterceptor ? `// Add date interceptor to client-specific interceptors if enabled
974
- if (config.enableDateTransform !== false) {
975
- const currentInterceptors = config.interceptors || [];
973
+ // Add client-specific interceptor instances
974
+ if (config.interceptors && config.interceptors.length > 0) {
975
+ const interceptorInstances = config.interceptors.map(InterceptorClass => new InterceptorClass());
976
+
977
+ ${hasDateInterceptor ? `// Add date interceptor if enabled (default: true)
978
+ if (config.enableDateTransform !== false) {
979
+ interceptorInstances.unshift(new DateInterceptor());
980
+ }` : `// Date transformation not available (dateType: 'string' was used in generation)`}
981
+
982
+ providers.push({
983
+ provide: ${interceptorsTokenName},
984
+ useValue: interceptorInstances
985
+ });
986
+ } ${hasDateInterceptor ? `else if (config.enableDateTransform !== false) {
987
+ // Only date interceptor enabled
976
988
  providers.push({
977
989
  provide: ${interceptorsTokenName},
978
- useValue: [new DateInterceptor(), ...currentInterceptors]
990
+ useValue: [new DateInterceptor()]
979
991
  });
980
- }` : `// Date transformation not available (dateType: 'string' was used in generation)`}
992
+ }` : ``} else {
993
+ // No interceptors
994
+ providers.push({
995
+ provide: ${interceptorsTokenName},
996
+ useValue: []
997
+ });
998
+ }
981
999
 
982
1000
  return makeEnvironmentProviders(providers);`;
983
1001
  sourceFile.addFunction({
@@ -995,7 +1013,7 @@ return makeEnvironmentProviders(providers);`;
995
1013
  " providers: [",
996
1014
  ` ${functionName}({`,
997
1015
  " basePath: 'https://api.example.com',",
998
- " interceptors: [new LoggingInterceptor(), new AuthInterceptor()]",
1016
+ " interceptors: [AuthInterceptor, LoggingInterceptor] // Classes, not instances",
999
1017
  " }),",
1000
1018
  " // other providers...",
1001
1019
  " ]",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ng-openapi",
3
- "version": "0.0.25-alpha.2",
3
+ "version": "0.0.25-alpha.4",
4
4
  "description": "Generate Angular services and TypeScript types from OpenAPI/Swagger specifications",
5
5
  "keywords": [
6
6
  "angular",