-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathangularClient.hbs
More file actions
38 lines (32 loc) · 1.29 KB
/
angularClient.hbs
File metadata and controls
38 lines (32 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
{{#each components}}
import { {{@key}} } from '../interfaces/{{@key}}.ts';
{{/each}}
{{#if description}}
/**
{{description}}
*/
{{/if}}
@Injectable({
providedIn: 'root'
})
export class {{tagname}}Service {
private servers: string[] = [
{{#servers}}
'{{{url}}}',
{{/servers}}
]
private readonly headers: HttpHeaders = new HttpHeaders();
constructor(private http: HttpClient) {
this.headers = this.headers.set('Content-Type', 'application/json');
}
{{#paths}}
{{#methods}}
public {{#if operationId}}{{{operationId}}}{{else}}{{methodName}}{{capitalize (removeSymbol ../route)}}{{/if}}({{#parameters}}{{name}}: {{type}}, {{/parameters}}{{#with requestBody.content.[application/json]}}body: {{{getType this.type}}}{{/with}}){{#responses}}{{#with content.[application/json]}}: Observable<{{getType type}}>{{/with}}{{/responses}} {
return this.http.{{methodName}}{{#responses}}{{#with content.[application/json]}}<{{getType type}}>{{/with}}{{/responses}}(`{{{../route}}}`{{#requestBody}}, body{{/requestBody}}{{#unless requestBody}}, null{{/unless}}, { headers: this.headers });
}
{{/methods}}
{{/paths}}
}