@automatons/typescript-client-axios 1.0.3 → 1.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automatons/typescript-client-axios",
3
- "version": "1.0.3",
3
+ "version": "1.0.7",
4
4
  "repository": "git@github.com:openapi-automatons/typescript-client-axios.git",
5
5
  "author": "tanmen <yt.prog@gmail.com>",
6
6
  "license": "MIT",
@@ -6,9 +6,7 @@ import { Config{{#if securities}}, Security{{/if}} } from "../config";
6
6
  import { {{#if hasTemplate}}template{{#or hasQuery hasFormData}},{{/or}}{{/if}} {{#if hasQuery}}query{{#if hasFormData}},{{/if}}{{/if}} {{#if hasFormData}}formData{{/if}} } from "../utils";
7
7
  {{/or}}
8
8
  {{/with}}
9
- {{#each api/imports~}}
10
- import { {{title}} } from "../models";
11
- {{/each}}
9
+ import { {{#each api/imports~}} {{title}}{{#unless @last}}, {{/unless}}{{/each}} } from "../models";
12
10
 
13
11
  {{#each api/servers}}
14
12
  type {{name}}Server = { name: "{{name}}"{{#if values}}; values: { {{#each values}}{{name}}: {{#if enums}}{{#each enums}}'{{this}}'{{#unless @last}} | {{/unless}}{{/each}}{{else}}string{{/if}} {{/each}} }; {{/if}} }
@@ -4,7 +4,7 @@ public async {{name}}({{> apis/config/arguments}}): Promise<AxiosRequestConfig>
4
4
  let _cookies = config?.headers?.Cookie ?? '';
5
5
  {{> apis/config/request/cookies }}
6
6
 
7
- const _headers = { ...config?.headers, 'Content-Type': headers['Content-Type'], Cookie: _cookies || undefined };
7
+ const _headers = Object.assign({ ...config?.headers, 'Content-Type': headers['Content-Type']}, _cookies ? {Cookie: _cookies} : undefined);
8
8
  {{> apis/config/request/headers }}
9
9
 
10
10
  return {
@@ -1,4 +1,9 @@
1
- import {ParsedUrlQueryInput} from 'querystring';
1
+ type ParsedUrlQueryInput = NodeJS.Dict<string | number | boolean | ReadonlyArray<string> | ReadonlyArray<number> | ReadonlyArray<boolean> | null>
2
+
3
+ const isObject = (value: any): value is object => {
4
+ const type = typeof value
5
+ return value != null && (type == 'object' || type == 'function')
6
+ }
2
7
 
3
8
  const queryForm =
4
9
  (name: string,
@@ -10,7 +15,7 @@ const queryForm =
10
15
  } else {
11
16
  return {[name]: value.join(',')}
12
17
  }
13
- } else if (value instanceof Object) {
18
+ } else if (isObject(value)) {
14
19
  if (explode) {
15
20
  return value;
16
21
  } else {
@@ -26,7 +31,7 @@ const querySpaceDelimited =
26
31
  value: string | number | Array<string | number> | { [key: string]: string | number }): ParsedUrlQueryInput => {
27
32
  if (Array.isArray(value)) {
28
33
  return {[name]: value.join(' ')}
29
- } else if (value instanceof Object) {
34
+ } else if (isObject(value)) {
30
35
  return {[name]: Object.entries(value).map((prop: [string, string | number]) => prop.join(' ')).join(' ')}
31
36
  }
32
37
  throw new Error(`Unsupported value: ${name}`);
@@ -37,7 +42,7 @@ const queryPipeDelimited =
37
42
  value: string | number | Array<string | number> | { [key: string]: string | number }): ParsedUrlQueryInput => {
38
43
  if (Array.isArray(value)) {
39
44
  return {[name]: value.join('|')}
40
- } else if (value instanceof Object) {
45
+ } else if (isObject(value)) {
41
46
  return {[name]: Object.entries(value).map((prop: [string, string | number]) => prop.join('|')).join('|')}
42
47
  }
43
48
  throw new Error(`Unsupported value: ${name}`);
@@ -46,7 +51,7 @@ const queryPipeDelimited =
46
51
  const queryDeepObject =
47
52
  (name: string,
48
53
  value: string | number | Array<string | number> | { [key: string]: string | number }): ParsedUrlQueryInput => {
49
- if (!Array.isArray(value) && value instanceof Object) {
54
+ if (!Array.isArray(value) && isObject(value)) {
50
55
  return Object.keys(value).reduce((pre, cur) => ({...pre, [`${name}[${cur}]`]: value[cur]}), {});
51
56
  }
52
57
  throw new Error(`Unsupported value: ${name}`);