forked from ferdikoomen/openapi-typescript-codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexportService.hbs
150 lines (142 loc) · 3.51 KB
/
exportService.hbs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
{{>header}}
{{#equals @root.httpClient 'angular'}}
{{#if @root.exportClient}}
import { Injectable } from '@angular/core';
import type { Observable } from 'rxjs';
{{else}}
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import type { Observable } from 'rxjs';
{{/if}}
{{/equals}}
{{#if imports}}
{{#each imports}}
import type { {{{this}}} } from '../models/{{{this}}}';
{{/each}}
{{/if}}
{{#notEquals @root.httpClient 'angular'}}
import type { CancelablePromise } from '../core/CancelablePromise';
{{/notEquals}}
{{#if @root.exportClient}}
{{#equals @root.httpClient 'angular'}}
import { BaseHttpRequest } from '../core/BaseHttpRequest';
{{else}}
import type { BaseHttpRequest } from '../core/BaseHttpRequest';
{{/equals}}
{{else}}
import { OpenAPI } from '../core/OpenAPI';
import { request as __request } from '../core/request';
{{/if}}
{{#equals @root.httpClient 'angular'}}
@Injectable()
{{/equals}}
export class {{{name}}}{{{@root.postfix}}} {
{{#if @root.exportClient}}
constructor(public readonly httpRequest: BaseHttpRequest) {}
{{else}}
{{#equals @root.httpClient 'angular'}}
constructor(public readonly http: HttpClient) {}
{{/equals}}
{{/if}}
{{#each operations}}
/**
{{#if deprecated}}
* @deprecated
{{/if}}
{{#if summary}}
* {{{escapeComment summary}}}
{{/if}}
{{#if description}}
* {{{escapeComment description}}}
{{/if}}
{{#unless @root.useOptions}}
{{#if parameters}}
{{#each parameters}}
* @param {{{name}}} {{#if description}}{{{escapeComment description}}}{{/if}}
{{/each}}
{{/if}}
{{/unless}}
{{#each results}}
* @returns {{{type}}} {{#if description}}{{{escapeComment description}}}{{/if}}
{{/each}}
* @throws ApiError
*/
{{#if @root.exportClient}}
{{#equals @root.httpClient 'angular'}}
public {{{name}}}({{>parameters}}): Observable<{{>result}}> {
return this.httpRequest.request({
{{else}}
public {{{name}}}({{>parameters}}): CancelablePromise<{{>result}}> {
return this.httpRequest.request({
{{/equals}}
{{else}}
{{#equals @root.httpClient 'angular'}}
public {{{name}}}({{>parameters}}): Observable<{{>result}}> {
return __request(OpenAPI, this.http, {
{{else}}
public static {{{name}}}({{>parameters}}): CancelablePromise<{{>result}}> {
return __request(OpenAPI, {
{{/equals}}
{{/if}}
method: '{{{method}}}',
url: '{{{path}}}',
{{#if parametersPath}}
path: {
{{#each parametersPath}}
'{{{prop}}}': {{{name}}},
{{/each}}
},
{{/if}}
{{#if parametersCookie}}
cookies: {
{{#each parametersCookie}}
'{{{prop}}}': {{{name}}},
{{/each}}
},
{{/if}}
{{#if parametersHeader}}
headers: {
{{#each parametersHeader}}
'{{{prop}}}': {{{name}}},
{{/each}}
},
{{/if}}
{{#if parametersQuery}}
query: {
{{#each parametersQuery}}
'{{{prop}}}': {{{name}}},
{{/each}}
},
{{/if}}
{{#if parametersForm}}
formData: {
{{#each parametersForm}}
'{{{prop}}}': {{{name}}},
{{/each}}
},
{{/if}}
{{#if parametersBody}}
{{#equals parametersBody.in 'formData'}}
formData: {{{parametersBody.name}}},
{{/equals}}
{{#equals parametersBody.in 'body'}}
body: {{{parametersBody.name}}},
{{/equals}}
{{#if parametersBody.mediaType}}
mediaType: '{{{parametersBody.mediaType}}}',
{{/if}}
{{/if}}
{{#if responseHeader}}
responseHeader: '{{{responseHeader}}}',
{{/if}}
{{#if errors}}
errors: {
{{#each errors}}
{{{code}}}: `{{{escapeDescription description}}}`,
{{/each}}
},
{{/if}}
});
}
{{/each}}
}