swagger-angular-generator icon indicating copy to clipboard operation
swagger-angular-generator copied to clipboard

Make base path of endpoints injectable and use schema + domain + baseUrl as default value

Open leiserfg opened this issue 7 years ago • 2 comments

Something like


@Injectable()
export class CareerService {
  constructor(private http: HttpClient, @Inject(URL) baseUrl: string='http://localhost/api/') {}
.....
positions(params: PositionsParams): Observable<object> {
    const pathParams = {
      positionId: params.positionId,
      version: params.version
    }
    return this.http.get<object>(
      `${this.baseUrl}/api/career/v${pathParams.version}/positions/${pathParams.positionId}`
    )
  }

And in def add a file with:

import { InjectionToken } from '@angular/core';
export const URL = new InjectionToken<string>('baseUrl');

leiserfg avatar Feb 19 '18 20:02 leiserfg

@leiserfg, thanks for the idea. Btw, you are welcome to make a PR (incl. docs update demonstrating the usage), if you want to have it done faster.

jnwltr avatar Feb 20 '18 12:02 jnwltr

Currently the ad hoc (env-based) configuration can by done via interceptors, which are typically used also for authentication, e.g.

jnwltr avatar Feb 20 '18 12:02 jnwltr