@automatons/typescript-client-axios 1.0.258 → 2.0.1

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.
Files changed (78) hide show
  1. package/index.d.ts +4 -3
  2. package/index.js +107 -5
  3. package/index.js.map +1 -1
  4. package/package.json +51 -49
  5. package/extractors/api.d.ts +0 -7
  6. package/extractors/api.d.ts.map +0 -1
  7. package/extractors/api.js +0 -15
  8. package/extractors/api.js.map +0 -1
  9. package/generator/generate.d.ts +0 -3
  10. package/generator/generate.d.ts.map +0 -1
  11. package/generator/generate.js +0 -31
  12. package/generator/generate.js.map +0 -1
  13. package/generator/index.d.ts +0 -2
  14. package/generator/index.d.ts.map +0 -1
  15. package/generator/index.js +0 -18
  16. package/generator/index.js.map +0 -1
  17. package/generator/register.d.ts +0 -2
  18. package/generator/register.d.ts.map +0 -1
  19. package/generator/register.js +0 -43
  20. package/generator/register.js.map +0 -1
  21. package/generator/setup.d.ts +0 -2
  22. package/generator/setup.d.ts.map +0 -1
  23. package/generator/setup.js +0 -25
  24. package/generator/setup.js.map +0 -1
  25. package/generator/writer.d.ts +0 -2
  26. package/generator/writer.d.ts.map +0 -1
  27. package/generator/writer.js +0 -19
  28. package/generator/writer.js.map +0 -1
  29. package/index.d.ts.map +0 -1
  30. package/paths.d.ts +0 -7
  31. package/paths.d.ts.map +0 -1
  32. package/paths.js +0 -13
  33. package/paths.js.map +0 -1
  34. package/src/src/extractors/api.ts +0 -13
  35. package/src/src/generator/generate.ts +0 -42
  36. package/src/src/generator/index.ts +0 -1
  37. package/src/src/generator/register.ts +0 -23
  38. package/src/src/generator/setup.ts +0 -20
  39. package/src/src/generator/writer.ts +0 -12
  40. package/src/src/index.ts +0 -7
  41. package/src/src/paths.ts +0 -8
  42. package/src/src/templates/apis/abstractApi.hbs +0 -63
  43. package/src/src/templates/apis/api.hbs +0 -17
  44. package/src/src/templates/apis/index.hbs +0 -3
  45. package/src/src/templates/apis/partials/arguments/server.hbs +0 -3
  46. package/src/src/templates/apis/partials/arguments/server_interface.hbs +0 -3
  47. package/src/src/templates/apis/partials/class/arguments.hbs +0 -21
  48. package/src/src/templates/apis/partials/class/arguments_interface.hbs +0 -21
  49. package/src/src/templates/apis/partials/class/path.hbs +0 -4
  50. package/src/src/templates/apis/partials/class/request.hbs +0 -14
  51. package/src/src/templates/apis/partials/class/variables.hbs +0 -4
  52. package/src/src/templates/apis/partials/class.hbs +0 -17
  53. package/src/src/templates/apis/partials/config/arguments.hbs +0 -19
  54. package/src/src/templates/apis/partials/config/request/baseURL.hbs +0 -1
  55. package/src/src/templates/apis/partials/config/request/cookies.hbs +0 -13
  56. package/src/src/templates/apis/partials/config/request/headers.hbs +0 -14
  57. package/src/src/templates/apis/partials/config/request/queries.hbs +0 -11
  58. package/src/src/templates/apis/partials/config/request.hbs +0 -19
  59. package/src/src/templates/apis/partials/config/server.hbs +0 -11
  60. package/src/src/templates/apis/partials/config.hbs +0 -14
  61. package/src/src/templates/config.hbs +0 -19
  62. package/src/src/templates/index.hbs +0 -3
  63. package/src/src/templates/models/index.hbs +0 -3
  64. package/src/src/templates/models/model.hbs +0 -6
  65. package/src/src/templates/models/partials/allOf.hbs +0 -7
  66. package/src/src/templates/models/partials/array.hbs +0 -6
  67. package/src/src/templates/models/partials/boolean.hbs +0 -1
  68. package/src/src/templates/models/partials/nullable.hbs +0 -1
  69. package/src/src/templates/models/partials/number.hbs +0 -6
  70. package/src/src/templates/models/partials/object.hbs +0 -13
  71. package/src/src/templates/models/partials/oneOf.hbs +0 -7
  72. package/src/src/templates/models/partials/string.hbs +0 -10
  73. package/src/src/templates/models/partials/type.hbs +0 -19
  74. package/src/src/templates/partials/comment.hbs +0 -24
  75. package/src/src/templates/utils/formData.hbs +0 -10
  76. package/src/src/templates/utils/index.hbs +0 -3
  77. package/src/src/templates/utils/query.hbs +0 -79
  78. package/src/src/templates/utils/template.hbs +0 -55
