From e3189d414f6e0135eae4f85eb2268aea705cea20 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 4 Apr 2018 22:14:00 +1200 Subject: [PATCH 1/6] Added in injected basePath observable to api service to allow it to respond to external updates to this setting post construction. Added in injected basePath observable to api service to allow it to respond to external updates to this setting post construction. --- .../typescript-angular/api.service.mustache | 10 ++++++++-- .../typescript-angular/variables.mustache | 2 ++ .../default/api/pet.service.ts | 10 ++++++++-- .../default/api/store.service.ts | 10 ++++++++-- .../default/api/user.service.ts | 14 ++++++++++---- .../typescript-angular-v2/default/variables.ts | 2 ++ .../typescript-angular-v2/npm/api/pet.service.ts | 10 ++++++++-- .../typescript-angular-v2/npm/api/store.service.ts | 10 ++++++++-- .../typescript-angular-v2/npm/api/user.service.ts | 14 ++++++++++---- .../typescript-angular-v2/npm/variables.ts | 2 ++ .../with-interfaces/api/pet.service.ts | 10 ++++++++-- .../with-interfaces/api/store.service.ts | 10 ++++++++-- .../with-interfaces/api/user.service.ts | 14 ++++++++++---- .../with-interfaces/variables.ts | 2 ++ .../typescript-angular-v4.3/npm/api/pet.service.ts | 10 ++++++++-- .../npm/api/store.service.ts | 10 ++++++++-- .../npm/api/user.service.ts | 12 +++++++++--- .../typescript-angular-v4.3/npm/variables.ts | 2 ++ .../typescript-angular-v4/npm/api/pet.service.ts | 10 ++++++++-- .../typescript-angular-v4/npm/api/store.service.ts | 10 ++++++++-- .../typescript-angular-v4/npm/api/user.service.ts | 14 ++++++++++---- .../typescript-angular-v4/npm/variables.ts | 2 ++ 22 files changed, 149 insertions(+), 41 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache index c8c8df6c0d6..8980c0497c5 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache @@ -23,7 +23,7 @@ import '../rxjs-operators'; import { {{classname}} } from '../{{filename}}'; {{/imports}} -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; {{#withInterfaces}} import { {{classname}}Interface } from './{{classname}}Interface'; @@ -48,7 +48,10 @@ export class {{classname}} { public defaultHeaders = new {{#useHttpClient}}Http{{/useHttpClient}}Headers(); public configuration = new Configuration(); - constructor(protected {{#useHttpClient}}httpClient: HttpClient{{/useHttpClient}}{{^useHttpClient}}http: Http{{/useHttpClient}}, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected {{#useHttpClient}}httpClient: HttpClient{{/useHttpClient}}{{^useHttpClient}}http: Http{{/useHttpClient}}, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -56,6 +59,9 @@ export class {{classname}} { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/variables.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/variables.mustache index b3241fcebcd..a89ca2746ba 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular/variables.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/variables.mustache @@ -1,6 +1,8 @@ import { {{injectionToken}} } from '@angular/core'; +import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new {{injectionToken}}{{#injectionTokenTyped}}{{/injectionTokenTyped}}('basePath'); +export const BASE_PATH_OBSERVABLE = new {{injectionToken}}{{#injectionTokenTyped}}>{{/injectionTokenTyped}}('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts index 30354b57437..f1b2cb7bd43 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts @@ -23,7 +23,7 @@ import '../rxjs-operators'; import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -34,7 +34,10 @@ export class PetService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -42,6 +45,9 @@ export class PetService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts index 5c4d7ee5954..0f50cb7bdee 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -33,7 +33,10 @@ export class StoreService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -41,6 +44,9 @@ export class StoreService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts index fe2b4f7b6e7..f5f5e429a3b 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -33,7 +33,10 @@ export class UserService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -41,6 +44,9 @@ export class UserService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** @@ -124,7 +130,7 @@ export class UserService { /** * * @summary Get user by user name - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. */ public getUserByName(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.getUserByNameWithHttpInfo(username, extraHttpRequestParams) @@ -365,7 +371,7 @@ export class UserService { /** * Get user by user name * - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. */ public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { diff --git a/samples/client/petstore/typescript-angular-v2/default/variables.ts b/samples/client/petstore/typescript-angular-v2/default/variables.ts index 29b7e5b1d71..8011aa27fee 100644 --- a/samples/client/petstore/typescript-angular-v2/default/variables.ts +++ b/samples/client/petstore/typescript-angular-v2/default/variables.ts @@ -1,6 +1,8 @@ import { OpaqueToken } from '@angular/core'; +import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new OpaqueToken('basePath'); +export const BASE_PATH_OBSERVABLE = new OpaqueToken('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts index 30354b57437..f1b2cb7bd43 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts @@ -23,7 +23,7 @@ import '../rxjs-operators'; import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -34,7 +34,10 @@ export class PetService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -42,6 +45,9 @@ export class PetService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts index 5c4d7ee5954..0f50cb7bdee 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -33,7 +33,10 @@ export class StoreService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -41,6 +44,9 @@ export class StoreService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts index fe2b4f7b6e7..f5f5e429a3b 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -33,7 +33,10 @@ export class UserService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -41,6 +44,9 @@ export class UserService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** @@ -124,7 +130,7 @@ export class UserService { /** * * @summary Get user by user name - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. */ public getUserByName(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.getUserByNameWithHttpInfo(username, extraHttpRequestParams) @@ -365,7 +371,7 @@ export class UserService { /** * Get user by user name * - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. */ public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { diff --git a/samples/client/petstore/typescript-angular-v2/npm/variables.ts b/samples/client/petstore/typescript-angular-v2/npm/variables.ts index 29b7e5b1d71..8011aa27fee 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/variables.ts @@ -1,6 +1,8 @@ import { OpaqueToken } from '@angular/core'; +import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new OpaqueToken('basePath'); +export const BASE_PATH_OBSERVABLE = new OpaqueToken('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts index 565e6d3dbe4..daf0fb274c5 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts @@ -23,7 +23,7 @@ import '../rxjs-operators'; import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; import { PetServiceInterface } from './PetServiceInterface'; @@ -35,7 +35,10 @@ export class PetService implements PetServiceInterface { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -43,6 +46,9 @@ export class PetService implements PetServiceInterface { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts index 185de6d5e09..58c53c27161 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; import { StoreServiceInterface } from './StoreServiceInterface'; @@ -34,7 +34,10 @@ export class StoreService implements StoreServiceInterface { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -42,6 +45,9 @@ export class StoreService implements StoreServiceInterface { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts index ccbb653e9ef..db14f404d8f 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; import { UserServiceInterface } from './UserServiceInterface'; @@ -34,7 +34,10 @@ export class UserService implements UserServiceInterface { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -42,6 +45,9 @@ export class UserService implements UserServiceInterface { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** @@ -125,7 +131,7 @@ export class UserService implements UserServiceInterface { /** * * @summary Get user by user name - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. */ public getUserByName(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.getUserByNameWithHttpInfo(username, extraHttpRequestParams) @@ -366,7 +372,7 @@ export class UserService implements UserServiceInterface { /** * Get user by user name * - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. */ public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts index 29b7e5b1d71..8011aa27fee 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts @@ -1,6 +1,8 @@ import { OpaqueToken } from '@angular/core'; +import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new OpaqueToken('basePath'); +export const BASE_PATH_OBSERVABLE = new OpaqueToken('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts index 5dc987751bc..390da711724 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts @@ -21,7 +21,7 @@ import { Observable } from 'rxjs/Observab import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -32,7 +32,10 @@ export class PetService { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -40,6 +43,9 @@ export class PetService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts index 7c5364e471c..6d78b19be0c 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs/Observab import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -31,7 +31,10 @@ export class StoreService { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -39,6 +42,9 @@ export class StoreService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts index edc7a4b4298..d7ac66fe8df 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs/Observab import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -31,7 +31,10 @@ export class UserService { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -39,6 +42,9 @@ export class UserService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** @@ -238,7 +244,7 @@ export class UserService { /** * Get user by user name * - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts b/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts index 6fe58549f39..cb71ffc8be1 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts @@ -1,6 +1,8 @@ import { InjectionToken } from '@angular/core'; +import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new InjectionToken('basePath'); +export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts index 30354b57437..f1b2cb7bd43 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts @@ -23,7 +23,7 @@ import '../rxjs-operators'; import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -34,7 +34,10 @@ export class PetService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -42,6 +45,9 @@ export class PetService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts index 5c4d7ee5954..0f50cb7bdee 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -33,7 +33,10 @@ export class StoreService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -41,6 +44,9 @@ export class StoreService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts index fe2b4f7b6e7..f5f5e429a3b 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -33,7 +33,10 @@ export class UserService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -41,6 +44,9 @@ export class UserService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** @@ -124,7 +130,7 @@ export class UserService { /** * * @summary Get user by user name - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. */ public getUserByName(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.getUserByNameWithHttpInfo(username, extraHttpRequestParams) @@ -365,7 +371,7 @@ export class UserService { /** * Get user by user name * - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. */ public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { diff --git a/samples/client/petstore/typescript-angular-v4/npm/variables.ts b/samples/client/petstore/typescript-angular-v4/npm/variables.ts index 6fe58549f39..cb71ffc8be1 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/variables.ts @@ -1,6 +1,8 @@ import { InjectionToken } from '@angular/core'; +import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new InjectionToken('basePath'); +export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', From c5627409c6e75d3b0a5565b34813c0bc4f1d5d2e Mon Sep 17 00:00:00 2001 From: Chris Mellard Date: Thu, 5 Apr 2018 21:34:29 +1200 Subject: [PATCH 2/6] Updated README.mustache file with instructions on how to use BASE_PATH_OBSERVABLE DI token --- .../typescript-angular/README.mustache | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/README.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/README.mustache index 4025896cafa..aa22da5c173 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular/README.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/README.mustache @@ -144,6 +144,53 @@ export class AppModule {} ``` +### Set dynamic service base path +If required the base path can be modified throughout the lifecycle of the +service by injecting an `Observable` using the `BASE_PATH_OBSERVABLE` token. + + +``` +import { BASE_PATH_OBSERVABLE } from '{{npmName}}'; + +@NgModule({ + imports: [], + declarations: [ AppComponent ], + providers: [ + DynamicBasePathService, + { + provide: BASE_PATH_OBSERVABLE, + useFactory: () => new BehaviorSubject<string>('http://localhost:5000') + } + ], + bootstrap: [ AppComponent ] +}) +export class AppModule {} + +``` + +An example service defined below allows publishing new basePaths to the api services + +``` + +import {Inject, Injectable} from '@angular/core'; +import {Subject} from 'rxjs/Subject'; +import {BASE_PATH_OBSERVABLE} from '{{npmName}}'; + +@Injectable() +export class DynamicBasePathService { + + constructor(@Inject(BASE_PATH_OBSERVABLE) private basePathSubject$: Subject<string>) { + } + + public setBasePath(basePath: string): void { + this.basePathSubject$.next(basePath); + } + +} + +``` + + #### Using @angular/cli First extend your `src/environments/*.ts` files by adding the corresponding base path: From 095d039f6f5c180411cb904c5d3011de253c8e45 Mon Sep 17 00:00:00 2001 From: Chris Mellard Date: Sun, 13 May 2018 14:35:19 +1200 Subject: [PATCH 3/6] Issue7949 - Regenerated samples --- .../default/api/pet.service.ts | 10 +---- .../default/api/store.service.ts | 10 +---- .../default/api/user.service.ts | 10 +---- .../default/variables.ts | 2 - .../npm/api/pet.service.ts | 10 +---- .../npm/api/store.service.ts | 10 +---- .../npm/api/user.service.ts | 10 +---- .../typescript-angular-v2/npm/variables.ts | 2 - .../with-interfaces/README.md | 18 ++++----- .../with-interfaces/api/pet.service.ts | 10 +---- .../with-interfaces/api/store.service.ts | 10 +---- .../with-interfaces/api/user.service.ts | 10 +---- .../with-interfaces/package.json | 2 +- .../with-interfaces/variables.ts | 2 - .../npm/api/pet.service.ts | 10 +---- .../npm/api/store.service.ts | 10 +---- .../npm/api/user.service.ts | 10 +---- .../typescript-angular-v4.3/npm/variables.ts | 2 - .../with-interfaces/README.md | 24 ++++++------ .../api/pet.serviceInterface.ts | 1 - .../api/store.serviceInterface.ts | 1 - .../api/user.serviceInterface.ts | 1 - .../with-interfaces/ng-package.json | 6 +++ .../with-interfaces/package.json | 39 +++++++++++++++++++ .../with-interfaces/tsconfig.json | 25 ++++++++++++ .../with-interfaces/typings.json | 5 +++ .../npm/api/pet.service.ts | 10 +---- .../npm/api/store.service.ts | 10 +---- .../npm/api/user.service.ts | 10 +---- .../typescript-angular-v4/npm/variables.ts | 2 - .../with-interfaces/README.md | 24 ++++++------ .../api/pet.serviceInterface.ts | 1 - .../api/store.serviceInterface.ts | 1 - .../api/user.serviceInterface.ts | 1 - .../with-interfaces/ng-package.json | 6 +++ .../with-interfaces/package.json | 39 +++++++++++++++++++ .../with-interfaces/tsconfig.json | 25 ++++++++++++ .../with-interfaces/typings.json | 5 +++ 38 files changed, 214 insertions(+), 170 deletions(-) create mode 100644 samples/client/petstore/typescript-angular-v4.3/with-interfaces/ng-package.json create mode 100644 samples/client/petstore/typescript-angular-v4.3/with-interfaces/package.json create mode 100644 samples/client/petstore/typescript-angular-v4.3/with-interfaces/tsconfig.json create mode 100644 samples/client/petstore/typescript-angular-v4.3/with-interfaces/typings.json create mode 100644 samples/client/petstore/typescript-angular-v5/with-interfaces/ng-package.json create mode 100644 samples/client/petstore/typescript-angular-v5/with-interfaces/package.json create mode 100644 samples/client/petstore/typescript-angular-v5/with-interfaces/tsconfig.json create mode 100644 samples/client/petstore/typescript-angular-v5/with-interfaces/typings.json diff --git a/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts index 4f8d19784e8..0f487e7b1a0 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts @@ -23,7 +23,7 @@ import '../rxjs-operators'; import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; @@ -34,10 +34,7 @@ export class PetService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, - @Optional() @Inject(BASE_PATH) basePath: string, - @Optional() configuration: Configuration, - @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { this.basePath = basePath; } @@ -45,9 +42,6 @@ export class PetService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } - if (basePath$) { - basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); - } } /** diff --git a/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts index 13a18b7aeec..443d2ba8480 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; @@ -33,10 +33,7 @@ export class StoreService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, - @Optional() @Inject(BASE_PATH) basePath: string, - @Optional() configuration: Configuration, - @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { this.basePath = basePath; } @@ -44,9 +41,6 @@ export class StoreService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } - if (basePath$) { - basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); - } } /** diff --git a/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts index 19ac5ff4069..33bd9f1362a 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; @@ -33,10 +33,7 @@ export class UserService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, - @Optional() @Inject(BASE_PATH) basePath: string, - @Optional() configuration: Configuration, - @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { this.basePath = basePath; } @@ -44,9 +41,6 @@ export class UserService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } - if (basePath$) { - basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); - } } /** diff --git a/samples/client/petstore/typescript-angular-v2/default/variables.ts b/samples/client/petstore/typescript-angular-v2/default/variables.ts index 8011aa27fee..29b7e5b1d71 100644 --- a/samples/client/petstore/typescript-angular-v2/default/variables.ts +++ b/samples/client/petstore/typescript-angular-v2/default/variables.ts @@ -1,8 +1,6 @@ import { OpaqueToken } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new OpaqueToken('basePath'); -export const BASE_PATH_OBSERVABLE = new OpaqueToken('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts index 4f8d19784e8..0f487e7b1a0 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts @@ -23,7 +23,7 @@ import '../rxjs-operators'; import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; @@ -34,10 +34,7 @@ export class PetService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, - @Optional() @Inject(BASE_PATH) basePath: string, - @Optional() configuration: Configuration, - @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { this.basePath = basePath; } @@ -45,9 +42,6 @@ export class PetService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } - if (basePath$) { - basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); - } } /** diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts index 13a18b7aeec..443d2ba8480 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; @@ -33,10 +33,7 @@ export class StoreService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, - @Optional() @Inject(BASE_PATH) basePath: string, - @Optional() configuration: Configuration, - @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { this.basePath = basePath; } @@ -44,9 +41,6 @@ export class StoreService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } - if (basePath$) { - basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); - } } /** diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts index 19ac5ff4069..33bd9f1362a 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; @@ -33,10 +33,7 @@ export class UserService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, - @Optional() @Inject(BASE_PATH) basePath: string, - @Optional() configuration: Configuration, - @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { this.basePath = basePath; } @@ -44,9 +41,6 @@ export class UserService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } - if (basePath$) { - basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); - } } /** diff --git a/samples/client/petstore/typescript-angular-v2/npm/variables.ts b/samples/client/petstore/typescript-angular-v2/npm/variables.ts index 8011aa27fee..29b7e5b1d71 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/variables.ts @@ -1,8 +1,6 @@ import { OpaqueToken } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new OpaqueToken('basePath'); -export const BASE_PATH_OBSERVABLE = new OpaqueToken('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/README.md b/samples/client/petstore/typescript-angular-v2/with-interfaces/README.md index 851ec448b23..1d02eea3ae8 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/README.md +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/README.md @@ -1,4 +1,4 @@ -## @ +## @swagger/angular2-typescript-petstore@0.0.1 ### Building @@ -19,7 +19,7 @@ Navigate to the folder of your consuming project and run one of next commands. _published:_ ``` -npm install @ --save +npm install @swagger/angular2-typescript-petstore@0.0.1 --save ``` _without publishing (not recommended):_ @@ -37,7 +37,7 @@ npm link In your project: ``` -npm link +npm link @swagger/angular2-typescript-petstore ``` __Note for Windows users:__ The Angular CLI has troubles to use linked npm packages. @@ -52,7 +52,7 @@ In your Angular project: ``` // without configuring providers -import { ApiModule } from ''; +import { ApiModule } from '@swagger/angular2-typescript-petstore'; import { HttpModule } from '@angular/http'; @@ -70,7 +70,7 @@ export class AppModule {} ``` // configuring providers -import { ApiModule, Configuration, ConfigurationParameters } from ''; +import { ApiModule, Configuration, ConfigurationParameters } from '@swagger/angular2-typescript-petstore'; export function apiConfigFactory (): Configuration => { const params: ConfigurationParameters = { @@ -89,7 +89,7 @@ export class AppModule {} ``` ``` -import { DefaultApi } from ''; +import { DefaultApi } from '@swagger/angular2-typescript-petstore'; export class AppComponent { constructor(private apiGateway: DefaultApi) { } @@ -126,7 +126,7 @@ export class AppModule { If different than the generated base path, during app bootstrap, you can provide the base path to your service. ``` -import { BASE_PATH } from ''; +import { BASE_PATH } from '@swagger/angular2-typescript-petstore'; bootstrap(AppComponent, [ { provide: BASE_PATH, useValue: 'https://your-web-service.com' }, @@ -135,7 +135,7 @@ bootstrap(AppComponent, [ or ``` -import { BASE_PATH } from ''; +import { BASE_PATH } from '@swagger/angular2-typescript-petstore'; @NgModule({ imports: [], @@ -159,7 +159,7 @@ export const environment = { In the src/app/app.module.ts: ``` -import { BASE_PATH } from ''; +import { BASE_PATH } from '@swagger/angular2-typescript-petstore'; import { environment } from '../environments/environment'; @NgModule({ diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts index a691c381577..4e93857c426 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts @@ -23,7 +23,7 @@ import '../rxjs-operators'; import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; import { PetServiceInterface } from './pet.serviceInterface'; @@ -35,10 +35,7 @@ export class PetService implements PetServiceInterface { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, - @Optional() @Inject(BASE_PATH) basePath: string, - @Optional() configuration: Configuration, - @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { this.basePath = basePath; } @@ -46,9 +43,6 @@ export class PetService implements PetServiceInterface { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } - if (basePath$) { - basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); - } } /** diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts index 176f1fd1045..47e4cfd5e93 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; import { StoreServiceInterface } from './store.serviceInterface'; @@ -34,10 +34,7 @@ export class StoreService implements StoreServiceInterface { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, - @Optional() @Inject(BASE_PATH) basePath: string, - @Optional() configuration: Configuration, - @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { this.basePath = basePath; } @@ -45,9 +42,6 @@ export class StoreService implements StoreServiceInterface { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } - if (basePath$) { - basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); - } } /** diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts index e35c4f718bc..f664442825d 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; import { UserServiceInterface } from './user.serviceInterface'; @@ -34,10 +34,7 @@ export class UserService implements UserServiceInterface { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, - @Optional() @Inject(BASE_PATH) basePath: string, - @Optional() configuration: Configuration, - @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { this.basePath = basePath; } @@ -45,9 +42,6 @@ export class UserService implements UserServiceInterface { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } - if (basePath$) { - basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); - } } /** diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/package.json b/samples/client/petstore/typescript-angular-v2/with-interfaces/package.json index 704da6b4cae..d73ea17840b 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/package.json +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/package.json @@ -34,7 +34,7 @@ "reflect-metadata": "^0.1.3", "rxjs": "^5.4.0", "zone.js": "^0.7.6", - "typescript": "~2.1.5" + "typescript": ">=2.1.5 <2.8" }, "publishConfig": { "registry": "https://skimdb.npmjs.com/registry" diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts index 8011aa27fee..29b7e5b1d71 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts @@ -1,8 +1,6 @@ import { OpaqueToken } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new OpaqueToken('basePath'); -export const BASE_PATH_OBSERVABLE = new OpaqueToken('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts index 99017ffe27f..18563adb1b3 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts @@ -21,7 +21,7 @@ import { Observable } from 'rxjs/Observab import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; @@ -32,10 +32,7 @@ export class PetService { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, - @Optional() @Inject(BASE_PATH) basePath: string, - @Optional() configuration: Configuration, - @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { + constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { this.basePath = basePath; } @@ -43,9 +40,6 @@ export class PetService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } - if (basePath$) { - basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); - } } /** diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts index 3372180d555..03016b73c9d 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs/Observab import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; @@ -31,10 +31,7 @@ export class StoreService { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, - @Optional() @Inject(BASE_PATH) basePath: string, - @Optional() configuration: Configuration, - @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { + constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { this.basePath = basePath; } @@ -42,9 +39,6 @@ export class StoreService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } - if (basePath$) { - basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); - } } /** diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts index 9a63ef74fa2..7c7ccda2a79 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs/Observab import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; @@ -31,10 +31,7 @@ export class UserService { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, - @Optional() @Inject(BASE_PATH) basePath: string, - @Optional() configuration: Configuration, - @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { + constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { this.basePath = basePath; } @@ -42,9 +39,6 @@ export class UserService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } - if (basePath$) { - basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); - } } /** diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts b/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts index cb71ffc8be1..6fe58549f39 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts @@ -1,8 +1,6 @@ import { InjectionToken } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new InjectionToken('basePath'); -export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/README.md b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/README.md index 9c7753a47b7..b5a6ac2a8b8 100644 --- a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/README.md +++ b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/README.md @@ -1,4 +1,4 @@ -## @ +## @swagger/angular2-typescript-petstore@0.0.1 ### Building @@ -10,7 +10,7 @@ npm run build ### publishing -First build the package than run ```npm publish``` +First build the package than run ```npm publish dist``` (don't forget to specify the `dist` folder!) ### consuming @@ -19,25 +19,25 @@ Navigate to the folder of your consuming project and run one of next commands. _published:_ ``` -npm install @ --save +npm install @swagger/angular2-typescript-petstore@0.0.1 --save ``` _without publishing (not recommended):_ ``` -npm install PATH_TO_GENERATED_PACKAGE --save +npm install PATH_TO_GENERATED_PACKAGE/dist --save ``` _using `npm link`:_ -In PATH_TO_GENERATED_PACKAGE: +In PATH_TO_GENERATED_PACKAGE/dist: ``` npm link ``` In your project: ``` -npm link +npm link @swagger/angular2-typescript-petstore ``` __Note for Windows users:__ The Angular CLI has troubles to use linked npm packages. @@ -52,7 +52,7 @@ In your Angular project: ``` // without configuring providers -import { ApiModule } from ''; +import { ApiModule } from '@swagger/angular2-typescript-petstore'; import { HttpClientModule } from '@angular/common/http'; @@ -72,7 +72,7 @@ export class AppModule {} ``` // configuring providers -import { ApiModule, Configuration, ConfigurationParameters } from ''; +import { ApiModule, Configuration, ConfigurationParameters } from '@swagger/angular2-typescript-petstore'; export function apiConfigFactory (): Configuration => { const params: ConfigurationParameters = { @@ -91,7 +91,7 @@ export class AppModule {} ``` ``` -import { DefaultApi } from ''; +import { DefaultApi } from '@swagger/angular2-typescript-petstore'; export class AppComponent { constructor(private apiGateway: DefaultApi) { } @@ -130,7 +130,7 @@ export class AppModule { If different than the generated base path, during app bootstrap, you can provide the base path to your service. ``` -import { BASE_PATH } from ''; +import { BASE_PATH } from '@swagger/angular2-typescript-petstore'; bootstrap(AppComponent, [ { provide: BASE_PATH, useValue: 'https://your-web-service.com' }, @@ -139,7 +139,7 @@ bootstrap(AppComponent, [ or ``` -import { BASE_PATH } from ''; +import { BASE_PATH } from '@swagger/angular2-typescript-petstore'; @NgModule({ imports: [], @@ -163,7 +163,7 @@ export const environment = { In the src/app/app.module.ts: ``` -import { BASE_PATH } from ''; +import { BASE_PATH } from '@swagger/angular2-typescript-petstore'; import { environment } from '../environments/environment'; @NgModule({ diff --git a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/pet.serviceInterface.ts b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/pet.serviceInterface.ts index 0278db6664e..d7dc9e5be5e 100644 --- a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/pet.serviceInterface.ts +++ b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/pet.serviceInterface.ts @@ -13,7 +13,6 @@ import { HttpHeaders } from '@angular/comm import { Observable } from 'rxjs/Observable'; - import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; diff --git a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/store.serviceInterface.ts b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/store.serviceInterface.ts index 5d3227ea075..38614ae7be2 100644 --- a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/store.serviceInterface.ts +++ b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/store.serviceInterface.ts @@ -13,7 +13,6 @@ import { HttpHeaders } from '@angular/comm import { Observable } from 'rxjs/Observable'; - import { Order } from '../model/order'; diff --git a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/user.serviceInterface.ts b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/user.serviceInterface.ts index 7dc6496c2fa..b298d40ca4f 100644 --- a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/user.serviceInterface.ts +++ b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/user.serviceInterface.ts @@ -13,7 +13,6 @@ import { HttpHeaders } from '@angular/comm import { Observable } from 'rxjs/Observable'; - import { User } from '../model/user'; diff --git a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/ng-package.json b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/ng-package.json new file mode 100644 index 00000000000..3b17900dc9c --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/ng-package.json @@ -0,0 +1,6 @@ +{ + "$schema": "./node_modules/ng-packagr/ng-package.schema.json", + "lib": { + "entryFile": "index.ts" + } +} diff --git a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/package.json b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/package.json new file mode 100644 index 00000000000..3b689b9df96 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/package.json @@ -0,0 +1,39 @@ +{ + "name": "@swagger/angular2-typescript-petstore", + "version": "0.0.1", + "description": "swagger client for @swagger/angular2-typescript-petstore", + "author": "Swagger Codegen Contributors", + "keywords": [ + "swagger-client" + ], + "license": "Unlicense", + "scripts": { + "build": "ng-packagr -p ng-package.json" + }, + "peerDependencies": { + "@angular/core": "^4.3.0", + "@angular/http": "^4.3.0", + "@angular/common": "^4.3.0", + "@angular/compiler": "^4.3.0", + "core-js": "^2.4.0", + "reflect-metadata": "^0.1.3", + "rxjs": "^5.4.0", + "zone.js": "^0.7.6" + }, + "devDependencies": { + "@angular/compiler-cli": "^4.3.0", + "@angular/core": "^4.3.0", + "@angular/http": "^4.3.0", + "@angular/common": "^4.3.0", + "@angular/compiler": "^4.3.0", + "@angular/platform-browser": "^4.3.0", + "ng-packagr": "^1.6.0", + "reflect-metadata": "^0.1.3", + "rxjs": "^5.4.0", + "zone.js": "^0.7.6", + "typescript": ">=2.1.5 <2.8" + }, + "publishConfig": { + "registry": "https://skimdb.npmjs.com/registry" + } +} diff --git a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/tsconfig.json b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/tsconfig.json new file mode 100644 index 00000000000..498ee01e9dd --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "noImplicitAny": false, + "suppressImplicitAnyIndexErrors": true, + "target": "es5", + "module": "commonjs", + "moduleResolution": "node", + "removeComments": true, + "sourceMap": true, + "outDir": "./dist", + "noLib": false, + "declaration": true, + "lib": [ "es6", "dom" ] + }, + "exclude": [ + "node_modules", + "dist" + ], + "filesGlob": [ + "./model/*.ts", + "./api/*.ts" + ] +} diff --git a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/typings.json b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/typings.json new file mode 100644 index 00000000000..507c40e5cbe --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/typings.json @@ -0,0 +1,5 @@ +{ + "globalDependencies": { + "core-js": "registry:dt/core-js#0.0.0+20160725163759" + } +} diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts index 4f8d19784e8..0f487e7b1a0 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts @@ -23,7 +23,7 @@ import '../rxjs-operators'; import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; @@ -34,10 +34,7 @@ export class PetService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, - @Optional() @Inject(BASE_PATH) basePath: string, - @Optional() configuration: Configuration, - @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { this.basePath = basePath; } @@ -45,9 +42,6 @@ export class PetService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } - if (basePath$) { - basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); - } } /** diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts index 13a18b7aeec..443d2ba8480 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; @@ -33,10 +33,7 @@ export class StoreService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, - @Optional() @Inject(BASE_PATH) basePath: string, - @Optional() configuration: Configuration, - @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { this.basePath = basePath; } @@ -44,9 +41,6 @@ export class StoreService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } - if (basePath$) { - basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); - } } /** diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts index 19ac5ff4069..33bd9f1362a 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; @@ -33,10 +33,7 @@ export class UserService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, - @Optional() @Inject(BASE_PATH) basePath: string, - @Optional() configuration: Configuration, - @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { this.basePath = basePath; } @@ -44,9 +41,6 @@ export class UserService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } - if (basePath$) { - basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); - } } /** diff --git a/samples/client/petstore/typescript-angular-v4/npm/variables.ts b/samples/client/petstore/typescript-angular-v4/npm/variables.ts index cb71ffc8be1..6fe58549f39 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/variables.ts @@ -1,8 +1,6 @@ import { InjectionToken } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new InjectionToken('basePath'); -export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v5/with-interfaces/README.md b/samples/client/petstore/typescript-angular-v5/with-interfaces/README.md index 9c7753a47b7..b5a6ac2a8b8 100644 --- a/samples/client/petstore/typescript-angular-v5/with-interfaces/README.md +++ b/samples/client/petstore/typescript-angular-v5/with-interfaces/README.md @@ -1,4 +1,4 @@ -## @ +## @swagger/angular2-typescript-petstore@0.0.1 ### Building @@ -10,7 +10,7 @@ npm run build ### publishing -First build the package than run ```npm publish``` +First build the package than run ```npm publish dist``` (don't forget to specify the `dist` folder!) ### consuming @@ -19,25 +19,25 @@ Navigate to the folder of your consuming project and run one of next commands. _published:_ ``` -npm install @ --save +npm install @swagger/angular2-typescript-petstore@0.0.1 --save ``` _without publishing (not recommended):_ ``` -npm install PATH_TO_GENERATED_PACKAGE --save +npm install PATH_TO_GENERATED_PACKAGE/dist --save ``` _using `npm link`:_ -In PATH_TO_GENERATED_PACKAGE: +In PATH_TO_GENERATED_PACKAGE/dist: ``` npm link ``` In your project: ``` -npm link +npm link @swagger/angular2-typescript-petstore ``` __Note for Windows users:__ The Angular CLI has troubles to use linked npm packages. @@ -52,7 +52,7 @@ In your Angular project: ``` // without configuring providers -import { ApiModule } from ''; +import { ApiModule } from '@swagger/angular2-typescript-petstore'; import { HttpClientModule } from '@angular/common/http'; @@ -72,7 +72,7 @@ export class AppModule {} ``` // configuring providers -import { ApiModule, Configuration, ConfigurationParameters } from ''; +import { ApiModule, Configuration, ConfigurationParameters } from '@swagger/angular2-typescript-petstore'; export function apiConfigFactory (): Configuration => { const params: ConfigurationParameters = { @@ -91,7 +91,7 @@ export class AppModule {} ``` ``` -import { DefaultApi } from ''; +import { DefaultApi } from '@swagger/angular2-typescript-petstore'; export class AppComponent { constructor(private apiGateway: DefaultApi) { } @@ -130,7 +130,7 @@ export class AppModule { If different than the generated base path, during app bootstrap, you can provide the base path to your service. ``` -import { BASE_PATH } from ''; +import { BASE_PATH } from '@swagger/angular2-typescript-petstore'; bootstrap(AppComponent, [ { provide: BASE_PATH, useValue: 'https://your-web-service.com' }, @@ -139,7 +139,7 @@ bootstrap(AppComponent, [ or ``` -import { BASE_PATH } from ''; +import { BASE_PATH } from '@swagger/angular2-typescript-petstore'; @NgModule({ imports: [], @@ -163,7 +163,7 @@ export const environment = { In the src/app/app.module.ts: ``` -import { BASE_PATH } from ''; +import { BASE_PATH } from '@swagger/angular2-typescript-petstore'; import { environment } from '../environments/environment'; @NgModule({ diff --git a/samples/client/petstore/typescript-angular-v5/with-interfaces/api/pet.serviceInterface.ts b/samples/client/petstore/typescript-angular-v5/with-interfaces/api/pet.serviceInterface.ts index 0278db6664e..d7dc9e5be5e 100644 --- a/samples/client/petstore/typescript-angular-v5/with-interfaces/api/pet.serviceInterface.ts +++ b/samples/client/petstore/typescript-angular-v5/with-interfaces/api/pet.serviceInterface.ts @@ -13,7 +13,6 @@ import { HttpHeaders } from '@angular/comm import { Observable } from 'rxjs/Observable'; - import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; diff --git a/samples/client/petstore/typescript-angular-v5/with-interfaces/api/store.serviceInterface.ts b/samples/client/petstore/typescript-angular-v5/with-interfaces/api/store.serviceInterface.ts index 5d3227ea075..38614ae7be2 100644 --- a/samples/client/petstore/typescript-angular-v5/with-interfaces/api/store.serviceInterface.ts +++ b/samples/client/petstore/typescript-angular-v5/with-interfaces/api/store.serviceInterface.ts @@ -13,7 +13,6 @@ import { HttpHeaders } from '@angular/comm import { Observable } from 'rxjs/Observable'; - import { Order } from '../model/order'; diff --git a/samples/client/petstore/typescript-angular-v5/with-interfaces/api/user.serviceInterface.ts b/samples/client/petstore/typescript-angular-v5/with-interfaces/api/user.serviceInterface.ts index 7dc6496c2fa..b298d40ca4f 100644 --- a/samples/client/petstore/typescript-angular-v5/with-interfaces/api/user.serviceInterface.ts +++ b/samples/client/petstore/typescript-angular-v5/with-interfaces/api/user.serviceInterface.ts @@ -13,7 +13,6 @@ import { HttpHeaders } from '@angular/comm import { Observable } from 'rxjs/Observable'; - import { User } from '../model/user'; diff --git a/samples/client/petstore/typescript-angular-v5/with-interfaces/ng-package.json b/samples/client/petstore/typescript-angular-v5/with-interfaces/ng-package.json new file mode 100644 index 00000000000..3b17900dc9c --- /dev/null +++ b/samples/client/petstore/typescript-angular-v5/with-interfaces/ng-package.json @@ -0,0 +1,6 @@ +{ + "$schema": "./node_modules/ng-packagr/ng-package.schema.json", + "lib": { + "entryFile": "index.ts" + } +} diff --git a/samples/client/petstore/typescript-angular-v5/with-interfaces/package.json b/samples/client/petstore/typescript-angular-v5/with-interfaces/package.json new file mode 100644 index 00000000000..3de3a319525 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v5/with-interfaces/package.json @@ -0,0 +1,39 @@ +{ + "name": "@swagger/angular2-typescript-petstore", + "version": "0.0.1", + "description": "swagger client for @swagger/angular2-typescript-petstore", + "author": "Swagger Codegen Contributors", + "keywords": [ + "swagger-client" + ], + "license": "Unlicense", + "scripts": { + "build": "ng-packagr -p ng-package.json" + }, + "peerDependencies": { + "@angular/core": "^5.0.0", + "@angular/http": "^5.0.0", + "@angular/common": "^5.0.0", + "@angular/compiler": "^5.0.0", + "core-js": "^2.4.0", + "reflect-metadata": "^0.1.3", + "rxjs": "^5.4.0", + "zone.js": "^0.7.6" + }, + "devDependencies": { + "@angular/compiler-cli": "^5.0.0", + "@angular/core": "^5.0.0", + "@angular/http": "^5.0.0", + "@angular/common": "^5.0.0", + "@angular/compiler": "^5.0.0", + "@angular/platform-browser": "^5.0.0", + "ng-packagr": "^2.4.1", + "reflect-metadata": "^0.1.3", + "rxjs": "^5.4.0", + "zone.js": "^0.7.6", + "typescript": ">=2.1.5 <2.8" + }, + "publishConfig": { + "registry": "https://skimdb.npmjs.com/registry" + } +} diff --git a/samples/client/petstore/typescript-angular-v5/with-interfaces/tsconfig.json b/samples/client/petstore/typescript-angular-v5/with-interfaces/tsconfig.json new file mode 100644 index 00000000000..498ee01e9dd --- /dev/null +++ b/samples/client/petstore/typescript-angular-v5/with-interfaces/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "noImplicitAny": false, + "suppressImplicitAnyIndexErrors": true, + "target": "es5", + "module": "commonjs", + "moduleResolution": "node", + "removeComments": true, + "sourceMap": true, + "outDir": "./dist", + "noLib": false, + "declaration": true, + "lib": [ "es6", "dom" ] + }, + "exclude": [ + "node_modules", + "dist" + ], + "filesGlob": [ + "./model/*.ts", + "./api/*.ts" + ] +} diff --git a/samples/client/petstore/typescript-angular-v5/with-interfaces/typings.json b/samples/client/petstore/typescript-angular-v5/with-interfaces/typings.json new file mode 100644 index 00000000000..507c40e5cbe --- /dev/null +++ b/samples/client/petstore/typescript-angular-v5/with-interfaces/typings.json @@ -0,0 +1,5 @@ +{ + "globalDependencies": { + "core-js": "registry:dt/core-js#0.0.0+20160725163759" + } +} From ebbcef23d48a3817c3f7a5742dcb11ec3336aab9 Mon Sep 17 00:00:00 2001 From: Chris Mellard Date: Sun, 13 May 2018 20:49:38 +1200 Subject: [PATCH 4/6] Issue7949 - Regenerated samples --- .../typescript-angular-v2/default/README.md | 47 +++++++++++++++++++ .../default/api/pet.service.ts | 10 +++- .../default/api/store.service.ts | 10 +++- .../default/api/user.service.ts | 10 +++- .../default/variables.ts | 2 + .../typescript-angular-v2/npm/README.md | 47 +++++++++++++++++++ .../npm/api/pet.service.ts | 10 +++- .../npm/api/store.service.ts | 10 +++- .../npm/api/user.service.ts | 10 +++- .../typescript-angular-v2/npm/variables.ts | 2 + .../with-interfaces/README.md | 47 +++++++++++++++++++ .../with-interfaces/api/pet.service.ts | 10 +++- .../with-interfaces/api/store.service.ts | 10 +++- .../with-interfaces/api/user.service.ts | 10 +++- .../with-interfaces/variables.ts | 2 + .../typescript-angular-v4.3/npm/README.md | 47 +++++++++++++++++++ .../npm/api/pet.service.ts | 10 +++- .../npm/api/store.service.ts | 10 +++- .../npm/api/user.service.ts | 10 +++- .../typescript-angular-v4.3/npm/variables.ts | 2 + .../with-interfaces/README.md | 47 +++++++++++++++++++ .../with-interfaces/api/pet.service.ts | 10 +++- .../with-interfaces/api/store.service.ts | 10 +++- .../with-interfaces/api/user.service.ts | 10 +++- .../with-interfaces/variables.ts | 2 + .../typescript-angular-v4/npm/README.md | 47 +++++++++++++++++++ .../npm/api/pet.service.ts | 10 +++- .../npm/api/store.service.ts | 10 +++- .../npm/api/user.service.ts | 10 +++- .../typescript-angular-v4/npm/variables.ts | 2 + .../typescript-angular-v5/npm/README.md | 47 +++++++++++++++++++ .../npm/api/pet.service.ts | 10 +++- .../npm/api/store.service.ts | 10 +++- .../npm/api/user.service.ts | 10 +++- .../typescript-angular-v5/npm/variables.ts | 2 + .../with-interfaces/README.md | 47 +++++++++++++++++++ .../with-interfaces/api/pet.service.ts | 10 +++- .../with-interfaces/api/store.service.ts | 10 +++- .../with-interfaces/api/user.service.ts | 10 +++- .../with-interfaces/variables.ts | 2 + .../typescript-angular-v6/npm/README.md | 47 +++++++++++++++++++ .../npm/api/pet.service.ts | 10 +++- .../npm/api/store.service.ts | 10 +++- .../npm/api/user.service.ts | 10 +++- .../typescript-angular-v6/npm/variables.ts | 2 + 45 files changed, 657 insertions(+), 54 deletions(-) diff --git a/samples/client/petstore/typescript-angular-v2/default/README.md b/samples/client/petstore/typescript-angular-v2/default/README.md index 851ec448b23..a269164bf1b 100644 --- a/samples/client/petstore/typescript-angular-v2/default/README.md +++ b/samples/client/petstore/typescript-angular-v2/default/README.md @@ -147,6 +147,53 @@ export class AppModule {} ``` +### Set dynamic service base path +If required the base path can be modified throughout the lifecycle of the +service by injecting an `Observable` using the `BASE_PATH_OBSERVABLE` token. + + +``` +import { BASE_PATH_OBSERVABLE } from ''; + +@NgModule({ + imports: [], + declarations: [ AppComponent ], + providers: [ + DynamicBasePathService, + { + provide: BASE_PATH_OBSERVABLE, + useFactory: () => new BehaviorSubject<string>('http://localhost:5000') + } + ], + bootstrap: [ AppComponent ] +}) +export class AppModule {} + +``` + +An example service defined below allows publishing new basePaths to the api services + +``` + +import {Inject, Injectable} from '@angular/core'; +import {Subject} from 'rxjs/Subject'; +import {BASE_PATH_OBSERVABLE} from ''; + +@Injectable() +export class DynamicBasePathService { + + constructor(@Inject(BASE_PATH_OBSERVABLE) private basePathSubject$: Subject<string>) { + } + + public setBasePath(basePath: string): void { + this.basePathSubject$.next(basePath); + } + +} + +``` + + #### Using @angular/cli First extend your `src/environments/*.ts` files by adding the corresponding base path: diff --git a/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts index 0f487e7b1a0..4f8d19784e8 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts @@ -23,7 +23,7 @@ import '../rxjs-operators'; import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -34,7 +34,10 @@ export class PetService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -42,6 +45,9 @@ export class PetService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts index 443d2ba8480..13a18b7aeec 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -33,7 +33,10 @@ export class StoreService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -41,6 +44,9 @@ export class StoreService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts index 33bd9f1362a..19ac5ff4069 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -33,7 +33,10 @@ export class UserService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -41,6 +44,9 @@ export class UserService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v2/default/variables.ts b/samples/client/petstore/typescript-angular-v2/default/variables.ts index 29b7e5b1d71..8011aa27fee 100644 --- a/samples/client/petstore/typescript-angular-v2/default/variables.ts +++ b/samples/client/petstore/typescript-angular-v2/default/variables.ts @@ -1,6 +1,8 @@ import { OpaqueToken } from '@angular/core'; +import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new OpaqueToken('basePath'); +export const BASE_PATH_OBSERVABLE = new OpaqueToken('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v2/npm/README.md b/samples/client/petstore/typescript-angular-v2/npm/README.md index 1d02eea3ae8..57db079fc98 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/README.md +++ b/samples/client/petstore/typescript-angular-v2/npm/README.md @@ -147,6 +147,53 @@ export class AppModule {} ``` +### Set dynamic service base path +If required the base path can be modified throughout the lifecycle of the +service by injecting an `Observable` using the `BASE_PATH_OBSERVABLE` token. + + +``` +import { BASE_PATH_OBSERVABLE } from '@swagger/angular2-typescript-petstore'; + +@NgModule({ + imports: [], + declarations: [ AppComponent ], + providers: [ + DynamicBasePathService, + { + provide: BASE_PATH_OBSERVABLE, + useFactory: () => new BehaviorSubject<string>('http://localhost:5000') + } + ], + bootstrap: [ AppComponent ] +}) +export class AppModule {} + +``` + +An example service defined below allows publishing new basePaths to the api services + +``` + +import {Inject, Injectable} from '@angular/core'; +import {Subject} from 'rxjs/Subject'; +import {BASE_PATH_OBSERVABLE} from '@swagger/angular2-typescript-petstore'; + +@Injectable() +export class DynamicBasePathService { + + constructor(@Inject(BASE_PATH_OBSERVABLE) private basePathSubject$: Subject<string>) { + } + + public setBasePath(basePath: string): void { + this.basePathSubject$.next(basePath); + } + +} + +``` + + #### Using @angular/cli First extend your `src/environments/*.ts` files by adding the corresponding base path: diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts index 0f487e7b1a0..4f8d19784e8 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts @@ -23,7 +23,7 @@ import '../rxjs-operators'; import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -34,7 +34,10 @@ export class PetService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -42,6 +45,9 @@ export class PetService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts index 443d2ba8480..13a18b7aeec 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -33,7 +33,10 @@ export class StoreService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -41,6 +44,9 @@ export class StoreService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts index 33bd9f1362a..19ac5ff4069 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -33,7 +33,10 @@ export class UserService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -41,6 +44,9 @@ export class UserService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v2/npm/variables.ts b/samples/client/petstore/typescript-angular-v2/npm/variables.ts index 29b7e5b1d71..8011aa27fee 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/variables.ts @@ -1,6 +1,8 @@ import { OpaqueToken } from '@angular/core'; +import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new OpaqueToken('basePath'); +export const BASE_PATH_OBSERVABLE = new OpaqueToken('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/README.md b/samples/client/petstore/typescript-angular-v2/with-interfaces/README.md index 1d02eea3ae8..57db079fc98 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/README.md +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/README.md @@ -147,6 +147,53 @@ export class AppModule {} ``` +### Set dynamic service base path +If required the base path can be modified throughout the lifecycle of the +service by injecting an `Observable` using the `BASE_PATH_OBSERVABLE` token. + + +``` +import { BASE_PATH_OBSERVABLE } from '@swagger/angular2-typescript-petstore'; + +@NgModule({ + imports: [], + declarations: [ AppComponent ], + providers: [ + DynamicBasePathService, + { + provide: BASE_PATH_OBSERVABLE, + useFactory: () => new BehaviorSubject<string>('http://localhost:5000') + } + ], + bootstrap: [ AppComponent ] +}) +export class AppModule {} + +``` + +An example service defined below allows publishing new basePaths to the api services + +``` + +import {Inject, Injectable} from '@angular/core'; +import {Subject} from 'rxjs/Subject'; +import {BASE_PATH_OBSERVABLE} from '@swagger/angular2-typescript-petstore'; + +@Injectable() +export class DynamicBasePathService { + + constructor(@Inject(BASE_PATH_OBSERVABLE) private basePathSubject$: Subject<string>) { + } + + public setBasePath(basePath: string): void { + this.basePathSubject$.next(basePath); + } + +} + +``` + + #### Using @angular/cli First extend your `src/environments/*.ts` files by adding the corresponding base path: diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts index 4e93857c426..a691c381577 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts @@ -23,7 +23,7 @@ import '../rxjs-operators'; import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; import { PetServiceInterface } from './pet.serviceInterface'; @@ -35,7 +35,10 @@ export class PetService implements PetServiceInterface { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -43,6 +46,9 @@ export class PetService implements PetServiceInterface { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts index 47e4cfd5e93..176f1fd1045 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; import { StoreServiceInterface } from './store.serviceInterface'; @@ -34,7 +34,10 @@ export class StoreService implements StoreServiceInterface { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -42,6 +45,9 @@ export class StoreService implements StoreServiceInterface { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts index f664442825d..e35c4f718bc 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; import { UserServiceInterface } from './user.serviceInterface'; @@ -34,7 +34,10 @@ export class UserService implements UserServiceInterface { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -42,6 +45,9 @@ export class UserService implements UserServiceInterface { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts index 29b7e5b1d71..8011aa27fee 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts @@ -1,6 +1,8 @@ import { OpaqueToken } from '@angular/core'; +import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new OpaqueToken('basePath'); +export const BASE_PATH_OBSERVABLE = new OpaqueToken('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/README.md b/samples/client/petstore/typescript-angular-v4.3/npm/README.md index b5a6ac2a8b8..1c867e21151 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/README.md +++ b/samples/client/petstore/typescript-angular-v4.3/npm/README.md @@ -151,6 +151,53 @@ export class AppModule {} ``` +### Set dynamic service base path +If required the base path can be modified throughout the lifecycle of the +service by injecting an `Observable` using the `BASE_PATH_OBSERVABLE` token. + + +``` +import { BASE_PATH_OBSERVABLE } from '@swagger/angular2-typescript-petstore'; + +@NgModule({ + imports: [], + declarations: [ AppComponent ], + providers: [ + DynamicBasePathService, + { + provide: BASE_PATH_OBSERVABLE, + useFactory: () => new BehaviorSubject<string>('http://localhost:5000') + } + ], + bootstrap: [ AppComponent ] +}) +export class AppModule {} + +``` + +An example service defined below allows publishing new basePaths to the api services + +``` + +import {Inject, Injectable} from '@angular/core'; +import {Subject} from 'rxjs/Subject'; +import {BASE_PATH_OBSERVABLE} from '@swagger/angular2-typescript-petstore'; + +@Injectable() +export class DynamicBasePathService { + + constructor(@Inject(BASE_PATH_OBSERVABLE) private basePathSubject$: Subject<string>) { + } + + public setBasePath(basePath: string): void { + this.basePathSubject$.next(basePath); + } + +} + +``` + + #### Using @angular/cli First extend your `src/environments/*.ts` files by adding the corresponding base path: diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts index 18563adb1b3..99017ffe27f 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts @@ -21,7 +21,7 @@ import { Observable } from 'rxjs/Observab import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -32,7 +32,10 @@ export class PetService { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -40,6 +43,9 @@ export class PetService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts index 03016b73c9d..3372180d555 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs/Observab import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -31,7 +31,10 @@ export class StoreService { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -39,6 +42,9 @@ export class StoreService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts index 7c7ccda2a79..9a63ef74fa2 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs/Observab import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -31,7 +31,10 @@ export class UserService { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -39,6 +42,9 @@ export class UserService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts b/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts index 6fe58549f39..cb71ffc8be1 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts @@ -1,6 +1,8 @@ import { InjectionToken } from '@angular/core'; +import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new InjectionToken('basePath'); +export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/README.md b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/README.md index b5a6ac2a8b8..1c867e21151 100644 --- a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/README.md +++ b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/README.md @@ -151,6 +151,53 @@ export class AppModule {} ``` +### Set dynamic service base path +If required the base path can be modified throughout the lifecycle of the +service by injecting an `Observable` using the `BASE_PATH_OBSERVABLE` token. + + +``` +import { BASE_PATH_OBSERVABLE } from '@swagger/angular2-typescript-petstore'; + +@NgModule({ + imports: [], + declarations: [ AppComponent ], + providers: [ + DynamicBasePathService, + { + provide: BASE_PATH_OBSERVABLE, + useFactory: () => new BehaviorSubject<string>('http://localhost:5000') + } + ], + bootstrap: [ AppComponent ] +}) +export class AppModule {} + +``` + +An example service defined below allows publishing new basePaths to the api services + +``` + +import {Inject, Injectable} from '@angular/core'; +import {Subject} from 'rxjs/Subject'; +import {BASE_PATH_OBSERVABLE} from '@swagger/angular2-typescript-petstore'; + +@Injectable() +export class DynamicBasePathService { + + constructor(@Inject(BASE_PATH_OBSERVABLE) private basePathSubject$: Subject<string>) { + } + + public setBasePath(basePath: string): void { + this.basePathSubject$.next(basePath); + } + +} + +``` + + #### Using @angular/cli First extend your `src/environments/*.ts` files by adding the corresponding base path: diff --git a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/pet.service.ts b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/pet.service.ts index f7a5a17785d..4cee12634ed 100644 --- a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/pet.service.ts @@ -21,7 +21,7 @@ import { Observable } from 'rxjs/Observab import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; import { PetServiceInterface } from './pet.serviceInterface'; @@ -33,7 +33,10 @@ export class PetService implements PetServiceInterface { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -41,6 +44,9 @@ export class PetService implements PetServiceInterface { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/store.service.ts b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/store.service.ts index 233e257c2fa..e4a0f55f9c6 100644 --- a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/store.service.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs/Observab import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; import { StoreServiceInterface } from './store.serviceInterface'; @@ -32,7 +32,10 @@ export class StoreService implements StoreServiceInterface { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -40,6 +43,9 @@ export class StoreService implements StoreServiceInterface { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/user.service.ts b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/user.service.ts index b6e09b12657..9d58e316eaa 100644 --- a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/api/user.service.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs/Observab import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; import { UserServiceInterface } from './user.serviceInterface'; @@ -32,7 +32,10 @@ export class UserService implements UserServiceInterface { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -40,6 +43,9 @@ export class UserService implements UserServiceInterface { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/variables.ts b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/variables.ts index 6fe58549f39..cb71ffc8be1 100644 --- a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/variables.ts +++ b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/variables.ts @@ -1,6 +1,8 @@ import { InjectionToken } from '@angular/core'; +import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new InjectionToken('basePath'); +export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v4/npm/README.md b/samples/client/petstore/typescript-angular-v4/npm/README.md index 73c64dbafca..2d5b18615fc 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/README.md +++ b/samples/client/petstore/typescript-angular-v4/npm/README.md @@ -147,6 +147,53 @@ export class AppModule {} ``` +### Set dynamic service base path +If required the base path can be modified throughout the lifecycle of the +service by injecting an `Observable` using the `BASE_PATH_OBSERVABLE` token. + + +``` +import { BASE_PATH_OBSERVABLE } from '@swagger/angular2-typescript-petstore'; + +@NgModule({ + imports: [], + declarations: [ AppComponent ], + providers: [ + DynamicBasePathService, + { + provide: BASE_PATH_OBSERVABLE, + useFactory: () => new BehaviorSubject<string>('http://localhost:5000') + } + ], + bootstrap: [ AppComponent ] +}) +export class AppModule {} + +``` + +An example service defined below allows publishing new basePaths to the api services + +``` + +import {Inject, Injectable} from '@angular/core'; +import {Subject} from 'rxjs/Subject'; +import {BASE_PATH_OBSERVABLE} from '@swagger/angular2-typescript-petstore'; + +@Injectable() +export class DynamicBasePathService { + + constructor(@Inject(BASE_PATH_OBSERVABLE) private basePathSubject$: Subject<string>) { + } + + public setBasePath(basePath: string): void { + this.basePathSubject$.next(basePath); + } + +} + +``` + + #### Using @angular/cli First extend your `src/environments/*.ts` files by adding the corresponding base path: diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts index 0f487e7b1a0..4f8d19784e8 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts @@ -23,7 +23,7 @@ import '../rxjs-operators'; import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -34,7 +34,10 @@ export class PetService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -42,6 +45,9 @@ export class PetService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts index 443d2ba8480..13a18b7aeec 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -33,7 +33,10 @@ export class StoreService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -41,6 +44,9 @@ export class StoreService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts index 33bd9f1362a..19ac5ff4069 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts @@ -22,7 +22,7 @@ import '../rxjs-operators'; import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -33,7 +33,10 @@ export class UserService { public defaultHeaders = new Headers(); public configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected http: Http, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -41,6 +44,9 @@ export class UserService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v4/npm/variables.ts b/samples/client/petstore/typescript-angular-v4/npm/variables.ts index 6fe58549f39..cb71ffc8be1 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/variables.ts @@ -1,6 +1,8 @@ import { InjectionToken } from '@angular/core'; +import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new InjectionToken('basePath'); +export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v5/npm/README.md b/samples/client/petstore/typescript-angular-v5/npm/README.md index b5a6ac2a8b8..1c867e21151 100644 --- a/samples/client/petstore/typescript-angular-v5/npm/README.md +++ b/samples/client/petstore/typescript-angular-v5/npm/README.md @@ -151,6 +151,53 @@ export class AppModule {} ``` +### Set dynamic service base path +If required the base path can be modified throughout the lifecycle of the +service by injecting an `Observable` using the `BASE_PATH_OBSERVABLE` token. + + +``` +import { BASE_PATH_OBSERVABLE } from '@swagger/angular2-typescript-petstore'; + +@NgModule({ + imports: [], + declarations: [ AppComponent ], + providers: [ + DynamicBasePathService, + { + provide: BASE_PATH_OBSERVABLE, + useFactory: () => new BehaviorSubject<string>('http://localhost:5000') + } + ], + bootstrap: [ AppComponent ] +}) +export class AppModule {} + +``` + +An example service defined below allows publishing new basePaths to the api services + +``` + +import {Inject, Injectable} from '@angular/core'; +import {Subject} from 'rxjs/Subject'; +import {BASE_PATH_OBSERVABLE} from '@swagger/angular2-typescript-petstore'; + +@Injectable() +export class DynamicBasePathService { + + constructor(@Inject(BASE_PATH_OBSERVABLE) private basePathSubject$: Subject<string>) { + } + + public setBasePath(basePath: string): void { + this.basePathSubject$.next(basePath); + } + +} + +``` + + #### Using @angular/cli First extend your `src/environments/*.ts` files by adding the corresponding base path: diff --git a/samples/client/petstore/typescript-angular-v5/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v5/npm/api/pet.service.ts index 18563adb1b3..99017ffe27f 100644 --- a/samples/client/petstore/typescript-angular-v5/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v5/npm/api/pet.service.ts @@ -21,7 +21,7 @@ import { Observable } from 'rxjs/Observab import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -32,7 +32,10 @@ export class PetService { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -40,6 +43,9 @@ export class PetService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v5/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v5/npm/api/store.service.ts index 03016b73c9d..3372180d555 100644 --- a/samples/client/petstore/typescript-angular-v5/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v5/npm/api/store.service.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs/Observab import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -31,7 +31,10 @@ export class StoreService { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -39,6 +42,9 @@ export class StoreService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v5/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v5/npm/api/user.service.ts index 7c7ccda2a79..9a63ef74fa2 100644 --- a/samples/client/petstore/typescript-angular-v5/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v5/npm/api/user.service.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs/Observab import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -31,7 +31,10 @@ export class UserService { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -39,6 +42,9 @@ export class UserService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v5/npm/variables.ts b/samples/client/petstore/typescript-angular-v5/npm/variables.ts index 6fe58549f39..cb71ffc8be1 100644 --- a/samples/client/petstore/typescript-angular-v5/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v5/npm/variables.ts @@ -1,6 +1,8 @@ import { InjectionToken } from '@angular/core'; +import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new InjectionToken('basePath'); +export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v5/with-interfaces/README.md b/samples/client/petstore/typescript-angular-v5/with-interfaces/README.md index b5a6ac2a8b8..1c867e21151 100644 --- a/samples/client/petstore/typescript-angular-v5/with-interfaces/README.md +++ b/samples/client/petstore/typescript-angular-v5/with-interfaces/README.md @@ -151,6 +151,53 @@ export class AppModule {} ``` +### Set dynamic service base path +If required the base path can be modified throughout the lifecycle of the +service by injecting an `Observable` using the `BASE_PATH_OBSERVABLE` token. + + +``` +import { BASE_PATH_OBSERVABLE } from '@swagger/angular2-typescript-petstore'; + +@NgModule({ + imports: [], + declarations: [ AppComponent ], + providers: [ + DynamicBasePathService, + { + provide: BASE_PATH_OBSERVABLE, + useFactory: () => new BehaviorSubject<string>('http://localhost:5000') + } + ], + bootstrap: [ AppComponent ] +}) +export class AppModule {} + +``` + +An example service defined below allows publishing new basePaths to the api services + +``` + +import {Inject, Injectable} from '@angular/core'; +import {Subject} from 'rxjs/Subject'; +import {BASE_PATH_OBSERVABLE} from '@swagger/angular2-typescript-petstore'; + +@Injectable() +export class DynamicBasePathService { + + constructor(@Inject(BASE_PATH_OBSERVABLE) private basePathSubject$: Subject<string>) { + } + + public setBasePath(basePath: string): void { + this.basePathSubject$.next(basePath); + } + +} + +``` + + #### Using @angular/cli First extend your `src/environments/*.ts` files by adding the corresponding base path: diff --git a/samples/client/petstore/typescript-angular-v5/with-interfaces/api/pet.service.ts b/samples/client/petstore/typescript-angular-v5/with-interfaces/api/pet.service.ts index f7a5a17785d..4cee12634ed 100644 --- a/samples/client/petstore/typescript-angular-v5/with-interfaces/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v5/with-interfaces/api/pet.service.ts @@ -21,7 +21,7 @@ import { Observable } from 'rxjs/Observab import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; import { PetServiceInterface } from './pet.serviceInterface'; @@ -33,7 +33,10 @@ export class PetService implements PetServiceInterface { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -41,6 +44,9 @@ export class PetService implements PetServiceInterface { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v5/with-interfaces/api/store.service.ts b/samples/client/petstore/typescript-angular-v5/with-interfaces/api/store.service.ts index 233e257c2fa..e4a0f55f9c6 100644 --- a/samples/client/petstore/typescript-angular-v5/with-interfaces/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v5/with-interfaces/api/store.service.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs/Observab import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; import { StoreServiceInterface } from './store.serviceInterface'; @@ -32,7 +32,10 @@ export class StoreService implements StoreServiceInterface { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -40,6 +43,9 @@ export class StoreService implements StoreServiceInterface { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v5/with-interfaces/api/user.service.ts b/samples/client/petstore/typescript-angular-v5/with-interfaces/api/user.service.ts index b6e09b12657..9d58e316eaa 100644 --- a/samples/client/petstore/typescript-angular-v5/with-interfaces/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v5/with-interfaces/api/user.service.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs/Observab import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; import { UserServiceInterface } from './user.serviceInterface'; @@ -32,7 +32,10 @@ export class UserService implements UserServiceInterface { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -40,6 +43,9 @@ export class UserService implements UserServiceInterface { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v5/with-interfaces/variables.ts b/samples/client/petstore/typescript-angular-v5/with-interfaces/variables.ts index 6fe58549f39..cb71ffc8be1 100644 --- a/samples/client/petstore/typescript-angular-v5/with-interfaces/variables.ts +++ b/samples/client/petstore/typescript-angular-v5/with-interfaces/variables.ts @@ -1,6 +1,8 @@ import { InjectionToken } from '@angular/core'; +import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new InjectionToken('basePath'); +export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/samples/client/petstore/typescript-angular-v6/npm/README.md b/samples/client/petstore/typescript-angular-v6/npm/README.md index b5a6ac2a8b8..1c867e21151 100644 --- a/samples/client/petstore/typescript-angular-v6/npm/README.md +++ b/samples/client/petstore/typescript-angular-v6/npm/README.md @@ -151,6 +151,53 @@ export class AppModule {} ``` +### Set dynamic service base path +If required the base path can be modified throughout the lifecycle of the +service by injecting an `Observable` using the `BASE_PATH_OBSERVABLE` token. + + +``` +import { BASE_PATH_OBSERVABLE } from '@swagger/angular2-typescript-petstore'; + +@NgModule({ + imports: [], + declarations: [ AppComponent ], + providers: [ + DynamicBasePathService, + { + provide: BASE_PATH_OBSERVABLE, + useFactory: () => new BehaviorSubject<string>('http://localhost:5000') + } + ], + bootstrap: [ AppComponent ] +}) +export class AppModule {} + +``` + +An example service defined below allows publishing new basePaths to the api services + +``` + +import {Inject, Injectable} from '@angular/core'; +import {Subject} from 'rxjs/Subject'; +import {BASE_PATH_OBSERVABLE} from '@swagger/angular2-typescript-petstore'; + +@Injectable() +export class DynamicBasePathService { + + constructor(@Inject(BASE_PATH_OBSERVABLE) private basePathSubject$: Subject<string>) { + } + + public setBasePath(basePath: string): void { + this.basePathSubject$.next(basePath); + } + +} + +``` + + #### Using @angular/cli First extend your `src/environments/*.ts` files by adding the corresponding base path: diff --git a/samples/client/petstore/typescript-angular-v6/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v6/npm/api/pet.service.ts index d62314aefe5..e658e0a3485 100644 --- a/samples/client/petstore/typescript-angular-v6/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v6/npm/api/pet.service.ts @@ -21,7 +21,7 @@ import { Observable } from 'rxjs'; import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -32,7 +32,10 @@ export class PetService { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -40,6 +43,9 @@ export class PetService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v6/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v6/npm/api/store.service.ts index c8e83fb6416..8b342ece073 100644 --- a/samples/client/petstore/typescript-angular-v6/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v6/npm/api/store.service.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs'; import { Order } from '../model/order'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -31,7 +31,10 @@ export class StoreService { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -39,6 +42,9 @@ export class StoreService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v6/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v6/npm/api/user.service.ts index c6ea28aa921..761914ed4d9 100644 --- a/samples/client/petstore/typescript-angular-v6/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v6/npm/api/user.service.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs'; import { User } from '../model/user'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH, COLLECTION_FORMATS, BASE_PATH_OBSERVABLE } from '../variables'; import { Configuration } from '../configuration'; @@ -31,7 +31,10 @@ export class UserService { public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string, + @Optional() configuration: Configuration, + @Optional() @Inject(BASE_PATH_OBSERVABLE) basePath$: Observable) { if (basePath) { this.basePath = basePath; } @@ -39,6 +42,9 @@ export class UserService { this.configuration = configuration; this.basePath = basePath || configuration.basePath || this.basePath; } + if (basePath$) { + basePath$.subscribe(nextBasePath => this.basePath = nextBasePath); + } } /** diff --git a/samples/client/petstore/typescript-angular-v6/npm/variables.ts b/samples/client/petstore/typescript-angular-v6/npm/variables.ts index 6fe58549f39..cb71ffc8be1 100644 --- a/samples/client/petstore/typescript-angular-v6/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v6/npm/variables.ts @@ -1,6 +1,8 @@ import { InjectionToken } from '@angular/core'; +import {Observable} from 'rxjs/Observable'; export const BASE_PATH = new InjectionToken('basePath'); +export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', From 3574599d88389839e8c9bfe961595bf1f1288ef2 Mon Sep 17 00:00:00 2001 From: Chris Mellard Date: Sun, 13 May 2018 21:36:40 +1200 Subject: [PATCH 5/6] Issue7949 - Fixing up rxjs Observable import that was failing under latest rxjs package/angular6 --- .../src/main/resources/typescript-angular/variables.mustache | 2 +- .../client/petstore/typescript-angular-v2/default/variables.ts | 2 +- samples/client/petstore/typescript-angular-v2/npm/variables.ts | 2 +- .../petstore/typescript-angular-v2/with-interfaces/variables.ts | 2 +- .../client/petstore/typescript-angular-v4.3/npm/variables.ts | 2 +- .../typescript-angular-v4.3/with-interfaces/variables.ts | 2 +- samples/client/petstore/typescript-angular-v4/npm/variables.ts | 2 +- samples/client/petstore/typescript-angular-v5/npm/variables.ts | 2 +- .../petstore/typescript-angular-v5/with-interfaces/variables.ts | 2 +- samples/client/petstore/typescript-angular-v6/npm/variables.ts | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/variables.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/variables.mustache index a89ca2746ba..7f31b2652bd 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular/variables.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/variables.mustache @@ -1,5 +1,5 @@ import { {{injectionToken}} } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; export const BASE_PATH = new {{injectionToken}}{{#injectionTokenTyped}}{{/injectionTokenTyped}}('basePath'); export const BASE_PATH_OBSERVABLE = new {{injectionToken}}{{#injectionTokenTyped}}>{{/injectionTokenTyped}}('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v2/default/variables.ts b/samples/client/petstore/typescript-angular-v2/default/variables.ts index 8011aa27fee..80ed05bf398 100644 --- a/samples/client/petstore/typescript-angular-v2/default/variables.ts +++ b/samples/client/petstore/typescript-angular-v2/default/variables.ts @@ -1,5 +1,5 @@ import { OpaqueToken } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; export const BASE_PATH = new OpaqueToken('basePath'); export const BASE_PATH_OBSERVABLE = new OpaqueToken('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v2/npm/variables.ts b/samples/client/petstore/typescript-angular-v2/npm/variables.ts index 8011aa27fee..80ed05bf398 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/variables.ts @@ -1,5 +1,5 @@ import { OpaqueToken } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; export const BASE_PATH = new OpaqueToken('basePath'); export const BASE_PATH_OBSERVABLE = new OpaqueToken('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts index 8011aa27fee..80ed05bf398 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts @@ -1,5 +1,5 @@ import { OpaqueToken } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; export const BASE_PATH = new OpaqueToken('basePath'); export const BASE_PATH_OBSERVABLE = new OpaqueToken('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts b/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts index cb71ffc8be1..4a32bcf3ec3 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts @@ -1,5 +1,5 @@ import { InjectionToken } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; export const BASE_PATH = new InjectionToken('basePath'); export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/variables.ts b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/variables.ts index cb71ffc8be1..4a32bcf3ec3 100644 --- a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/variables.ts +++ b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/variables.ts @@ -1,5 +1,5 @@ import { InjectionToken } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; export const BASE_PATH = new InjectionToken('basePath'); export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v4/npm/variables.ts b/samples/client/petstore/typescript-angular-v4/npm/variables.ts index cb71ffc8be1..4a32bcf3ec3 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/variables.ts @@ -1,5 +1,5 @@ import { InjectionToken } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; export const BASE_PATH = new InjectionToken('basePath'); export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v5/npm/variables.ts b/samples/client/petstore/typescript-angular-v5/npm/variables.ts index cb71ffc8be1..4a32bcf3ec3 100644 --- a/samples/client/petstore/typescript-angular-v5/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v5/npm/variables.ts @@ -1,5 +1,5 @@ import { InjectionToken } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; export const BASE_PATH = new InjectionToken('basePath'); export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v5/with-interfaces/variables.ts b/samples/client/petstore/typescript-angular-v5/with-interfaces/variables.ts index cb71ffc8be1..4a32bcf3ec3 100644 --- a/samples/client/petstore/typescript-angular-v5/with-interfaces/variables.ts +++ b/samples/client/petstore/typescript-angular-v5/with-interfaces/variables.ts @@ -1,5 +1,5 @@ import { InjectionToken } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; export const BASE_PATH = new InjectionToken('basePath'); export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v6/npm/variables.ts b/samples/client/petstore/typescript-angular-v6/npm/variables.ts index cb71ffc8be1..4a32bcf3ec3 100644 --- a/samples/client/petstore/typescript-angular-v6/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v6/npm/variables.ts @@ -1,5 +1,5 @@ import { InjectionToken } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; export const BASE_PATH = new InjectionToken('basePath'); export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); From 130f2b205e6c2c860708ae0656aa4803bb17e82b Mon Sep 17 00:00:00 2001 From: Chris Mellard Date: Sun, 13 May 2018 21:53:49 +1200 Subject: [PATCH 6/6] Issue7949 - Fixing up rxjs Observable import --- .../main/resources/typescript-angular/variables.mustache | 8 +++++++- .../petstore/typescript-angular-v2/default/variables.ts | 3 ++- .../petstore/typescript-angular-v2/npm/variables.ts | 3 ++- .../typescript-angular-v2/with-interfaces/variables.ts | 3 ++- .../petstore/typescript-angular-v4.3/npm/variables.ts | 3 ++- .../typescript-angular-v4.3/with-interfaces/variables.ts | 3 ++- .../petstore/typescript-angular-v4/npm/variables.ts | 3 ++- .../petstore/typescript-angular-v5/npm/variables.ts | 3 ++- .../typescript-angular-v5/with-interfaces/variables.ts | 3 ++- .../petstore/typescript-angular-v6/npm/variables.ts | 3 ++- 10 files changed, 25 insertions(+), 10 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/variables.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/variables.mustache index 7f31b2652bd..cd009fc82d2 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular/variables.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/variables.mustache @@ -1,5 +1,11 @@ import { {{injectionToken}} } from '@angular/core'; -import {Observable} from 'rxjs'; + +{{^useRxJS6}} +import { Observable } from 'rxjs/Observable'; +{{/useRxJS6}} +{{#useRxJS6}} +import { Observable } from 'rxjs'; +{{/useRxJS6}} export const BASE_PATH = new {{injectionToken}}{{#injectionTokenTyped}}{{/injectionTokenTyped}}('basePath'); export const BASE_PATH_OBSERVABLE = new {{injectionToken}}{{#injectionTokenTyped}}>{{/injectionTokenTyped}}('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v2/default/variables.ts b/samples/client/petstore/typescript-angular-v2/default/variables.ts index 80ed05bf398..bd349d22a04 100644 --- a/samples/client/petstore/typescript-angular-v2/default/variables.ts +++ b/samples/client/petstore/typescript-angular-v2/default/variables.ts @@ -1,5 +1,6 @@ import { OpaqueToken } from '@angular/core'; -import {Observable} from 'rxjs'; + +import { Observable } from 'rxjs/Observable'; export const BASE_PATH = new OpaqueToken('basePath'); export const BASE_PATH_OBSERVABLE = new OpaqueToken('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v2/npm/variables.ts b/samples/client/petstore/typescript-angular-v2/npm/variables.ts index 80ed05bf398..bd349d22a04 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/variables.ts @@ -1,5 +1,6 @@ import { OpaqueToken } from '@angular/core'; -import {Observable} from 'rxjs'; + +import { Observable } from 'rxjs/Observable'; export const BASE_PATH = new OpaqueToken('basePath'); export const BASE_PATH_OBSERVABLE = new OpaqueToken('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts index 80ed05bf398..bd349d22a04 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/variables.ts @@ -1,5 +1,6 @@ import { OpaqueToken } from '@angular/core'; -import {Observable} from 'rxjs'; + +import { Observable } from 'rxjs/Observable'; export const BASE_PATH = new OpaqueToken('basePath'); export const BASE_PATH_OBSERVABLE = new OpaqueToken('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts b/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts index 4a32bcf3ec3..6adbee1db22 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts @@ -1,5 +1,6 @@ import { InjectionToken } from '@angular/core'; -import {Observable} from 'rxjs'; + +import { Observable } from 'rxjs/Observable'; export const BASE_PATH = new InjectionToken('basePath'); export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/variables.ts b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/variables.ts index 4a32bcf3ec3..6adbee1db22 100644 --- a/samples/client/petstore/typescript-angular-v4.3/with-interfaces/variables.ts +++ b/samples/client/petstore/typescript-angular-v4.3/with-interfaces/variables.ts @@ -1,5 +1,6 @@ import { InjectionToken } from '@angular/core'; -import {Observable} from 'rxjs'; + +import { Observable } from 'rxjs/Observable'; export const BASE_PATH = new InjectionToken('basePath'); export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v4/npm/variables.ts b/samples/client/petstore/typescript-angular-v4/npm/variables.ts index 4a32bcf3ec3..6adbee1db22 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/variables.ts @@ -1,5 +1,6 @@ import { InjectionToken } from '@angular/core'; -import {Observable} from 'rxjs'; + +import { Observable } from 'rxjs/Observable'; export const BASE_PATH = new InjectionToken('basePath'); export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v5/npm/variables.ts b/samples/client/petstore/typescript-angular-v5/npm/variables.ts index 4a32bcf3ec3..6adbee1db22 100644 --- a/samples/client/petstore/typescript-angular-v5/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v5/npm/variables.ts @@ -1,5 +1,6 @@ import { InjectionToken } from '@angular/core'; -import {Observable} from 'rxjs'; + +import { Observable } from 'rxjs/Observable'; export const BASE_PATH = new InjectionToken('basePath'); export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v5/with-interfaces/variables.ts b/samples/client/petstore/typescript-angular-v5/with-interfaces/variables.ts index 4a32bcf3ec3..6adbee1db22 100644 --- a/samples/client/petstore/typescript-angular-v5/with-interfaces/variables.ts +++ b/samples/client/petstore/typescript-angular-v5/with-interfaces/variables.ts @@ -1,5 +1,6 @@ import { InjectionToken } from '@angular/core'; -import {Observable} from 'rxjs'; + +import { Observable } from 'rxjs/Observable'; export const BASE_PATH = new InjectionToken('basePath'); export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable'); diff --git a/samples/client/petstore/typescript-angular-v6/npm/variables.ts b/samples/client/petstore/typescript-angular-v6/npm/variables.ts index 4a32bcf3ec3..fc3e7860a0a 100644 --- a/samples/client/petstore/typescript-angular-v6/npm/variables.ts +++ b/samples/client/petstore/typescript-angular-v6/npm/variables.ts @@ -1,5 +1,6 @@ import { InjectionToken } from '@angular/core'; -import {Observable} from 'rxjs'; + +import { Observable } from 'rxjs'; export const BASE_PATH = new InjectionToken('basePath'); export const BASE_PATH_OBSERVABLE = new InjectionToken>('basePathObservable');