@dazhicheng/openapi 1.1.6 → 1.1.7

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.
@@ -6,7 +6,7 @@
6
6
  /** {{ api.desc if api.desc else '此处后端没有提供注释' }} {{api.method | upper}} {{ api.pathInComment | safe }} */
7
7
  export async function {{ api.functionName }}(
8
8
  {%- if api.body -%}
9
- params
9
+ body
10
10
  {%- if genType === "ts" -%}
11
11
  : {% if api.body.propertiesList %}{
12
12
  {%- for prop in api.body.propertiesList %}
@@ -19,11 +19,12 @@ export async function {{ api.functionName }}(
19
19
  {%- else -%}
20
20
  {{ api.body.type }}
21
21
  {%- endif -%}
22
- {%- if api.params and api.params.path and api.params.path.length -%}
22
+ {%- if api.params and api.hasParams -%}
23
23
  & {{namespace}}.{{api.typeName}}
24
24
  {%- endif -%}
25
25
  {%- endif -%}
26
- {%- elif api.params and api.hasParams -%}
26
+ {%- endif -%}
27
+ {%- if not api.body and api.params and api.hasParams -%}
27
28
  params
28
29
  {%- if genType === "ts" -%}
29
30
  : {{namespace}}.{{api.typeName}}
@@ -38,15 +39,37 @@ export async function {{ api.functionName }}(
38
39
  options
39
40
  {%- endif -%}
40
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 %}
41
45
  {%- if api.params and api.params.path and api.params.path.length %}
46
+ {%- if not api.body %}
42
47
  const { {% for p in api.params.path %}{{ p.name }}{{ ", " if not loop.last }}{% endfor %} } = params;
48
+ {%- endif %}
43
49
  {%- endif %}
44
50
  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,
51
+ url: {{ ("`" + api.path | safe + "`") }},
52
+ {%- if api.params and api.hasParams and not api.body %}
53
+ params: {
54
+ {%- for query in api.params.query %}
55
+ {% if query.schema.default -%}
56
+ // {{query.name | safe}} has a default value: {{ query.schema.default | safe }}
57
+ '{{query.name | safe}}': '{{query.schema.default | safe}}',
58
+ {%- endif -%}
59
+ {%- endfor -%}
60
+ ...{{ 'params' }},
61
+ {%- for query in api.params.query %}
62
+ {%- if query.isComplexType %}
63
+ '{{query.name | safe}}': undefined,
64
+ ...{{ 'params' }}['{{query.name | safe}}'],
65
+ {%- endif %}
66
+ {%- endfor -%}
67
+ },
68
+ {%- endif %}
69
+ {%- if api.body %}
70
+ data: body,
48
71
  {%- endif %}
49
- ...(options ?? {}),
72
+ ...(options || {}),
50
73
  });
51
74
  }
52
75