@@ -1,23 +0,0 @@
1
- import {readFile} from "fs-extra";
2
- import {glob} from 'glob';
3
- import Handlebars, {registerPartial} from "handlebars";
4
- import paths from "../paths";
5
-
6
- const partial = registerPartial.bind(Handlebars);
7
-
8
- const convertName = (match: string) =>
9
- match.replace(`${paths.templates}/`, '')
10
- .replace('partials/', '')
11
- .replace('.hbs', '');
12
-
13
- export const register = () =>
14
- new Promise<string[]>((resolve, reject) =>
15
- glob('/**/partials/**/*.hbs',
16
- {root: paths.templates},
17
- (err, matches) => err ? reject(err) : resolve(matches)))
18
- .then(matches => matches.map<{ name: string, path: string }>(match =>
19
- ({name: convertName(match), path: match})))
20
- .then(files => Promise.all(
21
- files.map(({name, path}) => readFile(path, {encoding: 'utf-8'})
22
- .then(data => partial(name, data))))
23
- );
@@ -1,20 +0,0 @@
1
- import helpers from "handlebars-helpers";
2
- import HB from "handlebars";
3
- import {register} from "./register";
4
-
5
- HB.registerHelper('every', function <T extends Object>(value: T[], key: keyof T, text?: T[keyof T]) {
6
- if (text === undefined) {
7
- return value.every(item => (item[key] == undefined ? false : item[key]))
8
- }
9
- return value.every(item => (item[key] == undefined ? false : item[key]) === text)
10
- });
11
-
12
- HB.registerHelper('any', function <T extends Object>(value: T[], key: keyof T, text?: T[keyof T]) {
13
- if (text === undefined) {
14
- return value.some(item => (item[key] == undefined ? false : item[key]))
15
- }
16
- return value.some(item => (item[key] == undefined ? false : item[key]) === text)
17
- });
18
-
19
- helpers({handlebars: HB});
20
- export const setup = () => register();
@@ -1,12 +0,0 @@
1
- import path from "path";
2
- import {ensureDir, readFile, writeFile} from "fs-extra";
3
- import {format} from "prettier";
4
- import paths from "../paths";
5
- import {compile} from "handlebars";
6
-
7
- export const write = async (template: string, outDir: string | string[], context?: any) => {
8
- const outputPath = Array.isArray(outDir) ? path.resolve(...outDir) : outDir;
9
- await ensureDir(path.dirname(outputPath));
10
- const data = await readFile(path.resolve(paths.templates, template), {encoding: 'utf-8'});
11
- return writeFile(outputPath, format(compile(data)(context), {parser: 'typescript'}));
12
- };
package/src/src/index.ts DELETED
@@ -1,7 +0,0 @@
1
- import {Automaton} from "@automatons/tools";
2
- import {generate} from "./generator";
3
-
4
- const generatorTypescriptAxiosClient: Automaton = (openapi, settings) =>
5
- generate(openapi, settings);
6
-
7
- export default generatorTypescriptAxiosClient;
package/src/src/paths.ts DELETED
@@ -1,8 +0,0 @@
1
- import path from 'path';
2
-
3
- const paths = {
4
- src: path.resolve(__dirname),
5
- templates: path.resolve(__dirname, 'templates'),
6
- tmp: path.resolve(__dirname, '../tmp')
7
- };
8
- export default paths;
@@ -1,63 +0,0 @@
1
- import Axios, { AxiosInstance } from "axios";
2
- import type { Config{{#if securities}}, Security{{/if}} } from "../config";
3
-
4
- const DateFormat = /^\d{4}-\d{2}-\d{2}([tT]\d{2}:\d{2}:\d{2}(Z|[+-]\d{2}:\d{2})|Z)?$/;
5
- const reviver = (_key: string, value: any) =>
6
- typeof value === 'string' && DateFormat.test(value) ? new Date(value) : value;
7
-
8
- const BASE_AXIOS = Axios.create({
9
- transformResponse: (data) => JSON.parse(data, reviver)
10
- });
11
-
12
- /**
13
- * AbstractConfig
14
- */
15
- export class AbstractConfig {
16
- {{#if securities}}
17
- readonly #security: Security;
18
-
19
- /**
20
- * constructor
21
- */
22
- constructor(security: Security = {}) {
23
- this.#security = security;
24
- }
25
-
26
- {{#each securities}}
27
- {{#and (eq type 'http') (eq scheme 'basic')}}
28
- protected async security(key: "{{name}}"): Promise<{username: string; password: string;}>;
29
- {{else or (eq type 'oauth2') (eq type 'openIdConnect')}}
30
- protected async security(key: "{{name}}", scopes: string[]): Promise<string>;
31
- {{else}}
32
- protected async security(key: "{{name}}"): Promise<string>;
33
- {{/and}}
34
- {{/each}}
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
- if (!security) {
38
- throw new Error("Unauthorized user request.");
39
- } else if (security instanceof Function) {
40
- {{#or (any securities 'type' 'oauth2') (any securities 'type' 'openIdConnect')}}
41
- return scopes ? security(scopes) : security();
42
- {{else}}
43
- return security();
44
- {{/or}}
45
- }
46
- return security;
47
- }
48
- {{/if}}
49
- }
50
-
51
- /**
52
- * AbstractApi
53
- */
54
- export class AbstractApi {
55
- protected axios: AxiosInstance = BASE_AXIOS;
56
-
57
- /**
58
- * constructor
59
- */
60
- constructor({axios}: Config) {
61
- if (axios) this.axios = axios;
62
- }
63
- }
@@ -1,17 +0,0 @@
1
- import { AxiosResponse, AxiosRequestConfig } from "axios";
2
- import { AbstractApi, AbstractConfig } from "./abstractApi";
3
- import { Config{{#if securities}}, Security{{/if}} } from "../config";
4
- {{#with meta}}
5
- {{#or hasTemplate hasQuery hasFormData ~}}
6
- import { {{#if hasTemplate}}template{{#or hasQuery hasFormData}},{{/or}}{{/if}} {{#if hasQuery}}query{{#if hasFormData}},{{/if}}{{/if}} {{#if hasFormData}}formData{{/if}} } from "../utils";
7
- {{/or}}
8
- {{/with}}
9
- import { {{#each api/imports~}} {{title}}{{#unless @last}}, {{/unless}}{{/each}} } from "../models";
10
-
11
- {{#each api/servers}}
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}} }
13
- {{/each}}
14
-
15
- {{> apis/class api=api securities=securities }}
16
-
17
- {{> apis/config api=api securities=securities }}
@@ -1,3 +0,0 @@
1
- {{#each this ~}}
2
- export * from "./{{filename}}";
3
- {{/each}}
@@ -1,3 +0,0 @@
1
- {{#if this~}}
2
- server: {{#each this}}{{name}}Server{{#unless @last}} | {{/unless}}{{/each}}{{#and (lengthEqual this 1) (isEmpty this/0/values)}} = { name: '{{this/0/name}}'{{#if this/0/values}}, values: { {{#each this/0/values}}{{name}}: '{{defaultValue}}',{{/each}} } {{/if}} }{{/and}},
3
- {{~/if}}
@@ -1,3 +0,0 @@
1
- {{#if this~}}
2
- server?: {{#each this}}{{name}}Server{{#unless @last}} | {{/unless}}{{/each}},
3
- {{~/if}}
@@ -1,21 +0,0 @@
1
- {{~#each parameters}}{{name}}: {{> models/type schema}},{{/each}}
2
- {{~#if forms}}form: {{#each forms}}{{#unless @first}} | {{/unless}}{{> models/type schema}}{{/each}},{{/if}}
3
- {{~#if queries}}queries: {
4
- {{~#each queries}}
5
- {{name}}{{#unless required}}?{{/unless}}: {{> models/type schema}},
6
- {{/each}}
7
- }{{#if (every queries 'required' false)}} = {}{{/if}},
8
- {{/if}}
9
- {{~#if cookies}}cookies: {
10
- {{~#each cookies}}
11
- {{name}}{{#unless required}}?{{/unless}}: {{> models/type schema}},
12
- {{/each}}
13
- }{{#if (every cookies 'required' false)}} = {}{{/if}},
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
- {{~> apis/arguments/server servers}} config?: AxiosRequestConfig
@@ -1,21 +0,0 @@
1
- {{~#each parameters}}{{name}}: {{> models/type schema}},{{/each}}
2
- form: {{> models/type form/schema}},
3
- {{~#if queries}}queries: {
4
- {{~#each queries}}
5
- {{name}}{{#unless required}}?{{/unless}}: {{> models/type schema}},
6
- {{/each}}
7
- },
8
- {{/if}}
9
- headers{{#filter form/types 'application/json'}}?{{/filter}}: {
10
- 'Content-Type': {{#each form/types}}{{#unless @first}} | {{/unless}}'{{this}}'{{/each}},
11
- {{#each headers}}
12
- {{name}}{{#unless required}}?{{/unless}}: {{> models/type schema}},
13
- {{/each}}
14
- },
15
- {{~#if cookies}}cookies: {
16
- {{~#each cookies}}
17
- {{name}}{{#unless required}}?{{/unless}}: {{> models/type schema}},
18
- {{/each}}
19
- },
20
- {{/if}}
21
- {{~> apis/arguments/server_interface servers}} config?: AxiosRequestConfig
@@ -1,4 +0,0 @@
1
- "{{path}}"
2
- {{#each parameters}}
3
- .replace("{ {{~name~}} }", template('{{name}}', {{name}}, '{{#unless style}}simple{{else}}{{style}}{{/unless}}', {{#unless explode}}false{{else}}{{explode}}{{/unless}}))
4
- {{~/each}}
@@ -1,14 +0,0 @@
1
- {{> comment title=name async=true}}
2
- {{#gt (length forms) 1 }}
3
- {{#each forms}}
4
- public async {{../name}}({{> apis/class/arguments_interface .. form=this}}): Promise<AxiosResponse{{#if ../schema}}<{{> models/type ../schema}}>{{/if}}>;
5
- {{/each}}
6
- {{/gt}}
7
- public async {{name}}({{> apis/class/arguments}}): Promise<AxiosResponse{{#if schema}}<{{> models/type schema}}>{{/if}}> {
8
- const path = {{> apis/class/path}};
9
- const requestConfig = await this.#config.{{name}}({{> apis/class/variables }});
10
- {{#if forms}}
11
- const _form = formData(headers['Content-Type'], form);
12
- {{/if}}
13
- return this.axios.{{method}}(path, {{#if forms}}_form, {{/if}}requestConfig)
14
- }
@@ -1,4 +0,0 @@
1
- {{~#if queries}}queries,{{/if}}
2
- {{~#if cookies}}cookies,{{/if}}
3
- headers,
4
- {{~#if servers}}server,{{/if}} config
@@ -1,17 +0,0 @@
1
- {{> comment api}}
2
- export class {{api.title}} extends AbstractApi {
3
- readonly #config: {{api.title}}Config;
4
-
5
- /**
6
- * constructor
7
- * @param {Config} config
8
- */
9
- constructor(config: Config = {}) {
10
- super(config);
11
- this.#config = new {{api.title}}Config({{#if securities}}config.security{{/if}});
12
- }
13
- {{#each api.paths}}
14
-
15
- {{> apis/class/request }}
16
- {{/each}}
17
- }
@@ -1,19 +0,0 @@
1
- {{~#if queries}}queries: {
2
- {{~#each queries}}
3
- {{name}}{{#unless required}}?{{/unless}}: {{> models/type schema}},
4
- {{/each}}
5
- }{{#if (every queries 'required' false)}} = {}{{/if}},
6
- {{/if}}
7
- {{~#if cookies}}cookies: {
8
- {{~#each cookies}}
9
- {{name}}{{#unless required}}?{{/unless}}: {{> models/type schema}},
10
- {{/each}}
11
- }{{#if (every cookies 'required' false)}} = {}{{/if}},
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
- {{~> apis/arguments/server servers}} config?: AxiosRequestConfig
@@ -1 +0,0 @@
1
- config?.baseURL ? config.baseURL : {{title}}Config.server(server)
@@ -1,13 +0,0 @@
1
- {{~#each cookies}}
2
- if (cookies.{{name}}) {
3
- _cookies += Object.entries(query('{{name}}', cookies.{{name}}, 'form', {{#if explode}}true{{else}}false{{/if}})).reduce((pre, [key, value]) => `${pre}${key}=${value};`, '');
4
- }
5
- {{/each}}
6
- {{~#each securities}}
7
- {{#and (eq type 'apiKey') (eq in 'cookie')~}}
8
- const _cookie{{name}} = await this.security("{{name}}");
9
- if (_cookie{{name}}) {
10
- _cookies += `{{key}}=${_cookie{{name~}} };`;
11
- }
12
- {{/and}}
13
- {{/each}}
@@ -1,14 +0,0 @@
1
- {{~#each headers}}
2
- if (headers.{{name}}) {
3
- _headers['{{name}}'] = template('{{name}}', headers.{{name}}, 'simple', {{#if explode}}true{{else}}false{{/if}});
4
- }
5
- {{/each}}
6
- {{~#each securities}}
7
- {{#and (eq type 'apiKey') (eq in 'header')~}}
8
- _headers['{{key}}'] = await this.security("{{name}}");
9
- {{else and (eq type 'http') (eq schema 'bearer')}}
10
- _headers['Authorization'] = `Bearer ${await this.security("{{name}}")}`;
11
- {{else or (eq type 'oauth2') (eq type 'openIdConnect')}}
12
- _headers['Authorization'] = `Bearer ${await this.security("{{name}}", [{{#each scopes}}"{{this}}"{{#unless @last}}, {{/unless}}{{/each}}])}`;
13
- {{/and}}
14
- {{/each}}
@@ -1,11 +0,0 @@
1
- {
2
- ...config?.params,
3
- {{#each queries}}
4
- ...query("{{name}}", queries.{{name}}, '{{#unless style}}form{{else}}{{style}}{{/unless}}', {{#unless explode}}false{{else}}{{explode}}{{/unless}}),
5
- {{/each}}
6
- {{#each securities}}
7
- {{#and (eq type 'apiKey') (eq in 'query')}}
8
- {{key}}: await this.security("{{name}}"),
9
- {{/and}}
10
- {{/each}}
11
- }
@@ -1,19 +0,0 @@
1
- public async {{name}}({{> apis/config/arguments}}): Promise<AxiosRequestConfig> {
2
- const params = {{> apis/config/request/queries }};
3
-
4
- let _cookies = config?.headers?.Cookie ?? '';
5
- {{> apis/config/request/cookies }}
6
-
7
- const _headers = Object.assign({ ...config?.headers, 'Content-Type': headers['Content-Type']}, _cookies ? {Cookie: _cookies} : undefined);
8
- {{> apis/config/request/headers }}
9
-
10
- return {
11
- ...config,
12
- {{#each securities}}
13
- {{#and (eq type 'http') (eq scheme 'basic') }}auth: await this.security("{{name}}"),{{/and}}
14
- {{~/each}}
15
- baseURL: {{> apis/config/request/baseURL title=title }},
16
- params,
17
- headers: _headers
18
- };
19
- }
@@ -1,11 +0,0 @@
1
- private static server(server: {{#each servers}}{{name}}Server{{#unless @last}} | {{/unless}}{{/each}}) {
2
- {{#each servers}}
3
- if ('{{name}}' === server.name) {
4
- return '{{url}}'
5
- {{#each values}}
6
- .replace('{ {{~name~}} }', template('{{name}}', server.values.{{name}}, 'simple', false))
7
- {{~/each}};
8
- }
9
- {{/each}}
10
- throw new Error('Undefined server. please define server.');
11
- }
@@ -1,14 +0,0 @@
1
- class {{api.title}}Config extends AbstractConfig {
2
- {{#if securities}}
3
- constructor(security: Security = {}) {
4
- super(security);
5
- }
6
- {{/if}}
7
-
8
- {{> apis/config/server api }}
9
-
10
- {{#each api.paths}}
11
-
12
- {{> apis/config/request title=../api.title }}
13
- {{/each}}
14
- }
@@ -1,19 +0,0 @@
1
- import { AxiosInstance } from "axios";
2
-
3
- export type Security = {
4
- {{#each securities}}
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;}>);
7
- {{else or (eq type 'oauth2') (eq type 'openIdConnect')}}
8
- {{name}}?: string | Promise<string> | ((scopes?: string[]) => string | Promise<string>);
9
- {{else}}
10
- {{name}}?: string | Promise<string> | (() => string | Promise<string>);
11
- {{/and}}
12
- {{/each}}
13
- };
14
-
15
- export type Config = {
16
- axios?: AxiosInstance;
17
- token?: string | Promise<string> | (() => string | Promise<string>);
18
- security?: Security;
19
- }
@@ -1,3 +0,0 @@
1
- {{#if model}}export * from './models';{{/if}}
2
- {{#if api}}export * from './apis';{{/if}}
3
- export * from './config';
@@ -1,3 +0,0 @@
1
- {{#each this ~}}
2
- export * from "./{{filename}}";
3
- {{/each}}
@@ -1,6 +0,0 @@
1
- {{#each imports~}}
2
- import { {{title}} } from "./{{filename}}";
3
- {{/each}}
4
-
5
- {{> comment}}
6
- export type {{title}} = {{> models/type schema}};
@@ -1,7 +0,0 @@
1
- {{#noop~}}
2
- (
3
- {{~#each schemas}}
4
- {{~#if @first}}{{> models/type}}{{else}} & {{> models/type}}{{/if~}}
5
- {{/each~}}
6
- )
7
- {{~/noop}}
@@ -1,6 +0,0 @@
1
- {{#if items ~}}
2
- Array<{{#with items}}{{> models/type}}{{/with}}>
3
- {{~ else ~}}
4
- any[]
5
- {{~/if}}
6
- {{~> models/nullable}}
@@ -1 +0,0 @@
1
- boolean{{> models/nullable}}
@@ -1 +0,0 @@
1
- {{#if nullable}} | null{{/if}}
@@ -1,6 +0,0 @@
1
- {{#if enum}}
2
- {{~#each enum}}{{#if @first}}{{this}}{{else}} | {{this}}{{/if}}{{/each ~}}
3
- {{~ else ~}}
4
- number
5
- {{~/if}}
6
- {{> models/nullable}}
@@ -1,13 +0,0 @@
1
- {{#noop}}
2
- {{#if properties ~}}
3
- {
4
- {{#each properties}}
5
- {{> comment title=name}}
6
- {{#inArray name "-"}}"{{name}}"{{else}}{{name}}{{/inArray}}{{#unless required}}?{{/unless}}: {{> models/type schema}};
7
- {{/each}}
8
- }
9
- {{~ else ~}}
10
- object
11
- {{~/if}}
12
- {{> models/nullable}}
13
- {{~/noop}}
@@ -1,7 +0,0 @@
1
- {{#noop~}}
2
- (
3
- {{~#each schemas}}
4
- {{~#if @first}}{{> models/type}}{{else}} | {{> models/type}}{{/if~}}
5
- {{/each~}}
6
- )
7
- {{~/noop}}
@@ -1,10 +0,0 @@
1
- {{~#if enum}}
2
- {{~#each enum}}{{~#if @first}}"{{this}}"{{~else}} | "{{this}}"{{~/if}}{{~/each}}
3
- {{~else or (eq format 'date') (eq format 'date-time')~}}
4
- Date
5
- {{~else eq format 'url'~}}
6
- URL
7
- {{~else~}}
8
- string
9
- {{~/if}}
10
- {{> models/nullable}}
@@ -1,19 +0,0 @@
1
- {{#eq type 'model'}}
2
- {{~ name ~}}
3
- {{else eq type 'object'}}
4
- {{~> models/object}}
5
- {{else eq type 'allOf'}}
6
- {{~> models/allOf}}
7
- {{else eq type 'oneOf'}}
8
- {{~> models/oneOf}}
9
- {{else eq type 'array'}}
10
- {{~> models/array}}
11
- {{else eq type 'boolean'}}
12
- {{~> models/boolean}}
13
- {{else eq type 'string'}}
14
- {{~> models/string}}
15
- {{else eq type 'number'}}
16
- {{~> models/number}}
17
- {{else}}
18
- {{~ type}}
19
- {{/eq}}
@@ -1,24 +0,0 @@
1
- /**
2
- * {{title}}
3
- {{#if async}}
4
- * @async
5
- {{/if}}
6
- {{#if description}}
7
- * @description {{description}}
8
- {{/if}}
9
- {{#if deprecated}}
10
- * @deprecated
11
- {{/if}}
12
- {{#if readOnly}}
13
- * @readonly
14
- {{/if}}
15
- {{#if defaultValue}}
16
- * @default {{defaultValue}}
17
- {{/if}}
18
- {{#each params}}
19
- * @params { {{type}} } {{name}}
20
- {{/each}}
21
- {{#if example}}
22
- * @example
23
- {{/if}}
24
- */
@@ -1,10 +0,0 @@
1
- import { serialize } from 'object-to-formdata';
2
-
3
- export const formData = <T = unknown>(type: string, form: T): T | FormData => {
4
- switch(type) {
5
- case 'multipart/form-data':
6
- return serialize(form);
7
- default:
8
- return form;
9
- }
10
- }
@@ -1,3 +0,0 @@
1
- export * from './template';
2
- export * from './query';
3
- export * from './formData';
@@ -1,79 +0,0 @@
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
- }
7
-
8
- const queryForm =
9
- (name: string,
10
- value: string | number | Array<string | number> | { [key: string]: string | number },
11
- explode: boolean): ParsedUrlQueryInput => {
12
- if (Array.isArray(value)) {
13
- if (explode) {
14
- return {[name]: value.map(String)}
15
- } else {
16
- return {[name]: value.join(',')}
17
- }
18
- } else if (isObject(value)) {
19
- if (explode) {
20
- return value;
21
- } else {
22
- return {[name]: Object.entries(value).map((prop: [string, string | number]) => prop.join(',')).join(',')}
23
- }
24
- } else {
25
- return {[name]: value};
26
- }
27
- }
28
-
29
- const querySpaceDelimited =
30
- (name: string,
31
- value: string | number | Array<string | number> | { [key: string]: string | number }): ParsedUrlQueryInput => {
32
- if (Array.isArray(value)) {
33
- return {[name]: value.join(' ')}
34
- } else if (isObject(value)) {
35
- return {[name]: Object.entries(value).map((prop: [string, string | number]) => prop.join(' ')).join(' ')}
36
- }
37
- throw new Error(`Unsupported value: ${name}`);
38
- }
39
-
40
- const queryPipeDelimited =
41
- (name: string,
42
- value: string | number | Array<string | number> | { [key: string]: string | number }): ParsedUrlQueryInput => {
43
- if (Array.isArray(value)) {
44
- return {[name]: value.join('|')}
45
- } else if (isObject(value)) {
46
- return {[name]: Object.entries(value).map((prop: [string, string | number]) => prop.join('|')).join('|')}
47
- }
48
- throw new Error(`Unsupported value: ${name}`);
49
- }
50
-
51
- const queryDeepObject =
52
- (name: string,
53
- value: string | number | Array<string | number> | { [key: string]: string | number }): ParsedUrlQueryInput => {
54
- if (!Array.isArray(value) && isObject(value)) {
55
- return Object.keys(value).reduce((pre, cur) => ({...pre, [`${name}[${cur}]`]: value[cur]}), {});
56
- }
57
- throw new Error(`Unsupported value: ${name}`);
58
- }
59
-
60
- export const query =
61
- (
62
- name: string,
63
- value: undefined | string | number | Array<string | number> | { [key: string]: string | number },
64
- style: 'form' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject',
65
- explode: boolean): ParsedUrlQueryInput => {
66
- if (value === undefined) return {};
67
- switch (style) {
68
- case 'form':
69
- return queryForm(name, value, explode);
70
- case 'spaceDelimited':
71
- return querySpaceDelimited(name, value);
72
- case 'pipeDelimited':
73
- return queryPipeDelimited(name, value);
74
- case 'deepObject':
75
- return queryDeepObject(name, value);
76
- default:
77
- throw new Error(`Unsupported style: ${style}`);
78
- }
79
- }