@automatons/typescript-client-axios 1.0.0

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 (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/extractors/api.d.ts +7 -0
  4. package/extractors/api.d.ts.map +1 -0
  5. package/extractors/api.js +14 -0
  6. package/extractors/api.js.map +1 -0
  7. package/generator/generate.d.ts +3 -0
  8. package/generator/generate.d.ts.map +1 -0
  9. package/generator/generate.js +29 -0
  10. package/generator/generate.js.map +1 -0
  11. package/generator/index.d.ts +2 -0
  12. package/generator/index.d.ts.map +1 -0
  13. package/generator/index.js +14 -0
  14. package/generator/index.js.map +1 -0
  15. package/generator/register.d.ts +2 -0
  16. package/generator/register.d.ts.map +1 -0
  17. package/generator/register.js +18 -0
  18. package/generator/register.js.map +1 -0
  19. package/generator/setup.d.ts +2 -0
  20. package/generator/setup.d.ts.map +1 -0
  21. package/generator/setup.js +18 -0
  22. package/generator/setup.js.map +1 -0
  23. package/generator/writer.d.ts +2 -0
  24. package/generator/writer.d.ts.map +1 -0
  25. package/generator/writer.js +19 -0
  26. package/generator/writer.js.map +1 -0
  27. package/index.d.ts +4 -0
  28. package/index.d.ts.map +1 -0
  29. package/index.js +6 -0
  30. package/index.js.map +1 -0
  31. package/package.json +72 -0
  32. package/paths.d.ts +7 -0
  33. package/paths.d.ts.map +1 -0
  34. package/paths.js +13 -0
  35. package/paths.js.map +1 -0
  36. package/templates/apis/abstractApi.hbs +59 -0
  37. package/templates/apis/api.hbs +19 -0
  38. package/templates/apis/index.hbs +3 -0
  39. package/templates/apis/partials/arguments/server.hbs +3 -0
  40. package/templates/apis/partials/arguments/server_interface.hbs +3 -0
  41. package/templates/apis/partials/class/arguments.hbs +21 -0
  42. package/templates/apis/partials/class/arguments_interface.hbs +21 -0
  43. package/templates/apis/partials/class/path.hbs +4 -0
  44. package/templates/apis/partials/class/request.hbs +14 -0
  45. package/templates/apis/partials/class/variables.hbs +4 -0
  46. package/templates/apis/partials/class.hbs +17 -0
  47. package/templates/apis/partials/config/arguments.hbs +19 -0
  48. package/templates/apis/partials/config/request/baseURL.hbs +1 -0
  49. package/templates/apis/partials/config/request/cookies.hbs +10 -0
  50. package/templates/apis/partials/config/request/headers.hbs +14 -0
  51. package/templates/apis/partials/config/request/queries.hbs +11 -0
  52. package/templates/apis/partials/config/request.hbs +19 -0
  53. package/templates/apis/partials/config/server.hbs +11 -0
  54. package/templates/apis/partials/config.hbs +14 -0
  55. package/templates/config.hbs +19 -0
  56. package/templates/index.hbs +3 -0
  57. package/templates/models/index.hbs +3 -0
  58. package/templates/models/model.hbs +6 -0
  59. package/templates/models/partials/allOf.hbs +7 -0
  60. package/templates/models/partials/array.hbs +6 -0
  61. package/templates/models/partials/boolean.hbs +1 -0
  62. package/templates/models/partials/nullable.hbs +1 -0
  63. package/templates/models/partials/number.hbs +6 -0
  64. package/templates/models/partials/object.hbs +13 -0
  65. package/templates/models/partials/oneOf.hbs +7 -0
  66. package/templates/models/partials/string.hbs +10 -0
  67. package/templates/models/partials/type.hbs +19 -0
  68. package/templates/partials/comment.hbs +24 -0
  69. package/templates/utils/formData.hbs +10 -0
  70. package/templates/utils/index.hbs +3 -0
  71. package/templates/utils/query.hbs +74 -0
  72. package/templates/utils/template.hbs +55 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) tanmen (yt.prog@gmail.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @automatons/typescript-client-axios
2
+
3
+ ## What @automatons/typescript-client-axios
4
+ This is generator.
5
+ Only use openapi-automatons.
@@ -0,0 +1,7 @@
1
+ import { Api } from "@automatons/parser";
2
+ export declare const extractApiMeta: (api: Api) => {
3
+ hasQuery: boolean;
4
+ hasTemplate: boolean;
5
+ hasFormData: boolean;
6
+ };
7
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/extractors/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,GAAG,EAAO,MAAM,oBAAoB,CAAC;AAIzD,eAAO,MAAM,cAAc,QAAS,GAAG;;;;CAQtC,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractApiMeta = void 0;
4
+ const isAffectPath = (path) => ['post', 'patch', 'put'].includes(path.method);
5
+ exports.extractApiMeta = (api) => {
6
+ const hasTemplate = api.servers.some(server => { var _a; return (_a = server.values) === null || _a === void 0 ? void 0 : _a.length; })
7
+ || api.paths.some(path => { var _a; return (_a = path.parameters) === null || _a === void 0 ? void 0 : _a.length; })
8
+ || api.paths.some(path => { var _a; return (_a = path.headers) === null || _a === void 0 ? void 0 : _a.length; });
9
+ const hasQuery = api.paths.some(path => { var _a; return (_a = path.queries) === null || _a === void 0 ? void 0 : _a.length; })
10
+ || api.paths.some(path => { var _a; return (_a = path.cookies) === null || _a === void 0 ? void 0 : _a.length; });
11
+ const hasFormData = api.paths.some(path => { var _a; return isAffectPath(path) ? (_a = path.forms) === null || _a === void 0 ? void 0 : _a.length : false; });
12
+ return { hasQuery, hasTemplate, hasFormData };
13
+ };
14
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/extractors/api.ts"],"names":[],"mappings":";;;AAEA,MAAM,YAAY,GAAG,CAAC,IAAU,EAAsB,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAE3F,QAAA,cAAc,GAAG,CAAC,GAAQ,EAAE,EAAE;IACzC,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,wBAAC,MAAM,CAAC,MAAM,0CAAE,MAAM,GAAA,CAAC;WAChE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,wBAAC,IAAI,CAAC,UAAU,0CAAE,MAAM,GAAA,CAAC;WAC/C,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,wBAAC,IAAI,CAAC,OAAO,0CAAE,MAAM,GAAA,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,wBAAC,IAAI,CAAC,OAAO,0CAAE,MAAM,GAAA,CAAC;WACxD,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,wBAAC,IAAI,CAAC,OAAO,0CAAE,MAAM,GAAA,CAAC,CAAC;IAClD,MAAM,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,WAAC,OAAA,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,OAAC,IAAI,CAAC,KAAK,0CAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAA,EAAA,CAAC,CAAC;IAC5F,OAAO,EAAC,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAC,CAAC;AAC9C,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { AutomatonSettings, Openapi } from "@automatons/tools";
2
+ export declare const generate: (openapi: Openapi, settings: AutomatonSettings) => Promise<void[]>;
3
+ //# sourceMappingURL=generate.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generate = void 0;
4
+ const parser_1 = require("@automatons/parser");
5
+ const writer_1 = require("./writer");
6
+ const setup_1 = require("./setup");
7
+ const api_1 = require("../extractors/api");
8
+ exports.generate = async (openapi, settings) => {
9
+ const { outDir } = settings;
10
+ const promises = [];
11
+ await setup_1.setup();
12
+ const { models, apis, securities } = await parser_1.parser(openapi, settings);
13
+ if (models.length) {
14
+ promises.push(writer_1.write('models/index.hbs', [outDir, 'models', 'index.ts'], models));
15
+ const modelPromises = models
16
+ .map(model => writer_1.write('models/model.hbs', [outDir, 'models', `${model.filename}.ts`], model));
17
+ promises.push(...modelPromises);
18
+ }
19
+ if (apis.length) {
20
+ promises.push(writer_1.write('apis/index.hbs', [outDir, 'apis', 'index.ts'], apis), writer_1.write('apis/abstractApi.hbs', [outDir, 'apis', 'abstractApi.ts'], { securities }));
21
+ promises.push(...apis.map(api => writer_1.write('apis/api.hbs', [outDir, 'apis', `${api.filename}.ts`], {
22
+ api,
23
+ meta: api_1.extractApiMeta(api)
24
+ })));
25
+ }
26
+ promises.push(writer_1.write('index.hbs', [outDir, 'index.ts'], { api: apis.length, model: models.length }), writer_1.write('config.hbs', [outDir, 'config.ts'], { securities }), writer_1.write('utils/index.hbs', [outDir, 'utils', 'index.ts']), writer_1.write('utils/template.hbs', [outDir, 'utils', 'template.ts']), writer_1.write('utils/query.hbs', [outDir, 'utils', 'query.ts']), writer_1.write('utils/formData.hbs', [outDir, 'utils', 'formData.ts']));
27
+ return Promise.all(promises);
28
+ };
29
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/generator/generate.ts"],"names":[],"mappings":";;;AACA,+CAA0C;AAC1C,qCAA+B;AAC/B,mCAA8B;AAC9B,2CAAiD;AAGpC,QAAA,QAAQ,GAAG,KAAK,EAAE,OAAgB,EAAE,QAA2B,EAAE,EAAE;IAC9E,MAAM,EAAC,MAAM,EAAC,GAAG,QAAQ,CAAC;IAC1B,MAAM,QAAQ,GAAoB,EAAE,CAAC;IACrC,MAAM,aAAK,EAAE,CAAC;IAEd,MAAM,EAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAC,GAAG,MAAM,eAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACnE,IAAI,MAAM,CAAC,MAAM,EAAE;QACjB,QAAQ,CAAC,IAAI,CAAC,cAAK,CAAC,kBAAkB,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;QAChF,MAAM,aAAa,GAAG,MAAM;aACzB,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,cAAK,CAAC,kBAAkB,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,QAAQ,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;QAC9F,QAAQ,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAA;KAChC;IAED,IAAI,IAAI,CAAC,MAAM,EAAE;QACf,QAAQ,CAAC,IAAI,CACX,cAAK,CAAC,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,EAC3D,cAAK,CAAC,sBAAsB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,EAAC,UAAU,EAAC,CAAC,CAChF,CAAC;QACF,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,cAAK,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,QAAQ,KAAK,CAAC,EAAE;YAC7F,GAAG;YACH,IAAI,EAAE,oBAAc,CAAC,GAAG,CAAC;SAC1B,CAAC,CAAC,CAAC,CAAC;KACN;IAED,QAAQ,CAAC,IAAI,CACX,cAAK,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,EAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAC,CAAC,EAClF,cAAK,CAAC,YAAY,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,EAAC,UAAU,EAAC,CAAC,EACxD,cAAK,CAAC,iBAAiB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,EACvD,cAAK,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,EAC7D,cAAK,CAAC,iBAAiB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,EACvD,cAAK,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAC9D,CAAC;IACF,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAC9B,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './generate';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./generate"), exports);
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA2B"}
@@ -0,0 +1,2 @@
1
+ export declare const register: () => Promise<void[]>;
2
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/generator/register.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,QAAQ,uBAUhB,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.register = void 0;
7
+ const fs_extra_1 = require("fs-extra");
8
+ const glob_1 = require("glob");
9
+ const handlebars_1 = require("handlebars");
10
+ const paths_1 = __importDefault(require("../paths"));
11
+ const convertName = (match) => match.replace(`${paths_1.default.templates}/`, '')
12
+ .replace('partials/', '')
13
+ .replace('.hbs', '');
14
+ exports.register = () => new Promise((resolve, reject) => glob_1.glob('/**/partials/**/*.hbs', { root: paths_1.default.templates }, (err, matches) => err ? reject(err) : resolve(matches)))
15
+ .then(matches => matches.map(match => ({ name: convertName(match), path: match })))
16
+ .then(files => Promise.all(files.map(({ name, path }) => fs_extra_1.readFile(path, { encoding: 'utf-8' })
17
+ .then(data => handlebars_1.registerPartial(name, data)))));
18
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/generator/register.ts"],"names":[],"mappings":";;;;;;AAAA,uCAAkC;AAClC,+BAA0B;AAC1B,2CAA2C;AAC3C,qDAA6B;AAE7B,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,EAAE,CACpC,KAAK,CAAC,OAAO,CAAC,GAAG,eAAK,CAAC,SAAS,GAAG,EAAE,EAAE,CAAC;KACrC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;KACxB,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAEZ,QAAA,QAAQ,GAAG,GAAG,EAAE,CAC3B,IAAI,OAAO,CAAW,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CACxC,WAAI,CAAC,uBAAuB,EAC1B,EAAC,IAAI,EAAE,eAAK,CAAC,SAAS,EAAC,EACvB,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;KACzD,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAiC,KAAK,CAAC,EAAE,CACnE,CAAC,EAAC,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,KAAK,EAAC,CAAC,CAAC,CAAC;KAC5C,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CACxB,KAAK,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAE,IAAI,EAAC,EAAE,EAAE,CAAC,mBAAQ,CAAC,IAAI,EAAE,EAAC,QAAQ,EAAE,OAAO,EAAC,CAAC;KAC5D,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,4BAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAC/C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const setup: () => Promise<void[]>;
2
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/generator/setup.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,KAAK,uBAAmB,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.setup = void 0;
7
+ const handlebars_helpers_1 = __importDefault(require("handlebars-helpers"));
8
+ const handlebars_1 = __importDefault(require("handlebars"));
9
+ const register_1 = require("./register");
10
+ handlebars_1.default.registerHelper('every', function (value, key, text) {
11
+ return value.every(item => (item[key] == undefined ? false : item[key]) === text);
12
+ });
13
+ handlebars_1.default.registerHelper('have', function (value, checkers) {
14
+ return value.some(item => checkers.every(({ key, text }) => item[key] === text));
15
+ });
16
+ handlebars_helpers_1.default({ handlebars: handlebars_1.default });
17
+ exports.setup = () => register_1.register();
18
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +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,4BAAO,CAAC,EAAC,UAAU,EAAE,oBAAE,EAAC,CAAC,CAAC;AACb,QAAA,KAAK,GAAG,GAAG,EAAE,CAAC,mBAAQ,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function write(template: string, outDir: string | string[], context?: any): Promise<void>;
2
+ //# sourceMappingURL=writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../src/generator/writer.ts"],"names":[],"mappings":"AAMA,wBAAsB,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,GAAG,iBAKrF"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.write = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_extra_1 = require("fs-extra");
9
+ const prettier_1 = require("prettier");
10
+ const paths_1 = __importDefault(require("../paths"));
11
+ const handlebars_1 = require("handlebars");
12
+ async function write(template, outDir, context) {
13
+ const outputPath = Array.isArray(outDir) ? path_1.default.resolve(...outDir) : outDir;
14
+ await fs_extra_1.ensureDir(path_1.default.dirname(outputPath));
15
+ const data = await fs_extra_1.readFile(path_1.default.resolve(paths_1.default.templates, template), { encoding: 'utf-8' });
16
+ return fs_extra_1.writeFile(outputPath, prettier_1.format(handlebars_1.compile(data)(context), { parser: 'typescript' }));
17
+ }
18
+ exports.write = write;
19
+ //# sourceMappingURL=writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer.js","sourceRoot":"","sources":["../../src/generator/writer.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,uCAAwD;AACxD,uCAAgC;AAChC,qDAA6B;AAC7B,2CAAmC;AAE5B,KAAK,UAAU,KAAK,CAAC,QAAgB,EAAE,MAAyB,EAAE,OAAa;IACpF,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,cAAI,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC5E,MAAM,oBAAS,CAAC,cAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,MAAM,mBAAQ,CAAC,cAAI,CAAC,OAAO,CAAC,eAAK,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,EAAC,QAAQ,EAAE,OAAO,EAAC,CAAC,CAAC;IAC1F,OAAO,oBAAS,CAAC,UAAU,EAAE,iBAAM,CAAC,oBAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,EAAC,MAAM,EAAE,YAAY,EAAC,CAAC,CAAC,CAAC;AACvF,CAAC;AALD,sBAKC"}
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { Automaton } from "@automatons/tools";
2
+ declare const generatorTypescriptAxiosClient: Automaton;
3
+ export default generatorTypescriptAxiosClient;
4
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAG5C,QAAA,MAAM,8BAA8B,EAAE,SACT,CAAC;AAE9B,eAAe,8BAA8B,CAAC"}
package/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const generator_1 = require("./generator");
4
+ const generatorTypescriptAxiosClient = (openapi, settings) => generator_1.generate(openapi, settings);
5
+ exports.default = generatorTypescriptAxiosClient;
6
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AACA,2CAAqC;AAErC,MAAM,8BAA8B,GAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,CACtE,oBAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAE9B,kBAAe,8BAA8B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@automatons/typescript-client-axios",
3
+ "version": "1.0.0",
4
+ "repository": "git@github.com:openapi-automatons/typescript-client-axios.git",
5
+ "author": "tanmen <yt.prog@gmail.com>",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "openapi",
9
+ "openapi-automatons",
10
+ "automatons",
11
+ "axios"
12
+ ],
13
+ "main": "index.js",
14
+ "scripts": {
15
+ "prebuild": "depcheck && node scripts/prebuild.js",
16
+ "build": "tsc && cp -R package.json README.md LICENSE src/templates dist",
17
+ "lint": "eslint src --ext .ts,.tsx",
18
+ "test": "jest",
19
+ "postinstall": "husky install && typesync && yarn check --integrity || yarn install --ignore-scripts && yarn-deduplicate",
20
+ "postversion": "cp package.json ../package.json"
21
+ },
22
+ "dependencies": {
23
+ "@automatons/parser": "^0.0.63",
24
+ "@automatons/tools": "^1.0.8",
25
+ "eslint": "^8.7.0",
26
+ "fs-extra": "^9.0.0",
27
+ "glob": "^7.2.0",
28
+ "handlebars": "^4.7.6",
29
+ "handlebars-helpers": "^0.10.0",
30
+ "prettier": "^2.5.1"
31
+ },
32
+ "peerDependencies": {
33
+ "axios": "^0",
34
+ "object-to-formdata": "^4",
35
+ "openapi-automatons": "^1"
36
+ },
37
+ "devDependencies": {
38
+ "@commitlint/cli": "^16.1.0",
39
+ "@commitlint/config-conventional": "^16.0.0",
40
+ "@semantic-release/changelog": "^6.0.1",
41
+ "@semantic-release/git": "^10.0.1",
42
+ "@semantic-release/npm": "^9.0.0",
43
+ "@types/eslint": "^8.4.1",
44
+ "@types/fs-extra": "^9.0.13",
45
+ "@types/glob": "^7.1.2",
46
+ "@types/handlebars": "^4.1.0",
47
+ "@types/handlebars-helpers": "^0.5.2",
48
+ "@types/jest": "^27.4.0",
49
+ "@types/js-yaml": "^4.0.5",
50
+ "@types/node": "^17.0.12",
51
+ "@types/prettier": "^2.0.0",
52
+ "@types/semantic-release": "^17.2.3",
53
+ "@typescript-eslint/eslint-plugin": "^5.10.1",
54
+ "@typescript-eslint/parser": "^5.10.1",
55
+ "depcheck": "^1.4.3",
56
+ "eslint": "^8.7.0",
57
+ "eslint-config-google": "^0.14.0",
58
+ "eslint-config-prettier": "^8.3.0",
59
+ "husky": "^7.0.4",
60
+ "jest": "^26.0.1",
61
+ "lint-staged": "^12.3.2",
62
+ "object-to-formdata": "^4.4.1",
63
+ "semantic-release": "^19.0.2",
64
+ "ts-jest": "^26.0.0",
65
+ "typescript": "^3.9.3",
66
+ "typesync": "^0.8.0",
67
+ "yarn-deduplicate": "^3.1.0"
68
+ },
69
+ "publishConfig": {
70
+ "access": "public"
71
+ }
72
+ }
package/paths.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ declare const paths: {
2
+ src: string;
3
+ templates: string;
4
+ tmp: string;
5
+ };
6
+ export default paths;
7
+ //# sourceMappingURL=paths.d.ts.map
package/paths.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,KAAK;;;;CAIV,CAAC;AACF,eAAe,KAAK,CAAC"}
package/paths.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const paths = {
8
+ src: path_1.default.resolve(__dirname),
9
+ templates: path_1.default.resolve(__dirname, 'templates'),
10
+ tmp: path_1.default.resolve(__dirname, '../tmp')
11
+ };
12
+ exports.default = paths;
13
+ //# sourceMappingURL=paths.js.map
package/paths.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AAExB,MAAM,KAAK,GAAG;IACZ,GAAG,EAAE,cAAI,CAAC,OAAO,CAAC,SAAS,CAAC;IAC5B,SAAS,EAAE,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC;IAC/C,GAAG,EAAE,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC;CACvC,CAAC;AACF,kBAAe,KAAK,CAAC"}
@@ -0,0 +1,59 @@
1
+ import Axios, { AxiosInstance } from "axios";
2
+ import { Config{{#if securities.length}}, 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.length}}
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, scopes?: string[]): 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
+ return scopes ? security(scopes) : security();
41
+ }
42
+ return security;
43
+ }
44
+ {{/if}}
45
+ }
46
+
47
+ /**
48
+ * AbstractApi
49
+ */
50
+ export class AbstractApi {
51
+ protected axios: AxiosInstance = BASE_AXIOS;
52
+
53
+ /**
54
+ * constructor
55
+ */
56
+ constructor({axios}: Config) {
57
+ if (axios) this.axios = axios;
58
+ }
59
+ }
@@ -0,0 +1,19 @@
1
+ import { AxiosResponse, AxiosRequestConfig } from "axios";
2
+ import { AbstractApi, AbstractConfig } from "./abstractApi";
3
+ import { Config{{#if securities.length}}, 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
+ {{#each api/imports~}}
10
+ import { {{title}} } from "../models";
11
+ {{/each}}
12
+
13
+ {{#each api/servers}}
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
+ {{/each}}
16
+
17
+ {{> apis/class api }}
18
+
19
+ {{> apis/config api }}
@@ -0,0 +1,3 @@
1
+ {{#each this ~}}
2
+ export * from "./{{filename}}";
3
+ {{/each}}
@@ -0,0 +1,3 @@
1
+ {{#if this~}}
2
+ server: {{#each this}}{{name}}Server{{#unless @last}} | {{/unless}}{{/each}}{{#lengthEqual this 1}} = { name: '{{this/0/name}}'{{#if this/0/values}}, values: { {{#each this/0/values}}{{name}}: '{{defaultValue}}',{{/each}} } {{/if}} }{{/lengthEqual}},
3
+ {{~/if}}
@@ -0,0 +1,3 @@
1
+ {{#if this~}}
2
+ server?: {{#each this}}{{name}}Server{{#unless @last}} | {{/unless}}{{/each}},
3
+ {{~/if}}
@@ -0,0 +1,21 @@
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
+ 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
+ {{~#if cookies}}cookies: {
16
+ {{~#each cookies}}
17
+ {{name}}{{#unless required}}?{{/unless}}: {{> models/type schema}},
18
+ {{/each}}
19
+ }{{#if (every cookies 'required' false)}} = {}{{/if}},
20
+ {{/if}}
21
+ {{~> apis/arguments/server servers}} config?: AxiosRequestConfig
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,4 @@
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}}
@@ -0,0 +1,14 @@
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
+ }
@@ -0,0 +1,4 @@
1
+ {{~#if queries}}queries,{{/if}}
2
+ headers,
3
+ {{~#if cookies}}cookies,{{/if}}
4
+ {{~#if servers}}server,{{/if}} config
@@ -0,0 +1,17 @@
1
+ {{> comment}}
2
+ export class {{title}} extends AbstractApi {
3
+ readonly #config: {{title}}Config;
4
+
5
+ /**
6
+ * constructor
7
+ * @param {Config} config
8
+ */
9
+ constructor(config: Config) {
10
+ super(config);
11
+ this.#config = new {{title}}Config({{#if securities.length}}config.security{{/if}});
12
+ }
13
+ {{#each paths}}
14
+
15
+ {{> apis/class/request }}
16
+ {{/each}}
17
+ }
@@ -0,0 +1,19 @@
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
+ 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
+ {{~#if cookies}}cookies: {
14
+ {{~#each cookies}}
15
+ {{name}}{{#unless required}}?{{/unless}}: {{> models/type schema}},
16
+ {{/each}}
17
+ }{{#if (every cookies 'required' false)}} = {}{{/if}},
18
+ {{/if}}
19
+ {{~> apis/arguments/server servers}} config?: AxiosRequestConfig
@@ -0,0 +1 @@
1
+ config?.baseURL ? config.baseURL : {{title}}Config.server(server)
@@ -0,0 +1,10 @@
1
+ {{~#each cookies}}
2
+ if (cookies.{{name}}) {
3
+ _cookies['{{name}}'] = query('{{name}}', cookies.{{name}}, 'form', {{#if explode}}true{{else}}false{{/if}});
4
+ }
5
+ {{/each}}
6
+ {{~#each securities}}
7
+ {{#and (eq type 'apiKey') (eq in 'cookie')~}}
8
+ _cookies['{{key}}'] = await this.security("{{name}}");
9
+ {{/and}}
10
+ {{/each}}
@@ -0,0 +1,14 @@
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}}
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,19 @@
1
+ public async {{name}}({{> apis/config/arguments}}): Promise<AxiosRequestConfig> {
2
+ const params = {{> apis/config/request/queries }};
3
+
4
+ const _cookies = { ...config?.headers?.Cookie };
5
+ {{> apis/config/request/cookies }}
6
+
7
+ const _headers = { ...config?.headers, 'Content-Type': headers['Content-Type'], Cookie: _cookies };
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
+ }
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,14 @@
1
+ class {{title}}Config extends AbstractConfig {
2
+ {{#if securities.length}}
3
+ constructor(security?: Security) {
4
+ super(security);
5
+ }
6
+ {{/if}}
7
+
8
+ {{> apis/config/server }}
9
+
10
+ {{#each paths}}
11
+
12
+ {{> apis/config/request title=../title }}
13
+ {{/each}}
14
+ }
@@ -0,0 +1,19 @@
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
+ }
@@ -0,0 +1,3 @@
1
+ {{#if model}}export * from './models';{{/if}}
2
+ {{#if api}}export * from './apis';{{/if}}
3
+ export * from './config';
@@ -0,0 +1,3 @@
1
+ {{#each this ~}}
2
+ export * from "./{{filename}}";
3
+ {{/each}}
@@ -0,0 +1,6 @@
1
+ {{#each imports~}}
2
+ import { {{title}} } from "./{{filename}}";
3
+ {{/each}}
4
+
5
+ {{> comment}}
6
+ export type {{title}} = {{> models/type schema}};
@@ -0,0 +1,7 @@
1
+ {{#noop~}}
2
+ (
3
+ {{~#each schemas}}
4
+ {{~#if @first}}{{> models/type}}{{else}} & {{> models/type}}{{/if~}}
5
+ {{/each~}}
6
+ )
7
+ {{~/noop}}
@@ -0,0 +1,6 @@
1
+ {{#if items ~}}
2
+ Array<{{#with items}}{{> models/type}}{{/with}}>
3
+ {{~ else ~}}
4
+ any[]
5
+ {{~/if}}
6
+ {{~> models/nullable}}
@@ -0,0 +1 @@
1
+ boolean{{> models/nullable}}
@@ -0,0 +1 @@
1
+ {{#if nullable}} | null{{/if}}
@@ -0,0 +1,6 @@
1
+ {{#if enum}}
2
+ {{~#each enum}}{{#if @first}}{{this}}{{else}} | {{this}}{{/if}}{{/each ~}}
3
+ {{~ else ~}}
4
+ number
5
+ {{~/if}}
6
+ {{> models/nullable}}
@@ -0,0 +1,13 @@
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}}
@@ -0,0 +1,7 @@
1
+ {{#noop~}}
2
+ (
3
+ {{~#each schemas}}
4
+ {{~#if @first}}{{> models/type}}{{else}} | {{> models/type}}{{/if~}}
5
+ {{/each~}}
6
+ )
7
+ {{~/noop}}
@@ -0,0 +1,10 @@
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}}
@@ -0,0 +1,19 @@
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}}
@@ -0,0 +1,24 @@
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
+ */
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1,3 @@
1
+ export * from './template';
2
+ export * from './query';
3
+ export * from './formData';
@@ -0,0 +1,74 @@
1
+ import {ParsedUrlQueryInput} from 'querystring';
2
+
3
+ const queryForm =
4
+ (name: string,
5
+ value: string | number | Array<string | number> | { [key: string]: string | number },
6
+ explode: boolean): ParsedUrlQueryInput => {
7
+ if (Array.isArray(value)) {
8
+ if (explode) {
9
+ return {[name]: value.map(String)}
10
+ } else {
11
+ return {[name]: value.join(',')}
12
+ }
13
+ } else if (value instanceof Object) {
14
+ if (explode) {
15
+ return value;
16
+ } else {
17
+ return {[name]: Object.entries(value).map((prop: [string, string | number]) => prop.join(',')).join(',')}
18
+ }
19
+ } else {
20
+ return {[name]: value};
21
+ }
22
+ }
23
+
24
+ const querySpaceDelimited =
25
+ (name: string,
26
+ value: string | number | Array<string | number> | { [key: string]: string | number }): ParsedUrlQueryInput => {
27
+ if (Array.isArray(value)) {
28
+ return {[name]: value.join(' ')}
29
+ } else if (value instanceof Object) {
30
+ return {[name]: Object.entries(value).map((prop: [string, string | number]) => prop.join(' ')).join(' ')}
31
+ }
32
+ throw new Error(`Unsupported value: ${name}`);
33
+ }
34
+
35
+ const queryPipeDelimited =
36
+ (name: string,
37
+ value: string | number | Array<string | number> | { [key: string]: string | number }): ParsedUrlQueryInput => {
38
+ if (Array.isArray(value)) {
39
+ return {[name]: value.join('|')}
40
+ } else if (value instanceof Object) {
41
+ return {[name]: Object.entries(value).map((prop: [string, string | number]) => prop.join('|')).join('|')}
42
+ }
43
+ throw new Error(`Unsupported value: ${name}`);
44
+ }
45
+
46
+ const queryDeepObject =
47
+ (name: string,
48
+ value: string | number | Array<string | number> | { [key: string]: string | number }): ParsedUrlQueryInput => {
49
+ if (!Array.isArray(value) && value instanceof Object) {
50
+ return Object.keys(value).reduce((pre, cur) => ({...pre, [`${name}[${cur}]`]: value[cur]}), {});
51
+ }
52
+ throw new Error(`Unsupported value: ${name}`);
53
+ }
54
+
55
+ export const query =
56
+ (
57
+ name: string,
58
+ value: undefined | string | number | Array<string | number> | { [key: string]: string | number },
59
+ style: 'form' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject',
60
+ explode: boolean): ParsedUrlQueryInput => {
61
+ if (value === undefined) return {};
62
+ switch (style) {
63
+ case 'form':
64
+ return queryForm(name, value, explode);
65
+ case 'spaceDelimited':
66
+ return querySpaceDelimited(name, value);
67
+ case 'pipeDelimited':
68
+ return queryPipeDelimited(name, value);
69
+ case 'deepObject':
70
+ return queryDeepObject(name, value);
71
+ default:
72
+ throw new Error(`Unsupported style: ${style}`);
73
+ }
74
+ }
@@ -0,0 +1,55 @@
1
+ const templateSimple = (explode: boolean, value: string | number | Array<string | number> | { [p: string]: string | number }): string => {
2
+ if (!explode) {
3
+ return value instanceof Object
4
+ ? Array.isArray(value)
5
+ ? value.join(',') : Object.entries(value).map(prop => prop.join(',')).flat().join(',')
6
+ : String(value);
7
+ }
8
+ return value instanceof Object
9
+ ? Array.isArray(value)
10
+ ? value.join(',') : Object.entries(value).map(([key, value]) => `${key}=${value}`).flat().join(',')
11
+ : String(value);
12
+ }
13
+
14
+ const templateLabel = (explode: boolean, value: string | number | Array<string | number> | { [p: string]: string | number }): string => {
15
+ if (!explode) {
16
+ return `.${value instanceof Object
17
+ ? Array.isArray(value)
18
+ ? value.join(',') : Object.entries(value).map(prop => prop.join(',')).flat().join(',')
19
+ : String(value)}`;
20
+ }
21
+ return value instanceof Object
22
+ ? Array.isArray(value)
23
+ ? value.join(',') : Object.entries(value).map(([key, value]) => `${key}=${value}`).flat().join(',')
24
+ : String(value);
25
+ }
26
+
27
+ const templateMatrix = (explode: boolean, name: string, value: string | number | Array<string | number> | { [p: string]: string | number }): string => {
28
+ if (!explode) {
29
+ return `;${name}=${value instanceof Object
30
+ ? Array.isArray(value)
31
+ ? value.join(',') : Object.entries(value).map(prop => prop.join(',')).flat().join(',')
32
+ : String(value)}`;
33
+ }
34
+ return `;${value instanceof Object
35
+ ? Array.isArray(value)
36
+ ? value.map(item => `${name}=${item}`).join(';')
37
+ : Object.entries(value).map(([key, value]) => `${key}=${value}`).flat().join(';')
38
+ : `${name}=${String(value)}`}`;
39
+ }
40
+
41
+ export const template =
42
+ (
43
+ name: string,
44
+ value: string | number | Array<string | number> | { [key: string]: string | number },
45
+ style: 'simple' | 'label' | 'matrix',
46
+ explode: boolean): string => {
47
+ if (style === 'simple') {
48
+ return templateSimple(explode, value);
49
+ } else if (style === 'label') {
50
+ return templateLabel(explode, value);
51
+ } else if (style === 'matrix') {
52
+ return templateMatrix(explode, name, value);
53
+ }
54
+ throw new Error(`Unsupported style: ${style}`)
55
+ }