-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.handlebars
More file actions
121 lines (111 loc) · 2.88 KB
/
api.handlebars
File metadata and controls
121 lines (111 loc) · 2.88 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
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
// tslint:disable
/**
* 文件由openapi-parser-shark自动生成,尽量不要手动修改。
* 文件中出现类似StandardModel$2a327e1b,这种以$+hash码结尾的变量名,
* 说明swagger文档不规范,这里为了保证代码正确,用hash避免了,更好方案
* 应该是联系文档输出人,修正文档。
* 文档源:{{> getFileSource}}
*/
import { AxiosInstance } from 'axios';
import fetch from '{{> servicePath}}';
{{#each components.schemas}}
/**
* @summary {{> getOriginalProp @key}}
{{#if this.enum}}
* @enum {{@key}}
{{/if}}
{{#unless this.enum}}
* @interface {{@key}}
{{/unless}}
*/
{{#if this.enum}}
export enum {{@key}} {
{{#each this.enum}}
{{this}}='{{this}}',
{{/each}}
}
{{/if}}
{{#unless this.enum}}
export interface {{@key}} {
{{#each this.properties}}
/**
* {{this.description}}
* @type { {{> transformSchema this}} }
* @memberof {{@../key}}
*/
['{{@key}}']{{> isRequired source=../this.required target=@key}}:{{> transformSchema this}};
{{/each}}
}
{{/unless}}
{{/each}}
{{#each components.requestBodies}}
{{#if (isRef content)}}
{{#unless (isTypeNameEqual @key content)}}
/**
* @summary {{> getOriginalProp @key}}
* @interface {{@key}}
* @description {{description}}
* @required {{required}}
*/
export type {{@key}} = {{> linkRef content}}
{{/unless}}
{{else}}
{{/if}}
{{#unless (isRef content)}}
{{#if this.enum}}
/**
* @summary {{> getOriginalProp @key}}
* @interface {{@key}}
* @description {{description}}
* @required {{required}}
*/
export enum {{@key}} {
{{#each this.enum}}
{{this}}='{{this}}',
{{/each}}
}
{{/if}}
{{#unless this.enum}}
/**
* @summary {{> getOriginalProp @key}}
* @interface {{@key}}
* @description {{description}}
* @required {{required}}
*/
export interface {{@key}} {
{{#each this.properties}}
/**
* {{this.description}}
* @type { {{> transformSchema this}} }
* @memberof {{@../key}}
*/
['{{@key}}']{{> isRequired source=../this.required target=@key}}:{{> transformSchema this}};
{{/each}}
}
{{/unless}}
{{/unless}}
{{/each}}
{{#each paths}}
{{#each this}}
{{#if (isMethod @key)}}
/**
* @tags {{#each tags}}{{this}}{{/each}}
* @summary {{summary}}
{{> getAllParamsComment operationObject=this method=@key}}
* @param {AxiosInstance} local_options
*/
export const {{> generateMethodName path=@../key method=@key}} = async ({{> getAllParams operationObject=this method=@key}}local_options?:AxiosInstance):Promise<{{> responseType responses}}>=>{
let local_url = '{{@../key}}'
{{> getParamsPartial path=@../key operationObject=this method=@key}}
const result = await fetch({
url:local_url,
method:'{{@key}}',
params:local_params,
{{#unless (isSimpleMethod @key)}}data:local_body,{{/unless}}
...(local_options||{})
}) as unknown
return result as Promise<{{> responseType responses}}>
}
{{/if}}
{{/each}}
{{/each}}