@automatons/typescript-client-axios 1.0.1 → 1.0.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/generator/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAE,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAO7D,eAAO,MAAM,QAAQ,YAAmB,OAAO,YAAY,iBAAiB,oBAiC3E,CAAC"}
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/generator/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAE,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAO7D,eAAO,MAAM,QAAQ,YAAmB,OAAO,YAAY,iBAAiB,oBAkC3E,CAAC"}
@@ -20,7 +20,8 @@ const generate = async (openapi, settings) => {
20
20
  promises.push((0, writer_1.write)('apis/index.hbs', [outDir, 'apis', 'index.ts'], apis), (0, writer_1.write)('apis/abstractApi.hbs', [outDir, 'apis', 'abstractApi.ts'], { securities }));
21
21
  promises.push(...apis.map(api => (0, writer_1.write)('apis/api.hbs', [outDir, 'apis', `${api.filename}.ts`], {
22
22
  api,
23
- meta: (0, api_1.extractApiMeta)(api)
23
+ meta: (0, api_1.extractApiMeta)(api),
24
+ securities
24
25
  })));
25
26
  }
26
27
  promises.push((0, writer_1.write)('index.hbs', [outDir, 'index.ts'], { api: apis.length, model: models.length }), (0, writer_1.write)('config.hbs', [outDir, 'config.ts'], { securities }), (0, writer_1.write)('utils/index.hbs', [outDir, 'utils', 'index.ts']), (0, writer_1.write)('utils/template.hbs', [outDir, 'utils', 'template.ts']), (0, writer_1.write)('utils/query.hbs', [outDir, 'utils', 'query.ts']), (0, writer_1.write)('utils/formData.hbs', [outDir, 'utils', 'formData.ts']));
