@@ -12,16 +12,16 @@ import { BaseServerConfiguration, server1 } from "./servers{{importFileExtension
1212import { configureAuthMethods, AuthMethods, AuthMethodsConfiguration } from "./auth/auth{ {importFileExtension} }";
1313
1414export interface Configuration<M = Middleware > {
15- readonly baseServer: BaseServerConfiguration;
16- readonly httpApi: HttpLibrary;
17- readonly middleware: M[];
18- readonly authMethods: AuthMethods;
15+ readonly baseServer: BaseServerConfiguration;
16+ readonly httpApi: HttpLibrary;
17+ readonly middleware: M[];
18+ readonly authMethods: AuthMethods;
1919}
2020
2121// Additional option specific to middleware merge strategy
2222export interface MiddlewareMergeOptions {
23- // default is `' replace' ` for backwards compatibility
24- middlewareMergeStrategy?: ' replace' | ' append' | ' prepend' ;
23+ // default is `" replace" ` for backwards compatibility
24+ middlewareMergeStrategy?: " replace" | " append" | " prepend" ;
2525}
2626
2727// Unify configuration options using Partial plus extra merge strategy
@@ -36,44 +36,44 @@ export type PromiseConfigurationOptions = ConfigurationOptions<PromiseMiddleware
3636 */
3737export interface ConfigurationParameters {
3838 /**
39- * Default server to use - a list of available servers (according to the
39+ * Default server to use - a list of available servers (according to the
4040 * OpenAPI yaml definition) is included in the `servers` const in `./servers`. You can also
41- * create your own server with the `ServerConfiguration` class from the same
41+ * create your own server with the `ServerConfiguration` class from the same
4242 * file.
4343 */
4444 baseServer?: BaseServerConfiguration;
4545 /**
46- * HTTP library to use e.g. IsomorphicFetch. This can usually be skipped as
46+ * HTTP library to use e.g. IsomorphicFetch. This can usually be skipped as
4747 * all generators come with a default library.
4848 * If available, additional libraries can be imported from `./http/*`
4949 */
5050 httpApi?: HttpLibrary;
5151
5252 /**
53- * The middlewares which will be applied to requests and responses. You can
54- * add any number of middleware components to modify requests before they
53+ * The middlewares which will be applied to requests and responses. You can
54+ * add any number of middleware components to modify requests before they
5555 * are sent or before they are deserialized by implementing the `Middleware`
5656 * interface defined in `./middleware`
5757 */
5858 middleware?: Middleware[];
5959 /**
60- * Configures middleware functions that return promises instead of
61- * Observables (which are used by `middleware`). Otherwise allows for the
62- * same functionality as `middleware`, i.e., modifying requests before they
60+ * Configures middleware functions that return promises instead of
61+ * Observables (which are used by `middleware`). Otherwise allows for the
62+ * same functionality as `middleware`, i.e., modifying requests before they
6363 * are sent and before they are deserialized.
6464 */
6565 promiseMiddleware?: PromiseMiddleware[];
6666 /**
67- * Configuration for the available authentication methods (e.g., api keys)
68- * according to the OpenAPI yaml definition. For the definition, please refer to
67+ * Configuration for the available authentication methods (e.g., api keys)
68+ * according to the OpenAPI yaml definition. For the definition, please refer to
6969 * `./auth/auth`
7070 */
7171 authMethods?: AuthMethodsConfiguration
7272}
7373
7474/**
7575 * Provide your `ConfigurationParameters` to this function to get a `Configuration`
76- * object that can be used to configure your APIs (in the constructor or
76+ * object that can be used to configure your APIs (in the constructor or
7777 * for each request individually).
7878 *
7979 * If a property is not included in conf, a default is used:
@@ -106,38 +106,38 @@ export function createConfiguration(conf: ConfigurationParameters = {}): Configu
106106export function mergeConfiguration(_config: Configuration, _options?: Configuration{ {^useInversify} }Options{ {/useInversify} }): Configuration {
107107 let allMiddleware: Middleware[] = [];
108108 {{#useInversify} }
109- if (_options){
110- _config = _options;
109+ if (_options) {
110+ _config = _options;
111111 }
112112 allMiddleware = _config?.middleware;
113113 { {/useInversify} }
114114 { {^useInversify} }
115- if (_options && _options.middleware){
116- const middlewareMergeStrategy = _options.middlewareMergeStrategy || ' replace' // default to replace behavior
117- // call-time middleware provided
118- const calltimeMiddleware: Middleware[] = _options.middleware;
115+ if (_options && _options.middleware) {
116+ const middlewareMergeStrategy = _options.middlewareMergeStrategy || " replace" // default to replace behavior
117+ // call-time middleware provided
118+ const calltimeMiddleware: Middleware[] = _options.middleware;
119119
120- switch (middlewareMergeStrategy){
121- case ' append' :
122- allMiddleware = _config.middleware.concat(calltimeMiddleware);
123- break ;
124- case ' prepend' :
125- allMiddleware = calltimeMiddleware.concat(_config.middleware)
126- break ;
127- case ' replace' :
128- allMiddleware = calltimeMiddleware
129- break ;
130- default :
131- throw new Error(`unrecognized middleware merge strategy ' ${middlewareMergeStrategy}' `)
132- }
120+ switch (middlewareMergeStrategy) {
121+ case " append" :
122+ allMiddleware = _config.middleware.concat(calltimeMiddleware);
123+ break ;
124+ case " prepend" :
125+ allMiddleware = calltimeMiddleware.concat(_config.middleware)
126+ break ;
127+ case " replace" :
128+ allMiddleware = calltimeMiddleware
129+ break ;
130+ default :
131+ throw new Error(`unrecognized middleware merge strategy ' ${middlewareMergeStrategy}' `);
132+ }
133133 }
134- if (_options){
135- _config = {
136- baseServer: _options.baseServer || _config.baseServer,
137- httpApi: _options.httpApi || _config.httpApi,
138- authMethods: _options.authMethods || _config.authMethods,
139- middleware: allMiddleware || _config.middleware
140- } ;
134+ if (_options) {
135+ _config = {
136+ baseServer: _options.baseServer || _config.baseServer,
137+ httpApi: _options.httpApi || _config.httpApi,
138+ authMethods: _options.authMethods || _config.authMethods,
139+ middleware: allMiddleware || _config.middleware
140+ } ;
141141 }
142142 { {/useInversify} }
143143 return _config;
@@ -147,16 +147,16 @@ export function mergeConfiguration(_config: Configuration, _options?: Configurat
147147 * Convert Promise-based configuration options to Observable-based configuration options.
148148 */
149149export function wrapOptions(_options?: PromiseConfigurationOptions): StandardConfigurationOptions | undefined {
150- if (_options){
151- return {
152- baseServer: _options.baseServer,
153- httpApi: _options.httpApi,
154- middleware: _options.middleware?.map(
155- m => new PromiseMiddlewareWrapper(m)
156- ),
157- middlewareMergeStrategy: _options.middlewareMergeStrategy,
158- authMethods: _options.authMethods
159- }
160- }
161- return;
150+ if (_options) {
151+ return {
152+ baseServer: _options.baseServer,
153+ httpApi: _options.httpApi,
154+ middleware: _options.middleware?.map(
155+ m => new PromiseMiddlewareWrapper(m)
156+ ),
157+ middlewareMergeStrategy: _options.middlewareMergeStrategy,
158+ authMethods: _options.authMethods,
159+ }
160+ }
161+ return;
162162}
0 commit comments