swagger-angular-generator
swagger-angular-generator copied to clipboard
Make base path of endpoints injectable and use schema + domain + baseUrl as default value
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, 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.
Currently the ad hoc (env-based) configuration can by done via interceptors, which are typically used also for authentication, e.g.