@grandlinex/swagger-mate 0.30.8
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/LICENSE +29 -0
- package/README.md +137 -0
- package/dist/cjs/PathHelp.d.ts +2 -0
- package/dist/cjs/PathHelp.js +47 -0
- package/dist/cjs/Swagger/Client/ClientUtil.d.ts +59 -0
- package/dist/cjs/Swagger/Client/ClientUtil.js +208 -0
- package/dist/cjs/Swagger/Client/FunctionProps.d.ts +4 -0
- package/dist/cjs/Swagger/Client/FunctionProps.js +60 -0
- package/dist/cjs/Swagger/Client/FunctionTemplate.d.ts +13 -0
- package/dist/cjs/Swagger/Client/FunctionTemplate.js +46 -0
- package/dist/cjs/Swagger/Client/InterfaceTemplate.d.ts +3 -0
- package/dist/cjs/Swagger/Client/InterfaceTemplate.js +14 -0
- package/dist/cjs/Swagger/Client/SwaggerClient.d.ts +4 -0
- package/dist/cjs/Swagger/Client/SwaggerClient.js +197 -0
- package/dist/cjs/Swagger/Meta/Swagger.d.ts +10 -0
- package/dist/cjs/Swagger/Meta/Swagger.js +40 -0
- package/dist/cjs/Swagger/Meta/SwaggerTypes.d.ts +107 -0
- package/dist/cjs/Swagger/Meta/SwaggerTypes.js +9 -0
- package/dist/cjs/Swagger/Meta/SwaggerTypesStatic.d.ts +4 -0
- package/dist/cjs/Swagger/Meta/SwaggerTypesStatic.js +3 -0
- package/dist/cjs/Swagger/Path/SPathUtil.d.ts +28 -0
- package/dist/cjs/Swagger/Path/SPathUtil.js +228 -0
- package/dist/cjs/Swagger/Path/SUtilMap.d.ts +192 -0
- package/dist/cjs/Swagger/Path/SUtilMap.js +194 -0
- package/dist/cjs/Swagger/SwaggerUtil.d.ts +12 -0
- package/dist/cjs/Swagger/SwaggerUtil.js +195 -0
- package/dist/cjs/Swagger/debug/BaseCon.d.ts +68 -0
- package/dist/cjs/Swagger/debug/BaseCon.js +277 -0
- package/dist/cjs/Swagger/debug/FetchCon.d.ts +3 -0
- package/dist/cjs/Swagger/debug/FetchCon.js +79 -0
- package/dist/cjs/Swagger/debug/NodeCon.d.ts +3 -0
- package/dist/cjs/Swagger/debug/NodeCon.js +142 -0
- package/dist/cjs/Swagger/debug/index.d.ts +5 -0
- package/dist/cjs/Swagger/debug/index.js +27 -0
- package/dist/cjs/cli.d.ts +5 -0
- package/dist/cjs/cli.js +89 -0
- package/dist/cjs/index.d.ts +8 -0
- package/dist/cjs/index.js +30 -0
- package/dist/cjs/package.json +3 -0
- package/dist/mjs/PathHelp.d.ts +2 -0
- package/dist/mjs/PathHelp.js +16 -0
- package/dist/mjs/Swagger/Client/ClientUtil.d.ts +59 -0
- package/dist/mjs/Swagger/Client/ClientUtil.js +195 -0
- package/dist/mjs/Swagger/Client/FunctionProps.d.ts +4 -0
- package/dist/mjs/Swagger/Client/FunctionProps.js +58 -0
- package/dist/mjs/Swagger/Client/FunctionTemplate.d.ts +13 -0
- package/dist/mjs/Swagger/Client/FunctionTemplate.js +40 -0
- package/dist/mjs/Swagger/Client/InterfaceTemplate.d.ts +3 -0
- package/dist/mjs/Swagger/Client/InterfaceTemplate.js +13 -0
- package/dist/mjs/Swagger/Client/SwaggerClient.d.ts +4 -0
- package/dist/mjs/Swagger/Client/SwaggerClient.js +168 -0
- package/dist/mjs/Swagger/Meta/Swagger.d.ts +10 -0
- package/dist/mjs/Swagger/Meta/Swagger.js +32 -0
- package/dist/mjs/Swagger/Meta/SwaggerTypes.d.ts +107 -0
- package/dist/mjs/Swagger/Meta/SwaggerTypes.js +5 -0
- package/dist/mjs/Swagger/Meta/SwaggerTypesStatic.d.ts +4 -0
- package/dist/mjs/Swagger/Meta/SwaggerTypesStatic.js +2 -0
- package/dist/mjs/Swagger/Path/SPathUtil.d.ts +28 -0
- package/dist/mjs/Swagger/Path/SPathUtil.js +222 -0
- package/dist/mjs/Swagger/Path/SUtilMap.d.ts +192 -0
- package/dist/mjs/Swagger/Path/SUtilMap.js +192 -0
- package/dist/mjs/Swagger/SwaggerUtil.d.ts +12 -0
- package/dist/mjs/Swagger/SwaggerUtil.js +166 -0
- package/dist/mjs/Swagger/debug/BaseCon.d.ts +68 -0
- package/dist/mjs/Swagger/debug/BaseCon.js +269 -0
- package/dist/mjs/Swagger/debug/FetchCon.d.ts +3 -0
- package/dist/mjs/Swagger/debug/FetchCon.js +77 -0
- package/dist/mjs/Swagger/debug/NodeCon.d.ts +3 -0
- package/dist/mjs/Swagger/debug/NodeCon.js +114 -0
- package/dist/mjs/Swagger/debug/index.d.ts +5 -0
- package/dist/mjs/Swagger/debug/index.js +5 -0
- package/dist/mjs/cli.d.ts +5 -0
- package/dist/mjs/cli.js +61 -0
- package/dist/mjs/index.d.ts +8 -0
- package/dist/mjs/index.js +8 -0
- package/dist/mjs/package.json +3 -0
- package/package.json +77 -0
- package/res/html/index.html +69 -0
- package/res/html/swagger-ui-bundle.js +3 -0
- package/res/html/swagger-ui-standalone-preset.js +3 -0
- package/res/html/swagger-ui.css +3 -0
- package/res/templates/class/ApiCon.ts +11 -0
- package/res/templates/class/AxiosCon.ts +49 -0
- package/res/templates/class/BaseCon.ts +377 -0
- package/res/templates/class/CApiCon.ts +11 -0
- package/res/templates/class/FetchCon.ts +93 -0
- package/res/templates/class/IApiCon.ts +10 -0
- package/res/templates/class/NodeCon.ts +164 -0
- package/res/templates/class/index.ts +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023, GrandlineX
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Swagger-Mate
|
|
2
|
+
> GrandLineX Swagger-Mate project
|
|
3
|
+
|
|
4
|
+
[](https://github.com/GrandlineX/swagger-mate)
|
|
5
|
+
[](https://www.npmjs.com/package/@grandlinex/swagger-mate)
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
### Status
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
### Issues
|
|
16
|
+

|
|
17
|
+

|
|
18
|
+

|
|
19
|
+
|
|
20
|
+
## Features
|
|
21
|
+
|
|
22
|
+
- Generate swagger.{json|yml} from code
|
|
23
|
+
- Generate Api client from swagger.{json|yml}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### Install
|
|
29
|
+
|
|
30
|
+
1. Insatal npm package
|
|
31
|
+
```shell
|
|
32
|
+
npm i @grandlinex/swagger-mate
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
2. Update package.json
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
//...
|
|
39
|
+
"scripts": {
|
|
40
|
+
"makeSpec": "swagger-mate",
|
|
41
|
+
"serveSpec": "swagger-mate --serve",
|
|
42
|
+
"buildSpecMain": "swagger-mate --build --main",
|
|
43
|
+
"buildSpecDev": "swagger-mate --build --dev"
|
|
44
|
+
},
|
|
45
|
+
"glx": {
|
|
46
|
+
"kernel": "dist/Kernel.js"
|
|
47
|
+
}
|
|
48
|
+
//...
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
|Command| Description |
|
|
53
|
+
|---|-----------------------------------------------------------------------------------|
|
|
54
|
+
|`npm run makeSpec`| make `openapi.json` |
|
|
55
|
+
|`npm run serveSpec`| serve `openapi.json` with [swagger-ui](https://github.com/swagger-api/swagger-ui) |
|
|
56
|
+
|`npm run buildSpecMain`| build api client (prod) |
|
|
57
|
+
|`npm run buildSpecDev`| build api client (dev) |
|
|
58
|
+
|
|
59
|
+
### Serve option
|
|
60
|
+
|
|
61
|
+
> Default port = 9000
|
|
62
|
+
|
|
63
|
+
ENV variables
|
|
64
|
+
|
|
65
|
+
| ENV | Description |
|
|
66
|
+
|-----|--------------------------|
|
|
67
|
+
| SW_PORT | set custom serve port |
|
|
68
|
+
| SW_AUTH | set default bearer token |
|
|
69
|
+
|
|
70
|
+
## Define types
|
|
71
|
+
|
|
72
|
+
### Kernel
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { SPathUtil, Swagger } from '@grandlinex/swagger-mate';
|
|
76
|
+
// OpenApi 3.0.3 - Root Api definition
|
|
77
|
+
@Swagger({
|
|
78
|
+
info: {
|
|
79
|
+
title: 'KernelTest',
|
|
80
|
+
version: '0.1.0', // Version (optional) will be read from package.json
|
|
81
|
+
},
|
|
82
|
+
openapi: '3.0.3',
|
|
83
|
+
servers: [
|
|
84
|
+
{
|
|
85
|
+
url: 'http://localhost:9257',
|
|
86
|
+
description: 'LocalDev',
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
paths: {
|
|
90
|
+
// Static definition
|
|
91
|
+
'/version': {
|
|
92
|
+
get: {
|
|
93
|
+
description: 'Get version',
|
|
94
|
+
operationId: 'getVersion',
|
|
95
|
+
responses: SPathUtil.defaultResponse('200', '500'),
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
// Dynamic definition will be read from @SPath
|
|
99
|
+
},
|
|
100
|
+
security: [
|
|
101
|
+
{
|
|
102
|
+
bearerAuth: [],
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
components: {
|
|
106
|
+
securitySchemes: {
|
|
107
|
+
bearerAuth: {
|
|
108
|
+
type: 'http',
|
|
109
|
+
scheme: 'bearer',
|
|
110
|
+
bearerFormat: 'JWT',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
})
|
|
115
|
+
export default class SomeKernel {}
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Action
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { SPathUtil, Swagger } from '@grandlinex/swagger-mate';
|
|
123
|
+
|
|
124
|
+
// OpenApi 3.0.3 - Patch definition
|
|
125
|
+
@SPath({
|
|
126
|
+
'/test': {
|
|
127
|
+
get: {
|
|
128
|
+
description: 'test',
|
|
129
|
+
operationId: 'getTest', // name for the js api client
|
|
130
|
+
summary: 'Descritption summary',
|
|
131
|
+
responses: SPathUtil.defaultResponse('200','400', '500')
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
})
|
|
135
|
+
export default class SomeBaseApiAction {}
|
|
136
|
+
|
|
137
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.getBaseFolder = void 0;
|
|
30
|
+
const path_1 = __importDefault(require("path"));
|
|
31
|
+
const process = __importStar(require("process"));
|
|
32
|
+
function getBaseFolder() {
|
|
33
|
+
const dir = typeof __dirname !== 'undefined' ? __dirname : process.env.SM__DIRNAME;
|
|
34
|
+
if (!dir) {
|
|
35
|
+
throw new Error('Cant find base folder');
|
|
36
|
+
}
|
|
37
|
+
return dir;
|
|
38
|
+
}
|
|
39
|
+
exports.getBaseFolder = getBaseFolder;
|
|
40
|
+
function PathHelp(base, ...inp) {
|
|
41
|
+
const { env } = process;
|
|
42
|
+
if (env.dev) {
|
|
43
|
+
return path_1.default.join(base, ...inp);
|
|
44
|
+
}
|
|
45
|
+
return path_1.default.join(base, '..', ...inp);
|
|
46
|
+
}
|
|
47
|
+
exports.default = PathHelp;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { SSchemaEl } from '../Meta/SwaggerTypes.js';
|
|
2
|
+
export type IfMappingKeyType = {
|
|
3
|
+
key: string;
|
|
4
|
+
type: string;
|
|
5
|
+
required?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type IfMappingType = {
|
|
8
|
+
name: string;
|
|
9
|
+
keys: IfMappingKeyType[];
|
|
10
|
+
rawType?: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Save string from unknown
|
|
14
|
+
* @param e
|
|
15
|
+
*/
|
|
16
|
+
export declare function eS(e: any): string;
|
|
17
|
+
/**
|
|
18
|
+
* Optional field
|
|
19
|
+
* @param required
|
|
20
|
+
*/
|
|
21
|
+
export declare function rq(required?: boolean): string;
|
|
22
|
+
export declare function sK(e: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Cast first letter to uppercase
|
|
25
|
+
* @param e
|
|
26
|
+
*/
|
|
27
|
+
export declare function fuc(e: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Spacing function
|
|
30
|
+
* @param c number of spaces
|
|
31
|
+
*/
|
|
32
|
+
export declare function S(c: number): string;
|
|
33
|
+
export declare enum IFTag {
|
|
34
|
+
'RequestBody' = "RequestBody",
|
|
35
|
+
'Response' = "Response"
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* InterfaceName secure function
|
|
39
|
+
*/
|
|
40
|
+
export declare function saveName(inp: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* InterfaceName Helper function
|
|
43
|
+
*/
|
|
44
|
+
export declare function ifName(operation: string, tag: IFTag | string, use?: boolean): string;
|
|
45
|
+
export declare function typeByRef(ref: string, use?: boolean): string;
|
|
46
|
+
/**
|
|
47
|
+
* Map schema to typescript interface
|
|
48
|
+
* @param operation
|
|
49
|
+
* @param tag
|
|
50
|
+
* @param schema
|
|
51
|
+
*/
|
|
52
|
+
export declare function transformInterface(operation: string, tag: IFTag | string, schema: SSchemaEl): IfMappingType[];
|
|
53
|
+
/**
|
|
54
|
+
* Map schema to typescript interface
|
|
55
|
+
* @param operation
|
|
56
|
+
* @param tag
|
|
57
|
+
* @param schema
|
|
58
|
+
*/
|
|
59
|
+
export declare function transformFormInterface(operation: string, tag: IFTag | string, schema: SSchemaEl): IfMappingType[];
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformFormInterface = exports.transformInterface = exports.typeByRef = exports.ifName = exports.saveName = exports.IFTag = exports.S = exports.fuc = exports.sK = exports.rq = exports.eS = void 0;
|
|
4
|
+
const SwaggerTypes_js_1 = require("../Meta/SwaggerTypes.js");
|
|
5
|
+
/**
|
|
6
|
+
* Save string from unknown
|
|
7
|
+
* @param e
|
|
8
|
+
*/
|
|
9
|
+
function eS(e) {
|
|
10
|
+
return e || '';
|
|
11
|
+
}
|
|
12
|
+
exports.eS = eS;
|
|
13
|
+
/**
|
|
14
|
+
* Optional field
|
|
15
|
+
* @param required
|
|
16
|
+
*/
|
|
17
|
+
function rq(required) {
|
|
18
|
+
if (!required) {
|
|
19
|
+
return '?:';
|
|
20
|
+
}
|
|
21
|
+
return ':';
|
|
22
|
+
}
|
|
23
|
+
exports.rq = rq;
|
|
24
|
+
function sK(e) {
|
|
25
|
+
if (e.indexOf(':') >= 0) {
|
|
26
|
+
return `'${e}'`;
|
|
27
|
+
}
|
|
28
|
+
return e;
|
|
29
|
+
}
|
|
30
|
+
exports.sK = sK;
|
|
31
|
+
/**
|
|
32
|
+
* Cast first letter to uppercase
|
|
33
|
+
* @param e
|
|
34
|
+
*/
|
|
35
|
+
function fuc(e) {
|
|
36
|
+
if (e.length === 0) {
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
return e.charAt(0).toUpperCase() + e.substring(1);
|
|
40
|
+
}
|
|
41
|
+
exports.fuc = fuc;
|
|
42
|
+
/**
|
|
43
|
+
* Spacing function
|
|
44
|
+
* @param c number of spaces
|
|
45
|
+
*/
|
|
46
|
+
function S(c) {
|
|
47
|
+
let o = '';
|
|
48
|
+
for (let i = 0; i < c; i++) {
|
|
49
|
+
o += ' ';
|
|
50
|
+
}
|
|
51
|
+
return o;
|
|
52
|
+
}
|
|
53
|
+
exports.S = S;
|
|
54
|
+
var IFTag;
|
|
55
|
+
(function (IFTag) {
|
|
56
|
+
IFTag["RequestBody"] = "RequestBody";
|
|
57
|
+
IFTag["Response"] = "Response";
|
|
58
|
+
})(IFTag || (exports.IFTag = IFTag = {}));
|
|
59
|
+
/**
|
|
60
|
+
* InterfaceName secure function
|
|
61
|
+
*/
|
|
62
|
+
function saveName(inp) {
|
|
63
|
+
return inp.replace(/[^a-zA-Z0-9[\]]/g, 'X');
|
|
64
|
+
}
|
|
65
|
+
exports.saveName = saveName;
|
|
66
|
+
/**
|
|
67
|
+
* InterfaceName Helper function
|
|
68
|
+
*/
|
|
69
|
+
function ifName(operation, tag, use) {
|
|
70
|
+
return `${use ? 'TX.' : ''}${saveName(fuc(operation))}${saveName(fuc(tag))}`;
|
|
71
|
+
}
|
|
72
|
+
exports.ifName = ifName;
|
|
73
|
+
function typeByRef(ref, use) {
|
|
74
|
+
return `${use ? 'TX.' : ''}${fuc(ref.substring(1 + ref.lastIndexOf('/')))}`;
|
|
75
|
+
}
|
|
76
|
+
exports.typeByRef = typeByRef;
|
|
77
|
+
/**
|
|
78
|
+
* Map schema to typescript interface
|
|
79
|
+
* @param operation
|
|
80
|
+
* @param tag
|
|
81
|
+
* @param schema
|
|
82
|
+
*/
|
|
83
|
+
function transformInterface(operation, tag, schema) {
|
|
84
|
+
const out = [];
|
|
85
|
+
const cur = {
|
|
86
|
+
name: ifName(operation, tag),
|
|
87
|
+
keys: [],
|
|
88
|
+
};
|
|
89
|
+
let keys = null;
|
|
90
|
+
if (!(0, SwaggerTypes_js_1.isSwaggerRef)(schema)) {
|
|
91
|
+
switch (schema.type) {
|
|
92
|
+
case 'object':
|
|
93
|
+
if (schema.properties) {
|
|
94
|
+
keys = Object.keys(schema.properties || {});
|
|
95
|
+
for (const key of keys) {
|
|
96
|
+
const prop = schema.properties[key];
|
|
97
|
+
const isRequired = schema.required && schema.required.includes(key);
|
|
98
|
+
if (!(0, SwaggerTypes_js_1.isSwaggerRef)(prop)) {
|
|
99
|
+
switch (prop.type) {
|
|
100
|
+
case 'number':
|
|
101
|
+
case 'integer':
|
|
102
|
+
cur.keys.push({ key, type: 'number', required: isRequired });
|
|
103
|
+
break;
|
|
104
|
+
case 'string':
|
|
105
|
+
cur.keys.push({ key, type: 'string', required: isRequired });
|
|
106
|
+
break;
|
|
107
|
+
case 'boolean':
|
|
108
|
+
cur.keys.push({ key, type: 'boolean', required: isRequired });
|
|
109
|
+
break;
|
|
110
|
+
case 'object':
|
|
111
|
+
if (!prop.properties) {
|
|
112
|
+
cur.keys.push({ key, type: 'any', required: isRequired });
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
cur.keys.push({
|
|
116
|
+
key,
|
|
117
|
+
type: ifName(cur.name, key),
|
|
118
|
+
required: isRequired,
|
|
119
|
+
});
|
|
120
|
+
out.push(...transformInterface(cur.name, key, prop));
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
case 'array':
|
|
124
|
+
if ((0, SwaggerTypes_js_1.isSwaggerRef)(prop.items)) {
|
|
125
|
+
cur.keys.push({
|
|
126
|
+
key,
|
|
127
|
+
type: `${typeByRef(prop.items.$ref)}[]`,
|
|
128
|
+
required: isRequired,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
cur.keys.push({
|
|
133
|
+
key,
|
|
134
|
+
type: `${ifName(cur.name, `${key}Element`)}[]`,
|
|
135
|
+
required: isRequired,
|
|
136
|
+
});
|
|
137
|
+
out.push(...transformInterface(cur.name, key, prop));
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
default:
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
cur.keys.push({
|
|
145
|
+
key,
|
|
146
|
+
type: typeByRef(prop.$ref),
|
|
147
|
+
required: isRequired,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
out.push(cur);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
out.push({
|
|
155
|
+
...cur,
|
|
156
|
+
rawType: 'any',
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
break;
|
|
160
|
+
case 'array':
|
|
161
|
+
if (schema.items) {
|
|
162
|
+
if ((0, SwaggerTypes_js_1.isSwaggerRef)(schema.items)) {
|
|
163
|
+
out.push({
|
|
164
|
+
keys: [],
|
|
165
|
+
name: cur.name,
|
|
166
|
+
rawType: `${typeByRef(schema.items.$ref)}[]`,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
const int = transformInterface(cur.name, 'Element', schema.items);
|
|
171
|
+
out.push(...int);
|
|
172
|
+
out.push({
|
|
173
|
+
keys: [],
|
|
174
|
+
name: cur.name,
|
|
175
|
+
rawType: `${ifName(cur.name, 'Element')}[]`,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
break;
|
|
180
|
+
default:
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
cur.rawType = `${typeByRef(schema.$ref)}`;
|
|
186
|
+
out.push(cur);
|
|
187
|
+
}
|
|
188
|
+
return out;
|
|
189
|
+
}
|
|
190
|
+
exports.transformInterface = transformInterface;
|
|
191
|
+
/**
|
|
192
|
+
* Map schema to typescript interface
|
|
193
|
+
* @param operation
|
|
194
|
+
* @param tag
|
|
195
|
+
* @param schema
|
|
196
|
+
*/
|
|
197
|
+
function transformFormInterface(operation, tag, schema) {
|
|
198
|
+
const out = [];
|
|
199
|
+
const cur = {
|
|
200
|
+
name: ifName(operation, tag),
|
|
201
|
+
keys: [],
|
|
202
|
+
};
|
|
203
|
+
const keys = null;
|
|
204
|
+
cur.rawType = `FormData`;
|
|
205
|
+
out.push(cur);
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
208
|
+
exports.transformFormInterface = transformFormInterface;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SwaggerRPathConf } from '../Meta/SwaggerTypes.js';
|
|
2
|
+
import { FunctionTemplateProps } from './FunctionTemplate.js';
|
|
3
|
+
declare function functionProps(route: string, t: 'get' | 'post' | 'patch' | 'delete' | 'update', cur: SwaggerRPathConf): FunctionTemplateProps;
|
|
4
|
+
export default functionProps;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const SwaggerTypes_js_1 = require("../Meta/SwaggerTypes.js");
|
|
4
|
+
const ClientUtil_js_1 = require("./ClientUtil.js");
|
|
5
|
+
const FunctionTemplate_js_1 = require("./FunctionTemplate.js");
|
|
6
|
+
function functionProps(route, t, cur) {
|
|
7
|
+
const comments = [];
|
|
8
|
+
if (cur.description) {
|
|
9
|
+
comments.push(cur.description);
|
|
10
|
+
}
|
|
11
|
+
if (cur.summary) {
|
|
12
|
+
comments.push(cur.summary);
|
|
13
|
+
}
|
|
14
|
+
const queryKey = [];
|
|
15
|
+
const param = [];
|
|
16
|
+
const paramKey = [];
|
|
17
|
+
let bodyType = 'unknown';
|
|
18
|
+
cur.parameters
|
|
19
|
+
?.filter((el) => el.in === 'path')
|
|
20
|
+
.forEach((el) => {
|
|
21
|
+
param.push(`${el.name}: string `);
|
|
22
|
+
paramKey.push(el.name);
|
|
23
|
+
if (el.description) {
|
|
24
|
+
comments.push(`@param ${el.name} ${el.description}`);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
if (cur.requestBody && cur.operationId) {
|
|
28
|
+
bodyType = (0, ClientUtil_js_1.ifName)(cur.operationId, ClientUtil_js_1.IFTag.RequestBody, true);
|
|
29
|
+
param.push(`body: ${bodyType}`);
|
|
30
|
+
}
|
|
31
|
+
cur.parameters
|
|
32
|
+
?.filter((el) => el.in === 'query')
|
|
33
|
+
.forEach((el) => {
|
|
34
|
+
param.push(`${el.name}?: string `);
|
|
35
|
+
queryKey.push(el.name);
|
|
36
|
+
if (el.description) {
|
|
37
|
+
comments.push(`@param ${el.name} ${el.description}`);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
let type = 'unknown';
|
|
41
|
+
const active = cur.responses?.['200'] || cur.responses?.['201'];
|
|
42
|
+
if (cur.operationId &&
|
|
43
|
+
active &&
|
|
44
|
+
!(0, SwaggerTypes_js_1.isSwaggerRef)(active) &&
|
|
45
|
+
active.content?.['application/json']) {
|
|
46
|
+
type = (0, ClientUtil_js_1.ifName)(cur.operationId, ClientUtil_js_1.IFTag.Response, true);
|
|
47
|
+
}
|
|
48
|
+
else if (cur.operationId && active && (0, SwaggerTypes_js_1.isSwaggerRef)(active)) {
|
|
49
|
+
type = (0, ClientUtil_js_1.typeByRef)(active.$ref, true);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
FC_PROPS: `${param.join(',')}`,
|
|
53
|
+
FC_BODY: (0, FunctionTemplate_js_1.reqBody)(t.toUpperCase(), route, paramKey, !!cur.requestBody, type, bodyType, queryKey),
|
|
54
|
+
FC_GEN: '',
|
|
55
|
+
FC_RETURN: `: Promise<HandleRes<${type}>> `,
|
|
56
|
+
FC_ASYNC: 'async ',
|
|
57
|
+
FC_DOC: comments,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
exports.default = functionProps;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type FunctionTemplateProps = {
|
|
2
|
+
FC_PROPS: string;
|
|
3
|
+
FC_BODY: string;
|
|
4
|
+
FC_GEN: string;
|
|
5
|
+
FC_RETURN: string;
|
|
6
|
+
FC_ASYNC: string;
|
|
7
|
+
FC_DOC: string[];
|
|
8
|
+
};
|
|
9
|
+
declare function functionTemplate(FC_NAME: string, props: Partial<FunctionTemplateProps>): string;
|
|
10
|
+
declare function functionInterfaceTemplate(FC_NAME: string, props: Partial<FunctionTemplateProps>): string;
|
|
11
|
+
declare function abstractInterfaceTemplate(FC_NAME: string, props: Partial<FunctionTemplateProps>): string;
|
|
12
|
+
declare function reqBody(rType: string, path: string, paramKey: string[], hasBody: boolean, type: string, bodyType: string, queryKey: string[]): string;
|
|
13
|
+
export { functionTemplate, reqBody, functionInterfaceTemplate, abstractInterfaceTemplate, };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.abstractInterfaceTemplate = exports.functionInterfaceTemplate = exports.reqBody = exports.functionTemplate = void 0;
|
|
4
|
+
const ClientUtil_js_1 = require("./ClientUtil.js");
|
|
5
|
+
function docTemplate(inp, doc) {
|
|
6
|
+
const dDoc = [];
|
|
7
|
+
if (doc && doc.length > 0) {
|
|
8
|
+
dDoc.push(`${(0, ClientUtil_js_1.S)(2)}/**`);
|
|
9
|
+
doc.forEach((el) => dDoc.push(`${(0, ClientUtil_js_1.S)(2)} * ${el}`));
|
|
10
|
+
dDoc.push(`${(0, ClientUtil_js_1.S)(2)} */`);
|
|
11
|
+
return [...dDoc, inp].join('\n');
|
|
12
|
+
}
|
|
13
|
+
return inp;
|
|
14
|
+
}
|
|
15
|
+
function functionTemplate(FC_NAME, props) {
|
|
16
|
+
const { FC_PROPS, FC_BODY, FC_RETURN, FC_GEN, FC_ASYNC } = props;
|
|
17
|
+
return docTemplate(`${(0, ClientUtil_js_1.S)(2)}${(0, ClientUtil_js_1.eS)(FC_ASYNC)}${(0, ClientUtil_js_1.eS)(FC_NAME)}${(0, ClientUtil_js_1.eS)(FC_GEN)}(${(0, ClientUtil_js_1.eS)(FC_PROPS)})${(0, ClientUtil_js_1.eS)(FC_RETURN)}{
|
|
18
|
+
${(0, ClientUtil_js_1.S)(4)}${(0, ClientUtil_js_1.eS)(FC_BODY)}
|
|
19
|
+
${(0, ClientUtil_js_1.S)(2)}}`, props.FC_DOC);
|
|
20
|
+
}
|
|
21
|
+
exports.functionTemplate = functionTemplate;
|
|
22
|
+
function functionInterfaceTemplate(FC_NAME, props) {
|
|
23
|
+
const { FC_PROPS, FC_RETURN, FC_GEN, FC_DOC } = props;
|
|
24
|
+
return docTemplate(`${(0, ClientUtil_js_1.S)(2)}${(0, ClientUtil_js_1.eS)(FC_NAME)}${(0, ClientUtil_js_1.eS)(FC_GEN)}(${(0, ClientUtil_js_1.eS)(FC_PROPS)})${(0, ClientUtil_js_1.eS)(FC_RETURN)}`, FC_DOC);
|
|
25
|
+
}
|
|
26
|
+
exports.functionInterfaceTemplate = functionInterfaceTemplate;
|
|
27
|
+
function abstractInterfaceTemplate(FC_NAME, props) {
|
|
28
|
+
const { FC_PROPS, FC_RETURN, FC_GEN, FC_DOC } = props;
|
|
29
|
+
return docTemplate(`${(0, ClientUtil_js_1.S)(2)}abstract ${(0, ClientUtil_js_1.eS)(FC_NAME)}${(0, ClientUtil_js_1.eS)(FC_GEN)}(${(0, ClientUtil_js_1.eS)(FC_PROPS)})${(0, ClientUtil_js_1.eS)(FC_RETURN)};`, FC_DOC);
|
|
30
|
+
}
|
|
31
|
+
exports.abstractInterfaceTemplate = abstractInterfaceTemplate;
|
|
32
|
+
function reqBody(rType, path, paramKey, hasBody, type, bodyType, queryKey) {
|
|
33
|
+
let q = 'undefined';
|
|
34
|
+
if (queryKey.length > 0 || paramKey.length > 0) {
|
|
35
|
+
const comp = [];
|
|
36
|
+
if (paramKey.length > 0) {
|
|
37
|
+
comp.push(`param: {${paramKey.join(',')}}`);
|
|
38
|
+
}
|
|
39
|
+
if (queryKey.length > 0) {
|
|
40
|
+
comp.push(`query: {${queryKey.join(',')}}`);
|
|
41
|
+
}
|
|
42
|
+
q = `{${comp.join(',')}}`;
|
|
43
|
+
}
|
|
44
|
+
return `return this.handle<${type}, ${bodyType}>('${rType}','${path}',${hasBody ? 'body' : 'undefined'}, ${q});`;
|
|
45
|
+
}
|
|
46
|
+
exports.reqBody = reqBody;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interfaceTemplate = void 0;
|
|
4
|
+
/* eslint-disable prettier/prettier */
|
|
5
|
+
const ClientUtil_js_1 = require("./ClientUtil.js");
|
|
6
|
+
function interfaceTemplate(IF_NAME, types, rawType) {
|
|
7
|
+
if (rawType) {
|
|
8
|
+
return `export type ${IF_NAME} = ${rawType};`;
|
|
9
|
+
}
|
|
10
|
+
return `export interface ${IF_NAME} {
|
|
11
|
+
${types.map(({ key, type, required }) => `${(0, ClientUtil_js_1.S)(2)}${(0, ClientUtil_js_1.sK)(key)}${(0, ClientUtil_js_1.rq)(required)} ${type};`).join('\n')}
|
|
12
|
+
}`;
|
|
13
|
+
}
|
|
14
|
+
exports.interfaceTemplate = interfaceTemplate;
|