-
Notifications
You must be signed in to change notification settings - Fork 1
Angular 1.5
Swaggen will generate 2 Typescript files:
- MyAPIClient.ts: The file containing your client.
- clientConfigurationService.ts: This file contains a class which exposes 3 methods to edit to configure your apiClient.
Here are the 3 methods exposed by this file that you can edit.
// Edit this function to give the api client the api hostname
public getApiHostname(): string {
return 'badhostname.com';
}
// Edit this function if you want to modify the requestParams at each api call (optional)
// We use it for example to send the app SemVer in the headers to get the right data model for different app versions
public requestParamsGlobalHook(httpRequestParams: any): any {
return httpRequestParams;
}
// Edit this function to authenticate requests that need an authentication (optional)
public authenticateRequest(httpRequestParams: any): any {
// httpRequestParams.headers['Authorization'] = 'Bearer ' + this.currentAccessToken;
console.log("this requests needs an authentication. Override the ClientConfigurationService to configure it");
return httpRequestParams;
}
The angular version has 2 modes available (You can specify the mode in the config json):
This will generate the 2 files. You will need to add the 2 services to your application module.
"templateOptions": {
"clientName": "MyAPIClient",
"scheme": {
"override": "https"
},
"generateInterface": true
}
- clientName: The name of the generated file and of the generated class.
- scheme: Override the api scheme.
- generateInterface Generate the client class Interface to have autocompletion in Typescript.
This will generate an additional file : package.json defining an npm package.
It is also slightly different from the normal mode in the way it has to be used. The MyAPIClient.ts
file will define an Angular module named after the packageName
option. You will need to load this module in your application module and of course, import the file.
The purpose of this mode is to automatically generate the client each time the api is updated and put it on a private npm flow. In this case, you won't be able to modify the clientConfigurationService.ts file directly in the node_module directory. You will need to create your own one and override the default one in the config phase:
$provide.service('clientConfigurationService', MyClientConfigurationService);
"templateOptions": {
"clientName": "MyAPIClient",
"packageName": "my-api-client",
"scheme": {
"override": "https"
},
"generateInterface": true,
"projectProperties": [
{
"name": "author",
"value": "me"
},
{
"name": "description",
"value": "Client library to consume My API."
}]
}
- packageName: The name of the generated package.json file and of angular module to load.
- projectProperties: These properties will be added to the pacakge.json file.
- Home
- Jane's story
- Templates
- Csharp
- Angular
- Customization
- Custom Templates
- Custom Languages