@dazhicheng/openapi 1.1.5 → 1.1.6
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/package.json +1 -1
- package/templates/serviceController.njk +53 -44
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,44 +1,53 @@
|
|
|
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
|
-
params
|
|
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.params.path and api.params.path.length -%}
|
|
23
|
-
& {{namespace}}.{{api.typeName}}
|
|
24
|
-
{%- endif -%}
|
|
25
|
-
{%- endif -%}
|
|
26
|
-
{%- elif api.params and api.hasParams -%}
|
|
27
|
-
params
|
|
28
|
-
{%- if genType === "ts" -%}
|
|
29
|
-
: {{namespace}}.{{api.typeName}}
|
|
30
|
-
{%- endif -%}
|
|
31
|
-
{%- endif -%}
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
{%-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
{
|
|
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
|
+
params
|
|
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.params.path and api.params.path.length -%}
|
|
23
|
+
& {{namespace}}.{{api.typeName}}
|
|
24
|
+
{%- endif -%}
|
|
25
|
+
{%- endif -%}
|
|
26
|
+
{%- elif api.params and api.hasParams -%}
|
|
27
|
+
params
|
|
28
|
+
{%- if genType === "ts" -%}
|
|
29
|
+
: {{namespace}}.{{api.typeName}}
|
|
30
|
+
{%- endif -%}
|
|
31
|
+
{%- endif -%}
|
|
32
|
+
{%- if api.body or (api.params and api.hasParams) -%}
|
|
33
|
+
,
|
|
34
|
+
{%- endif -%}
|
|
35
|
+
{%- if genType === "ts" -%}
|
|
36
|
+
options?: { [key: string]: any }
|
|
37
|
+
{%- else -%}
|
|
38
|
+
options
|
|
39
|
+
{%- endif -%}
|
|
40
|
+
) {
|
|
41
|
+
{%- if api.params and api.params.path and api.params.path.length %}
|
|
42
|
+
const { {% for p in api.params.path %}{{ p.name }}{{ ", " if not loop.last }}{% endfor %} } = params;
|
|
43
|
+
{%- endif %}
|
|
44
|
+
return request.{{ "del" if api.method | lower == "delete" else api.method | lower }}{{ ("<" + api.response.type + ">") | safe if genType === "ts" }}({
|
|
45
|
+
url: {{ "`" if api.path and "${" in api.path else "'" }}{{ api.path }}{{ "`" if api.path and "${" in api.path else "'" }},
|
|
46
|
+
{%- if api.body or (api.params and api.hasParams) %}
|
|
47
|
+
{{ "data" if api.method | lower == "delete" else "params" }}: params,
|
|
48
|
+
{%- endif %}
|
|
49
|
+
...(options ?? {}),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
{% endfor -%}
|