@@ -1 +1 @@
1
- {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/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C,EAAE,EAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAC,CAAC,EAClF,IAAA,cAAK,EAAC,YAAY,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,EAAC,UAAU,EAAC,CAAC,EACxD,IAAA,cAAK,EAAC,iBAAiB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,EACvD,IAAA,cAAK,EAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,EAC7D,IAAA,cAAK,EAAC,iBAAiB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,EACvD,IAAA,cAAK,EAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAC9D,CAAC;IACF,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAC9B,CAAC,CAAC;AAlCW,QAAA,QAAQ,YAkCnB"}
@@ -1 +1 @@
1
- {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/generator/setup.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,KAAK,uBAAmB,CAAC"}
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/generator/setup.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,KAAK,uBAAmB,CAAC"}
@@ -8,10 +8,16 @@ const handlebars_helpers_1 = __importDefault(require("handlebars-helpers"));
8
8
  const handlebars_1 = __importDefault(require("handlebars"));
9
9
  const register_1 = require("./register");
10
10
  handlebars_1.default.registerHelper('every', function (value, key, text) {
11
+ if (!text) {
12
+ return value.every(item => (item[key] == undefined ? false : item[key]));
13
+ }
11
14
  return value.every(item => (item[key] == undefined ? false : item[key]) === text);
12
15
  });
13
- handlebars_1.default.registerHelper('have', function (value, checkers) {
14
- return value.some(item => checkers.every(({ key, text }) => item[key] === text));
16
+ handlebars_1.default.registerHelper('any', function (value, key, text) {
17
+ if (!text) {
18
+ return value.some(item => (item[key] == undefined ? false : item[key]));
19
+ }
20
+ return value.some(item => (item[key] == undefined ? false : item[key]) === text);
15
21
  });
16
22
  (0, handlebars_helpers_1.default)({ handlebars: handlebars_1.default });
17
23
  const setup = () => (0, register_1.register)();
@@ -1 +1 @@
1
- {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/generator/setup.ts"],"names":[],"mappings":";;;;;;AAAA,4EAAyC;AACzC,4DAA4B;AAC5B,yCAAoC;AAEpC,oBAAE,CAAC,cAAc,CAAC,OAAO,EAAE,UAA4B,KAAU,EAAE,GAAY,EAAE,IAAgB;IAC/F,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAA;AACnF,CAAC,CAAC,CAAC;AAEH,oBAAE,CAAC,cAAc,CAAC,MAAM,EAAE,UAA4B,KAAU,EAAE,QAAmD;IACnH,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAC,GAAG,EAAE,IAAI,EAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC;AACjF,CAAC,CAAC,CAAC;AAEH,IAAA,4BAAO,EAAC,EAAC,UAAU,EAAE,oBAAE,EAAC,CAAC,CAAC;AACnB,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,IAAA,mBAAQ,GAAE,CAAC;AAAzB,QAAA,KAAK,SAAoB"}
1
+ {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/generator/setup.ts"],"names":[],"mappings":";;;;;;AAAA,4EAAyC;AACzC,4DAA4B;AAC5B,yCAAoC;AAEpC,oBA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,6 @@
1
1
  {
2
2
  "name": "@automatons/typescript-client-axios",
3
- "version": "1.0.1",
3
+ "version": "1.0.5",
4
4
  "repository": "git@github.com:openapi-automatons/typescript-client-axios.git",
5
5
  "author": "tanmen <yt.prog@gmail.com>",
6
6
  "license": "MIT",
@@ -47,7 +47,7 @@
47
47
  "@types/handlebars-helpers": "^0.5.2",
48
48
  "@types/jest": "^27.4.0",
49
49
  "@types/js-yaml": "^4.0.5",
50
- "@types/node": "^17.0.12",
50
+ "@types/node": "^17.0.13",
51
51
  "@types/prettier": "^2.0.0",
52
52
  "@types/semantic-release": "^17.2.3",
53
53
  "@typescript-eslint/eslint-plugin": "^5.10.1",
@@ -1,5 +1,5 @@
1
1
  import Axios, { AxiosInstance } from "axios";
2
- import { Config{{#if securities.length}}, Security{{/if}} } from "../config";
2
+ import type { Config{{#if securities}}, Security{{/if}} } from "../config";
3
3
 
4
4
  const DateFormat = /^\d{4}-\d{2}-\d{2}([tT]\d{2}:\d{2}:\d{2}(Z|[+-]\d{2}:\d{2})|Z)?$/;
5
5
  const reviver = (_key: string, value: any) =>
@@ -13,13 +13,13 @@ const BASE_AXIOS = Axios.create({
13
13
  * AbstractConfig
14
14
  */
15
15
  export class AbstractConfig {
16
- {{#if securities.length}}
17
- readonly #security?: Security;
16
+ {{#if securities}}
17
+ readonly #security: Security;
18
18
 
19
19
  /**
20
20
  * constructor
21
21
  */
22
- constructor(security?: Security) {
22
+ constructor(security: Security = {}) {
23
23
  this.#security = security;
24
24
  }
25
25
 
@@ -32,12 +32,16 @@ export class AbstractConfig {
32
32
  protected async security(key: "{{name}}"): Promise<string>;
33
33
  {{/and}}
34
34
  {{/each}}
35
- protected async security(key: keyof Security, scopes?: string[]): Promise<string | {username: string; password: string;}> {
36
- const security = this.#security?.[key];
35
+ protected async security(key: keyof Security{{#or (any securities 'type' 'oauth2') (any securities 'type' 'openIdConnect')}}, scopes?: string[]{{/or}}): Promise<string | {username: string; password: string;}> {
36
+ const security = this.#security[key];
37
37
  if (!security) {
38
38
  throw new Error("Unauthorized user request.");
39
39
  } else if (security instanceof Function) {
40
+ {{#or (any securities 'type' 'oauth2') (any securities 'type' 'openIdConnect')}}
40
41
  return scopes ? security(scopes) : security();
42
+ {{else}}
43
+ return security();
44
+ {{/or}}
41
45
  }
42
46
  return security;
43
47
  }
@@ -1,6 +1,6 @@
1
1
  import { AxiosResponse, AxiosRequestConfig } from "axios";
2
2
  import { AbstractApi, AbstractConfig } from "./abstractApi";
3
- import { Config{{#if securities.length}}, Security{{/if}} } from "../config";
3
+ import { Config{{#if securities}}, Security{{/if}} } from "../config";
4
4
  {{#with meta}}
5
5
  {{#or hasTemplate hasQuery hasFormData ~}}
6
6
  import { {{#if hasTemplate}}template{{#or hasQuery hasFormData}},{{/or}}{{/if}} {{#if hasQuery}}query{{#if hasFormData}},{{/if}}{{/if}} {{#if hasFormData}}formData{{/if}} } from "../utils";
@@ -14,6 +14,6 @@ import { Config{{#if securities.length}}, Security{{/if}} } from "../config";
14
14
  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}} }
15
15
  {{/each}}
16
16
 
17
- {{> apis/class api }}
17
+ {{> apis/class api=api securities=securities }}
18
18
 
19
- {{> apis/config api }}
19
+ {{> apis/config api=api securities=securities }}
@@ -6,16 +6,16 @@
6
6
  {{/each}}
7
7
  }{{#if (every queries 'required' false)}} = {}{{/if}},
8
8
  {{/if}}
9
- headers: {
10
- 'Content-Type': {{#if forms}}{{#each forms}}{{#unless @first}} | {{/unless}}{{#each types}}{{#unless @first}} | {{/unless}}'{{this}}'{{/each}}{{/each}}{{else}}'application/json'{{/if}},
11
- {{#each headers}}
12
- {{name}}{{#unless required}}?{{/unless}}: {{> models/type schema}},
13
- {{/each}}
14
- }{{#if (every headers 'required' false)}} = { 'Content-Type': 'application/json' }{{/if}},
15
9
  {{~#if cookies}}cookies: {
16
10
  {{~#each cookies}}
17
11
  {{name}}{{#unless required}}?{{/unless}}: {{> models/type schema}},
18
12
  {{/each}}
19
13
  }{{#if (every cookies 'required' false)}} = {}{{/if}},
20
14
  {{/if}}
15
+ headers: {
16
+ 'Content-Type': {{#if forms}}{{#each forms}}{{#unless @first}} | {{/unless}}{{#each types}}{{#unless @first}} | {{/unless}}'{{this}}'{{/each}}{{/each}}{{else}}'application/json'{{/if}},
17
+ {{#each headers}}
18
+ {{name}}{{#unless required}}?{{/unless}}: {{> models/type schema}},
19
+ {{/each}}
20
+ }{{#if (every headers 'required' false)}} = { 'Content-Type': 'application/json' }{{/if}},
21
21
  {{~> apis/arguments/server servers}} config?: AxiosRequestConfig
@@ -1,4 +1,4 @@
1
1
  {{~#if queries}}queries,{{/if}}
2
- headers,
3
2
  {{~#if cookies}}cookies,{{/if}}
3
+ headers,
4
4
  {{~#if servers}}server,{{/if}} config
@@ -1,16 +1,16 @@
1
- {{> comment}}
2
- export class {{title}} extends AbstractApi {
3
- readonly #config: {{title}}Config;
1
+ {{> comment api}}
2
+ export class {{api.title}} extends AbstractApi {
3
+ readonly #config: {{api.title}}Config;
4
4
 
5
5
  /**
6
6
  * constructor
7
7
  * @param {Config} config
8
8
  */
9
- constructor(config: Config) {
9
+ constructor(config: Config = {}) {
10
10
  super(config);
11
- this.#config = new {{title}}Config({{#if securities.length}}config.security{{/if}});
11
+ this.#config = new {{api.title}}Config({{#if securities}}config.security{{/if}});
12
12
  }
13
- {{#each paths}}
13
+ {{#each api.paths}}
14
14
 
15
15
  {{> apis/class/request }}
16
16
  {{/each}}
@@ -4,16 +4,16 @@
4
4
  {{/each}}
5
5
  }{{#if (every queries 'required' false)}} = {}{{/if}},
6
6
  {{/if}}
7
- headers: {
8
- 'Content-Type': {{#if forms}}{{#each forms}}{{#unless @first}} | {{/unless}}{{#each types}}{{#unless @first}} | {{/unless}}'{{this}}'{{/each}}{{/each}}{{else}}'application/json'{{/if}},
9
- {{#each headers}}
10
- {{name}}{{#unless required}}?{{/unless}}: {{> models/type schema}},
11
- {{/each}}
12
- }{{#if (every headers 'required' false)}} = { 'Content-Type': 'application/json' }{{/if}},
13
7
  {{~#if cookies}}cookies: {
14
8
  {{~#each cookies}}
15
9
  {{name}}{{#unless required}}?{{/unless}}: {{> models/type schema}},
16
10
  {{/each}}
17
11
  }{{#if (every cookies 'required' false)}} = {}{{/if}},
18
12
  {{/if}}
13
+ headers: {
14
+ 'Content-Type': {{#if forms}}{{#each forms}}{{#unless @first}} | {{/unless}}{{#each types}}{{#unless @first}} | {{/unless}}'{{this}}'{{/each}}{{/each}}{{else}}'application/json'{{/if}},
15
+ {{#each headers}}
16
+ {{name}}{{#unless required}}?{{/unless}}: {{> models/type schema}},
17
+ {{/each}}
18
+ }{{#if (every headers 'required' false)}} = { 'Content-Type': 'application/json' }{{/if}},
19
19
  {{~> apis/arguments/server servers}} config?: AxiosRequestConfig
@@ -1,10 +1,13 @@
1
1
  {{~#each cookies}}
2
2
  if (cookies.{{name}}) {
3
- _cookies['{{name}}'] = query('{{name}}', cookies.{{name}}, 'form', {{#if explode}}true{{else}}false{{/if}});
3
+ _cookies += Object.entries(query('{{name}}', cookies.{{name}}, 'form', {{#if explode}}true{{else}}false{{/if}})).reduce((pre, [key, value]) => `${pre}${key}=${value};`, '');
4
4
  }
5
5
  {{/each}}
6
6
  {{~#each securities}}
7
7
  {{#and (eq type 'apiKey') (eq in 'cookie')~}}
8
- _cookies['{{key}}'] = await this.security("{{name}}");
8
+ const _cookie{{name}} = await this.security("{{name}}");
9
+ if (_cookie{{name}}) {
10
+ _cookies += `{{key}}=${_cookie{{name~}} };`;
11
+ }
9
12
  {{/and}}
10
13
  {{/each}}
@@ -1,10 +1,10 @@
1
1
  public async {{name}}({{> apis/config/arguments}}): Promise<AxiosRequestConfig> {
2
2
  const params = {{> apis/config/request/queries }};
3
3
 
4
- const _cookies = { ...(config?.headers?.Cookie as object) };
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 };
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,14 +1,14 @@
1
- class {{title}}Config extends AbstractConfig {
2
- {{#if securities.length}}
3
- constructor(security?: Security) {
1
+ class {{api.title}}Config extends AbstractConfig {
2
+ {{#if securities}}
3
+ constructor(security: Security = {}) {
4
4
  super(security);
5
5
  }
6
6
  {{/if}}
7
7
 
8
- {{> apis/config/server }}
8
+ {{> apis/config/server api }}
9
9
 
10
- {{#each paths}}
10
+ {{#each api.paths}}
11
11
 
12
- {{> apis/config/request title=../title }}
12
+ {{> apis/config/request title=../api.title }}
13
13
  {{/each}}
14
14
  }
@@ -3,11 +3,11 @@ import { AxiosInstance } from "axios";
3
3
  export type Security = {
4
4
  {{#each securities}}
5
5
  {{#and (eq type 'http') (eq scheme 'basic')}}
6
- {{name}}: {username: string; password: string;} | Promise<{username: string; password: string;}> | (() => {username: string; password: string;} | Promise<{username: string; password: string;}>);
6
+ {{name}}?: {username: string; password: string;} | Promise<{username: string; password: string;}> | (() => {username: string; password: string;} | Promise<{username: string; password: string;}>);
7
7
  {{else or (eq type 'oauth2') (eq type 'openIdConnect')}}
8
- {{name}}: string | Promise<string> | ((scopes?: string[]) => string | Promise<string>);
8
+ {{name}}?: string | Promise<string> | ((scopes?: string[]) => string | Promise<string>);
9
9
  {{else}}
10
- {{name}}: string | Promise<string> | (() => string | Promise<string>);
10
+ {{name}}?: string | Promise<string> | (() => string | Promise<string>);
11
11
  {{/and}}
12
12
  {{/each}}
13
13
  };