ng-openapi 0.0.23 → 0.0.24-rc.0

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 (3) hide show
  1. package/cli.cjs +45 -47
  2. package/index.js +44 -46
  3. package/package.json +1 -1
package/cli.cjs CHANGED
@@ -1895,7 +1895,7 @@ var ProviderGenerator = class {
1895
1895
  "makeEnvironmentProviders",
1896
1896
  "Type",
1897
1897
  "Injector",
1898
- "inject"
1898
+ "InjectionToken"
1899
1899
  ],
1900
1900
  moduleSpecifier: "@angular/core"
1901
1901
  },
@@ -1904,7 +1904,8 @@ var ProviderGenerator = class {
1904
1904
  "HttpClient",
1905
1905
  "HttpInterceptor",
1906
1906
  "HttpHandler",
1907
- "HttpRequest"
1907
+ "HttpBackend",
1908
+ "HTTP_INTERCEPTORS"
1908
1909
  ],
1909
1910
  moduleSpecifier: "@angular/common/http"
1910
1911
  },
@@ -1956,50 +1957,24 @@ var ProviderGenerator = class {
1956
1957
  }
1957
1958
  ]
1958
1959
  });
1959
- this.addInterceptorChainHelper(sourceFile);
1960
- this.addClientProviderFunction(sourceFile, pascalClientName, upperCaseClientName);
1961
- sourceFile.saveSync();
1962
- }
1963
- addInterceptorChainHelper(sourceFile) {
1964
- sourceFile.addFunction({
1965
- name: "createHttpClientWithInterceptors",
1966
- docs: [
1967
- "Creates an HttpClient with a custom interceptor chain"
1968
- ],
1969
- parameters: [
1970
- {
1971
- name: "baseClient",
1972
- type: "HttpClient"
1973
- },
1960
+ sourceFile.addVariableStatement({
1961
+ isExported: true,
1962
+ declarationKind: "const",
1963
+ declarations: [
1974
1964
  {
1975
- name: "interceptors",
1976
- type: "HttpInterceptor[]"
1965
+ name: `${upperCaseClientName}_INTERCEPTORS`,
1966
+ initializer: `new InjectionToken<HttpInterceptor[]>('${upperCaseClientName}_INTERCEPTORS')`
1977
1967
  }
1978
1968
  ],
1979
- returnType: "HttpClient",
1980
- statements: `
1981
- if (!interceptors.length) {
1982
- return baseClient;
1983
- }
1984
-
1985
- // Create a custom handler that applies interceptors in sequence
1986
- let handler = baseClient.handler;
1987
-
1988
- // Apply interceptors in reverse order (last interceptor wraps the original handler)
1989
- for (let i = interceptors.length - 1; i >= 0; i--) {
1990
- const currentHandler = handler;
1991
- const interceptor = interceptors[i];
1992
-
1993
- handler = {
1994
- handle: (req: HttpRequest<any>) => interceptor.intercept(req, currentHandler)
1995
- };
1996
- }
1997
-
1998
- // Return a new HttpClient with the custom handler
1999
- return new (baseClient.constructor as any)(handler);`
1969
+ leadingTrivia: `/**
1970
+ * Interceptor token for ${clientName} client
1971
+ */
1972
+ `
2000
1973
  });
1974
+ this.addSimpleProviderFunction(sourceFile, pascalClientName, upperCaseClientName);
1975
+ sourceFile.saveSync();
2001
1976
  }
2002
- addClientProviderFunction(sourceFile, pascalClientName, upperCaseClientName) {
1977
+ addSimpleProviderFunction(sourceFile, pascalClientName, upperCaseClientName) {
2003
1978
  const hasDateInterceptor = this.config.options.dateType === "Date";
2004
1979
  const functionBody = `
2005
1980
  const providers: Provider[] = [
@@ -2009,10 +1984,10 @@ const providers: Provider[] = [
2009
1984
  useValue: config.basePath
2010
1985
  },
2011
1986
 
2012
- // HTTP client with custom interceptors
1987
+ // Collect interceptors for this client
2013
1988
  {
2014
- provide: ${upperCaseClientName}_HTTP_CLIENT,
2015
- useFactory: (baseClient: HttpClient, injector: Injector) => {
1989
+ provide: ${upperCaseClientName}_INTERCEPTORS,
1990
+ useFactory: (injector: Injector) => {
2016
1991
  const interceptorInstances: HttpInterceptor[] = [];
2017
1992
 
2018
1993
  // Add custom interceptors
@@ -2028,9 +2003,32 @@ const providers: Provider[] = [
2028
2003
  interceptorInstances.push(injector.get(DateInterceptor));
2029
2004
  }` : ""}
2030
2005
 
2031
- return createHttpClientWithInterceptors(baseClient, interceptorInstances);
2006
+ return interceptorInstances;
2007
+ },
2008
+ deps: [Injector]
2009
+ },
2010
+
2011
+ // Create HTTP client with interceptors
2012
+ {
2013
+ provide: ${upperCaseClientName}_HTTP_CLIENT,
2014
+ useFactory: (backend: HttpBackend, interceptors: HttpInterceptor[]) => {
2015
+ if (!interceptors.length) {
2016
+ return new HttpClient(backend);
2017
+ }
2018
+
2019
+ // Create handler chain
2020
+ let handler = backend;
2021
+ for (let i = interceptors.length - 1; i >= 0; i--) {
2022
+ const interceptor = interceptors[i];
2023
+ const currentHandler = handler;
2024
+ handler = {
2025
+ handle: req => interceptor.intercept(req, currentHandler)
2026
+ };
2027
+ }
2028
+
2029
+ return new HttpClient(handler);
2032
2030
  },
2033
- deps: [HttpClient, Injector]
2031
+ deps: [HttpBackend, ${upperCaseClientName}_INTERCEPTORS]
2034
2032
  }
2035
2033
  ];
2036
2034
 
@@ -2136,7 +2134,7 @@ __name(generateFromConfig, "generateFromConfig");
2136
2134
  // package.json
2137
2135
  var package_default = {
2138
2136
  name: "ng-openapi",
2139
- version: "0.0.22",
2137
+ version: "0.0.23",
2140
2138
  description: "Generate Angular services and TypeScript types from OpenAPI/Swagger specifications",
2141
2139
  keywords: [
2142
2140
  "angular",
package/index.js CHANGED
@@ -1928,7 +1928,7 @@ var _ProviderGenerator = class _ProviderGenerator {
1928
1928
  "makeEnvironmentProviders",
1929
1929
  "Type",
1930
1930
  "Injector",
1931
- "inject"
1931
+ "InjectionToken"
1932
1932
  ],
1933
1933
  moduleSpecifier: "@angular/core"
1934
1934
  },
@@ -1937,7 +1937,8 @@ var _ProviderGenerator = class _ProviderGenerator {
1937
1937
  "HttpClient",
1938
1938
  "HttpInterceptor",
1939
1939
  "HttpHandler",
1940
- "HttpRequest"
1940
+ "HttpBackend",
1941
+ "HTTP_INTERCEPTORS"
1941
1942
  ],
1942
1943
  moduleSpecifier: "@angular/common/http"
1943
1944
  },
@@ -1989,50 +1990,24 @@ var _ProviderGenerator = class _ProviderGenerator {
1989
1990
  }
1990
1991
  ]
