@dazhicheng/openapi 1.1.7 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/serviceGenerator.ts +1092 -1092
- package/templates/serviceController.njk +62 -76
|
@@ -1,76 +1,62 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
{{ requestImportStatement }}
|
|
4
|
-
|
|
5
|
-
{% for api in list -%}
|
|
6
|
-
/** {{ api.desc if api.desc else '此处后端没有提供注释' }} {{api.method | upper}} {{ api.pathInComment | safe }} */
|
|
7
|
-
export async function {{ api.functionName }}(
|
|
8
|
-
{%- if api.body -%}
|
|
9
|
-
body
|
|
10
|
-
{%- if genType === "ts" -%}
|
|
11
|
-
: {% if api.body.propertiesList %}{
|
|
12
|
-
{%- for prop in api.body.propertiesList %}
|
|
13
|
-
{% if prop.schema.description -%}
|
|
14
|
-
/** {{ prop.schema.description }} */
|
|
15
|
-
{% endif -%}
|
|
16
|
-
{{ prop.key }}{{ "?" if not prop.schema.required }}: {{ prop.schema.type }},
|
|
17
|
-
{%- endfor %}
|
|
18
|
-
}
|
|
19
|
-
{%- else -%}
|
|
20
|
-
{{ api.body.type }}
|
|
21
|
-
{%- endif -%}
|
|
22
|
-
{%- if api.params and api.hasParams -%}
|
|
23
|
-
& {{namespace}}.{{api.typeName}}
|
|
24
|
-
{%- endif -%}
|
|
25
|
-
{%- endif -%}
|
|
26
|
-
{%- endif -%}
|
|
27
|
-
{%- if not api.body and api.params and api.hasParams -%}
|
|
28
|
-
params
|
|
29
|
-
{%- if genType === "ts" -%}
|
|
30
|
-
: {{namespace}}.{{api.typeName}}
|
|
31
|
-
{%- endif -%}
|
|
32
|
-
{%- endif -%}
|
|
33
|
-
{%- if api.body or (api.params and api.hasParams) -%}
|
|
34
|
-
,
|
|
35
|
-
{%- endif -%}
|
|
36
|
-
{%- if genType === "ts" -%}
|
|
37
|
-
options?: { [key: string]: any }
|
|
38
|
-
{%- else -%}
|
|
39
|
-
options
|
|
40
|
-
{%- endif -%}
|
|
41
|
-
) {
|
|
42
|
-
{%- if api.body and api.params and api.hasParams and api.params.path and api.params.path.length %}
|
|
43
|
-
const { {% for p in api.params.path %}{{ p.name }}{{ ", " if not loop.last }}{% endfor %} } = body;
|
|
44
|
-
{%- endif %}
|
|
45
|
-
{%- if api.params and api.params.path and api.params.path.length %}
|
|
46
|
-
{%- if not api.body %}
|
|
47
|
-
const { {% for p in api.params.path %}{{ p.name }}{{ ", " if not loop.last }}{% endfor %} } = params;
|
|
48
|
-
{%- endif %}
|
|
49
|
-
{%- endif %}
|
|
50
|
-
return request.{{ "del" if api.method | lower == "delete" else api.method | lower }}{{ ("<" + api.response.type + ">") | safe if genType === "ts" }}({
|
|
51
|
-
url: {{ ("`" + api.path | safe + "`") }},
|
|
52
|
-
{%- if api.params and api.hasParams and not api.body %}
|
|
53
|
-
params
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
'{{query.name | safe}}': undefined,
|
|
64
|
-
...{{ 'params' }}['{{query.name | safe}}'],
|
|
65
|
-
{%- endif %}
|
|
66
|
-
{%- endfor -%}
|
|
67
|
-
},
|
|
68
|
-
{%- endif %}
|
|
69
|
-
{%- if api.body %}
|
|
70
|
-
data: body,
|
|
71
|
-
{%- endif %}
|
|
72
|
-
...(options || {}),
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
{% endfor -%}
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
{{ requestImportStatement }}
|
|
4
|
+
|
|
5
|
+
{% for api in list -%}
|
|
6
|
+
/** {{ api.desc if api.desc else '此处后端没有提供注释' }} {{api.method | upper}} {{ api.pathInComment | safe }} */
|
|
7
|
+
export async function {{ api.functionName }}(
|
|
8
|
+
{%- if api.body -%}
|
|
9
|
+
body
|
|
10
|
+
{%- if genType === "ts" -%}
|
|
11
|
+
: {% if api.body.propertiesList %}{
|
|
12
|
+
{%- for prop in api.body.propertiesList %}
|
|
13
|
+
{% if prop.schema.description -%}
|
|
14
|
+
/** {{ prop.schema.description }} */
|
|
15
|
+
{% endif -%}
|
|
16
|
+
{{ prop.key }}{{ "?" if not prop.schema.required }}: {{ prop.schema.type }},
|
|
17
|
+
{%- endfor %}
|
|
18
|
+
}
|
|
19
|
+
{%- else -%}
|
|
20
|
+
{{ api.body.type }}
|
|
21
|
+
{%- endif -%}
|
|
22
|
+
{%- if api.params and api.hasParams -%}
|
|
23
|
+
& {{namespace}}.{{api.typeName}}
|
|
24
|
+
{%- endif -%}
|
|
25
|
+
{%- endif -%}
|
|
26
|
+
{%- endif -%}
|
|
27
|
+
{%- if not api.body and api.params and api.hasParams -%}
|
|
28
|
+
params
|
|
29
|
+
{%- if genType === "ts" -%}
|
|
30
|
+
: {{namespace}}.{{api.typeName}}
|
|
31
|
+
{%- endif -%}
|
|
32
|
+
{%- endif -%}
|
|
33
|
+
{%- if api.body or (api.params and api.hasParams) -%}
|
|
34
|
+
,
|
|
35
|
+
{%- endif -%}
|
|
36
|
+
{%- if genType === "ts" -%}
|
|
37
|
+
options?: { [key: string]: any }
|
|
38
|
+
{%- else -%}
|
|
39
|
+
options
|
|
40
|
+
{%- endif -%}
|
|
41
|
+
) {
|
|
42
|
+
{%- if api.body and api.params and api.hasParams and api.params.path and api.params.path.length %}
|
|
43
|
+
const { {% for p in api.params.path %}{{ p.name }}{{ ", " if not loop.last }}{% endfor %} } = body;
|
|
44
|
+
{%- endif %}
|
|
45
|
+
{%- if api.params and api.params.path and api.params.path.length %}
|
|
46
|
+
{%- if not api.body %}
|
|
47
|
+
const { {% for p in api.params.path %}{{ p.name }}{{ ", " if not loop.last }}{% endfor %} } = params;
|
|
48
|
+
{%- endif %}
|
|
49
|
+
{%- endif %}
|
|
50
|
+
return request.{{ "del" if api.method | lower == "delete" else api.method | lower }}{{ ("<" + api.response.type + ">") | safe if genType === "ts" }}({
|
|
51
|
+
url: {{ ("`" + api.path | safe + "`") }},
|
|
52
|
+
{%- if api.params and api.hasParams and not api.body %}
|
|
53
|
+
params,
|
|
54
|
+
{%- endif %}
|
|
55
|
+
{%- if api.body %}
|
|
56
|
+
data: body,
|
|
57
|
+
{%- endif %}
|
|
58
|
+
...(options || {}),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
{% endfor -%}
|