1991
1992
  });
1992
- this.addInterceptorChainHelper(sourceFile);
1993
- this.addClientProviderFunction(sourceFile, pascalClientName, upperCaseClientName);
1994
- sourceFile.saveSync();
1995
- }
1996
- addInterceptorChainHelper(sourceFile) {
1997
- sourceFile.addFunction({
1998
- name: "createHttpClientWithInterceptors",
1999
- docs: [
2000
- "Creates an HttpClient with a custom interceptor chain"
2001
- ],
2002
- parameters: [
2003
- {
2004
- name: "baseClient",
2005
- type: "HttpClient"
2006
- },
1993
+ sourceFile.addVariableStatement({
1994
+ isExported: true,
1995
+ declarationKind: "const",
1996
+ declarations: [
2007
1997
  {
2008
- name: "interceptors",
2009
- type: "HttpInterceptor[]"
1998
+ name: `${upperCaseClientName}_INTERCEPTORS`,
1999
+ initializer: `new InjectionToken<HttpInterceptor[]>('${upperCaseClientName}_INTERCEPTORS')`
2010
2000
  }
2011
2001
  ],
2012
- returnType: "HttpClient",
2013
- statements: `
2014
- if (!interceptors.length) {
2015
- return baseClient;
2016
- }
2017
-
2018
- // Create a custom handler that applies interceptors in sequence
2019
- let handler = baseClient.handler;
2020
-
2021
- // Apply interceptors in reverse order (last interceptor wraps the original handler)
2022
- for (let i = interceptors.length - 1; i >= 0; i--) {
2023
- const currentHandler = handler;
2024
- const interceptor = interceptors[i];
2025
-
2026
- handler = {
2027
- handle: (req: HttpRequest<any>) => interceptor.intercept(req, currentHandler)
2028
- };
2029
- }
2030
-
2031
- // Return a new HttpClient with the custom handler
2032
- return new (baseClient.constructor as any)(handler);`
2002
+ leadingTrivia: `/**
2003
+ * Interceptor token for ${clientName} client
2004
+ */
2005
+ `
2033
2006
  });
2007
+ this.addSimpleProviderFunction(sourceFile, pascalClientName, upperCaseClientName);
2008
+ sourceFile.saveSync();
2034
2009
  }
2035
- addClientProviderFunction(sourceFile, pascalClientName, upperCaseClientName) {
2010
+ addSimpleProviderFunction(sourceFile, pascalClientName, upperCaseClientName) {
2036
2011
  const hasDateInterceptor = this.config.options.dateType === "Date";
2037
2012
  const functionBody = `
2038
2013
  const providers: Provider[] = [
@@ -2042,10 +2017,10 @@ const providers: Provider[] = [
2042
2017
  useValue: config.basePath
2043
2018
  },
2044
2019
 
2045
- // HTTP client with custom interceptors
2020
+ // Collect interceptors for this client
2046
2021
  {
2047
- provide: ${upperCaseClientName}_HTTP_CLIENT,
2048
- useFactory: (baseClient: HttpClient, injector: Injector) => {
2022
+ provide: ${upperCaseClientName}_INTERCEPTORS,
2023
+ useFactory: (injector: Injector) => {
2049
2024
  const interceptorInstances: HttpInterceptor[] = [];
2050
2025
 
2051
2026
  // Add custom interceptors
@@ -2061,9 +2036,32 @@ const providers: Provider[] = [
2061
2036
  interceptorInstances.push(injector.get(DateInterceptor));
2062
2037
  }` : ""}
2063
2038
 
2064
- return createHttpClientWithInterceptors(baseClient, interceptorInstances);
2039
+ return interceptorInstances;
2040
+ },
2041
+ deps: [Injector]
2042
+ },
2043
+
2044
+ // Create HTTP client with interceptors
2045
+ {
2046
+ provide: ${upperCaseClientName}_HTTP_CLIENT,
2047
+ useFactory: (backend: HttpBackend, interceptors: HttpInterceptor[]) => {
2048
+ if (!interceptors.length) {
2049
+ return new HttpClient(backend);
2050
+ }
2051
+
2052
+ // Create handler chain
2053
+ let handler = backend;
2054
+ for (let i = interceptors.length - 1; i >= 0; i--) {
2055
+ const interceptor = interceptors[i];
2056
+ const currentHandler = handler;
2057
+ handler = {
2058
+ handle: req => interceptor.intercept(req, currentHandler)
2059
+ };
2060
+ }
2061
+
2062
+ return new HttpClient(handler);
2065
2063
  },
2066
- deps: [HttpClient, Injector]
2064
+ deps: [HttpBackend, ${upperCaseClientName}_INTERCEPTORS]
2067
2065
  }
2068
2066
  ];
2069
2067
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ng-openapi",
3
- "version": "0.0.23",
3
+ "version": "0.0.24-rc.0",
4
4
  "description": "Generate Angular services and TypeScript types from OpenAPI/Swagger specifications",
5
5
  "keywords": [
6
6
  "angular",