@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
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
declare const DefaultMap: {
|
|
2
|
+
'100': {
|
|
3
|
+
description: string;
|
|
4
|
+
};
|
|
5
|
+
'101': {
|
|
6
|
+
description: string;
|
|
7
|
+
};
|
|
8
|
+
'102': {
|
|
9
|
+
description: string;
|
|
10
|
+
};
|
|
11
|
+
'103': {
|
|
12
|
+
description: string;
|
|
13
|
+
};
|
|
14
|
+
'200': {
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
'201': {
|
|
18
|
+
description: string;
|
|
19
|
+
};
|
|
20
|
+
'202': {
|
|
21
|
+
description: string;
|
|
22
|
+
};
|
|
23
|
+
'203': {
|
|
24
|
+
description: string;
|
|
25
|
+
};
|
|
26
|
+
'204': {
|
|
27
|
+
description: string;
|
|
28
|
+
};
|
|
29
|
+
'205': {
|
|
30
|
+
description: string;
|
|
31
|
+
};
|
|
32
|
+
'206': {
|
|
33
|
+
description: string;
|
|
34
|
+
};
|
|
35
|
+
'207': {
|
|
36
|
+
description: string;
|
|
37
|
+
};
|
|
38
|
+
'208': {
|
|
39
|
+
description: string;
|
|
40
|
+
};
|
|
41
|
+
'226': {
|
|
42
|
+
description: string;
|
|
43
|
+
};
|
|
44
|
+
'300': {
|
|
45
|
+
description: string;
|
|
46
|
+
};
|
|
47
|
+
'301': {
|
|
48
|
+
description: string;
|
|
49
|
+
};
|
|
50
|
+
'302': {
|
|
51
|
+
description: string;
|
|
52
|
+
};
|
|
53
|
+
'303': {
|
|
54
|
+
description: string;
|
|
55
|
+
};
|
|
56
|
+
'304': {
|
|
57
|
+
description: string;
|
|
58
|
+
};
|
|
59
|
+
'305': {
|
|
60
|
+
description: string;
|
|
61
|
+
};
|
|
62
|
+
'306': {
|
|
63
|
+
description: string;
|
|
64
|
+
};
|
|
65
|
+
'307': {
|
|
66
|
+
description: string;
|
|
67
|
+
};
|
|
68
|
+
'308': {
|
|
69
|
+
description: string;
|
|
70
|
+
};
|
|
71
|
+
'400': {
|
|
72
|
+
description: string;
|
|
73
|
+
};
|
|
74
|
+
'401': {
|
|
75
|
+
description: string;
|
|
76
|
+
};
|
|
77
|
+
'402': {
|
|
78
|
+
description: string;
|
|
79
|
+
};
|
|
80
|
+
'403': {
|
|
81
|
+
description: string;
|
|
82
|
+
};
|
|
83
|
+
'404': {
|
|
84
|
+
description: string;
|
|
85
|
+
};
|
|
86
|
+
'405': {
|
|
87
|
+
description: string;
|
|
88
|
+
};
|
|
89
|
+
'406': {
|
|
90
|
+
description: string;
|
|
91
|
+
};
|
|
92
|
+
'407': {
|
|
93
|
+
description: string;
|
|
94
|
+
};
|
|
95
|
+
'408': {
|
|
96
|
+
description: string;
|
|
97
|
+
};
|
|
98
|
+
'409': {
|
|
99
|
+
description: string;
|
|
100
|
+
};
|
|
101
|
+
'410': {
|
|
102
|
+
description: string;
|
|
103
|
+
};
|
|
104
|
+
'411': {
|
|
105
|
+
description: string;
|
|
106
|
+
};
|
|
107
|
+
'412': {
|
|
108
|
+
description: string;
|
|
109
|
+
};
|
|
110
|
+
'413': {
|
|
111
|
+
description: string;
|
|
112
|
+
};
|
|
113
|
+
'414': {
|
|
114
|
+
description: string;
|
|
115
|
+
};
|
|
116
|
+
'415': {
|
|
117
|
+
description: string;
|
|
118
|
+
};
|
|
119
|
+
'416': {
|
|
120
|
+
description: string;
|
|
121
|
+
};
|
|
122
|
+
'417': {
|
|
123
|
+
description: string;
|
|
124
|
+
};
|
|
125
|
+
'418': {
|
|
126
|
+
description: string;
|
|
127
|
+
};
|
|
128
|
+
'421': {
|
|
129
|
+
description: string;
|
|
130
|
+
};
|
|
131
|
+
'422': {
|
|
132
|
+
description: string;
|
|
133
|
+
};
|
|
134
|
+
'423': {
|
|
135
|
+
description: string;
|
|
136
|
+
};
|
|
137
|
+
'424': {
|
|
138
|
+
description: string;
|
|
139
|
+
};
|
|
140
|
+
'425': {
|
|
141
|
+
description: string;
|
|
142
|
+
};
|
|
143
|
+
'426': {
|
|
144
|
+
description: string;
|
|
145
|
+
};
|
|
146
|
+
'428': {
|
|
147
|
+
description: string;
|
|
148
|
+
};
|
|
149
|
+
'429': {
|
|
150
|
+
description: string;
|
|
151
|
+
};
|
|
152
|
+
'431': {
|
|
153
|
+
description: string;
|
|
154
|
+
};
|
|
155
|
+
'451': {
|
|
156
|
+
description: string;
|
|
157
|
+
};
|
|
158
|
+
'500': {
|
|
159
|
+
description: string;
|
|
160
|
+
};
|
|
161
|
+
'501': {
|
|
162
|
+
description: string;
|
|
163
|
+
};
|
|
164
|
+
'502': {
|
|
165
|
+
description: string;
|
|
166
|
+
};
|
|
167
|
+
'503': {
|
|
168
|
+
description: string;
|
|
169
|
+
};
|
|
170
|
+
'504': {
|
|
171
|
+
description: string;
|
|
172
|
+
};
|
|
173
|
+
'505': {
|
|
174
|
+
description: string;
|
|
175
|
+
};
|
|
176
|
+
'506': {
|
|
177
|
+
description: string;
|
|
178
|
+
};
|
|
179
|
+
'507': {
|
|
180
|
+
description: string;
|
|
181
|
+
};
|
|
182
|
+
'508': {
|
|
183
|
+
description: string;
|
|
184
|
+
};
|
|
185
|
+
'510': {
|
|
186
|
+
description: string;
|
|
187
|
+
};
|
|
188
|
+
'511': {
|
|
189
|
+
description: string;
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
export default DefaultMap;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const DefaultMap = {
|
|
4
|
+
'100': {
|
|
5
|
+
description: 'Continue',
|
|
6
|
+
},
|
|
7
|
+
'101': {
|
|
8
|
+
description: 'Switching protocols',
|
|
9
|
+
},
|
|
10
|
+
'102': {
|
|
11
|
+
description: 'Processing',
|
|
12
|
+
},
|
|
13
|
+
'103': {
|
|
14
|
+
description: 'Early Hints',
|
|
15
|
+
},
|
|
16
|
+
'200': {
|
|
17
|
+
description: 'OK',
|
|
18
|
+
},
|
|
19
|
+
'201': {
|
|
20
|
+
description: 'Created',
|
|
21
|
+
},
|
|
22
|
+
'202': {
|
|
23
|
+
description: 'Accepted',
|
|
24
|
+
},
|
|
25
|
+
'203': {
|
|
26
|
+
description: ' Non-Authoritative Information',
|
|
27
|
+
},
|
|
28
|
+
'204': {
|
|
29
|
+
description: 'No Content',
|
|
30
|
+
},
|
|
31
|
+
'205': {
|
|
32
|
+
description: 'Reset Content',
|
|
33
|
+
},
|
|
34
|
+
'206': {
|
|
35
|
+
description: 'Partial Content',
|
|
36
|
+
},
|
|
37
|
+
'207': {
|
|
38
|
+
description: 'Multi-Status',
|
|
39
|
+
},
|
|
40
|
+
'208': {
|
|
41
|
+
description: 'Already Reported',
|
|
42
|
+
},
|
|
43
|
+
'226': {
|
|
44
|
+
description: 'IM Used',
|
|
45
|
+
},
|
|
46
|
+
'300': {
|
|
47
|
+
description: 'Multiple Choices',
|
|
48
|
+
},
|
|
49
|
+
'301': {
|
|
50
|
+
description: 'Moved Permanently',
|
|
51
|
+
},
|
|
52
|
+
'302': {
|
|
53
|
+
description: 'Found (Previously MovedTemporarily)',
|
|
54
|
+
},
|
|
55
|
+
'303': {
|
|
56
|
+
description: 'See Other',
|
|
57
|
+
},
|
|
58
|
+
'304': {
|
|
59
|
+
description: 'Not Modified',
|
|
60
|
+
},
|
|
61
|
+
'305': {
|
|
62
|
+
description: 'Use Proxy',
|
|
63
|
+
},
|
|
64
|
+
'306': {
|
|
65
|
+
description: 'Switch Proxy',
|
|
66
|
+
},
|
|
67
|
+
'307': {
|
|
68
|
+
description: 'Temporary Redirect',
|
|
69
|
+
},
|
|
70
|
+
'308': {
|
|
71
|
+
description: 'Permanent Redirect',
|
|
72
|
+
},
|
|
73
|
+
'400': {
|
|
74
|
+
description: 'Bad Request',
|
|
75
|
+
},
|
|
76
|
+
'401': {
|
|
77
|
+
description: 'Unauthorized',
|
|
78
|
+
},
|
|
79
|
+
'402': {
|
|
80
|
+
description: 'Payment Required',
|
|
81
|
+
},
|
|
82
|
+
'403': {
|
|
83
|
+
description: 'Forbidden',
|
|
84
|
+
},
|
|
85
|
+
'404': {
|
|
86
|
+
description: 'Not Found',
|
|
87
|
+
},
|
|
88
|
+
'405': {
|
|
89
|
+
description: 'Method Not Allowed',
|
|
90
|
+
},
|
|
91
|
+
'406': {
|
|
92
|
+
description: 'Not Acceptable',
|
|
93
|
+
},
|
|
94
|
+
'407': {
|
|
95
|
+
description: 'Proxy Authentication Required',
|
|
96
|
+
},
|
|
97
|
+
'408': {
|
|
98
|
+
description: 'Request Timeout',
|
|
99
|
+
},
|
|
100
|
+
'409': {
|
|
101
|
+
description: 'Conflict',
|
|
102
|
+
},
|
|
103
|
+
'410': {
|
|
104
|
+
description: 'Gone',
|
|
105
|
+
},
|
|
106
|
+
'411': {
|
|
107
|
+
description: 'Length Required',
|
|
108
|
+
},
|
|
109
|
+
'412': {
|
|
110
|
+
description: 'Precondition Failed',
|
|
111
|
+
},
|
|
112
|
+
'413': {
|
|
113
|
+
description: 'Payload Too Large',
|
|
114
|
+
},
|
|
115
|
+
'414': {
|
|
116
|
+
description: 'URI Too Long',
|
|
117
|
+
},
|
|
118
|
+
'415': {
|
|
119
|
+
description: 'Unsupported Media Type',
|
|
120
|
+
},
|
|
121
|
+
'416': {
|
|
122
|
+
description: 'Range Not Satisfiable',
|
|
123
|
+
},
|
|
124
|
+
'417': {
|
|
125
|
+
description: 'Expectation Failed',
|
|
126
|
+
},
|
|
127
|
+
'418': {
|
|
128
|
+
description: "I'm a Teapot",
|
|
129
|
+
},
|
|
130
|
+
'421': {
|
|
131
|
+
description: 'Misdirected Request',
|
|
132
|
+
},
|
|
133
|
+
'422': {
|
|
134
|
+
description: 'Unprocessable Entity',
|
|
135
|
+
},
|
|
136
|
+
'423': {
|
|
137
|
+
description: 'Locked',
|
|
138
|
+
},
|
|
139
|
+
'424': {
|
|
140
|
+
description: 'Failed Dependency',
|
|
141
|
+
},
|
|
142
|
+
'425': {
|
|
143
|
+
description: 'Too Early',
|
|
144
|
+
},
|
|
145
|
+
'426': {
|
|
146
|
+
description: 'Upgrade Required',
|
|
147
|
+
},
|
|
148
|
+
'428': {
|
|
149
|
+
description: 'Precondition Required',
|
|
150
|
+
},
|
|
151
|
+
'429': {
|
|
152
|
+
description: 'Too Many Requests',
|
|
153
|
+
},
|
|
154
|
+
'431': {
|
|
155
|
+
description: 'Request Header Fields Too Large',
|
|
156
|
+
},
|
|
157
|
+
'451': {
|
|
158
|
+
description: 'Unavailable For Legal Reasons',
|
|
159
|
+
},
|
|
160
|
+
'500': {
|
|
161
|
+
description: 'Internal Server Error',
|
|
162
|
+
},
|
|
163
|
+
'501': {
|
|
164
|
+
description: 'Not Implemented',
|
|
165
|
+
},
|
|
166
|
+
'502': {
|
|
167
|
+
description: 'Bad Gateway',
|
|
168
|
+
},
|
|
169
|
+
'503': {
|
|
170
|
+
description: 'Service Unavailable',
|
|
171
|
+
},
|
|
172
|
+
'504': {
|
|
173
|
+
description: 'Gateway Timeout',
|
|
174
|
+
},
|
|
175
|
+
'505': {
|
|
176
|
+
description: 'HTTP Version Not Supported',
|
|
177
|
+
},
|
|
178
|
+
'506': {
|
|
179
|
+
description: 'Variant Also Negotiates',
|
|
180
|
+
},
|
|
181
|
+
'507': {
|
|
182
|
+
description: 'Insufficient Storage',
|
|
183
|
+
},
|
|
184
|
+
'508': {
|
|
185
|
+
description: 'Loop Detected',
|
|
186
|
+
},
|
|
187
|
+
'510': {
|
|
188
|
+
description: 'Not Extended',
|
|
189
|
+
},
|
|
190
|
+
'511': {
|
|
191
|
+
description: 'Network Authentication Required',
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
exports.default = DefaultMap;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ObjectLike } from '@grandlinex/core';
|
|
3
|
+
import { Server } from 'net';
|
|
4
|
+
import { MergeInputType, SwaggerConfig } from './Meta/SwaggerTypes.js';
|
|
5
|
+
export default class SwaggerUtil {
|
|
6
|
+
static writeMeta(conf: SwaggerConfig, kind: 'JSON' | 'YAML', path?: string): void;
|
|
7
|
+
static readMeta(path: string): any;
|
|
8
|
+
static serveMeta(conf: SwaggerConfig, port?: number, auth?: string): Promise<Server | null>;
|
|
9
|
+
static metaExtractor(root: ObjectLike, npmPackageVersion: boolean, ...path: ObjectLike[]): SwaggerConfig | undefined;
|
|
10
|
+
static merge(root: SwaggerConfig, data: MergeInputType[]): SwaggerConfig;
|
|
11
|
+
static mergeConfig(root: SwaggerConfig, data: SwaggerConfig[]): SwaggerConfig;
|
|
12
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
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
|
+
const Path = __importStar(require("path"));
|
|
30
|
+
const fs = __importStar(require("fs"));
|
|
31
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
32
|
+
const core_1 = require("@grandlinex/core");
|
|
33
|
+
const express_1 = __importDefault(require("express"));
|
|
34
|
+
const process = __importStar(require("process"));
|
|
35
|
+
const Swagger_js_1 = require("./Meta/Swagger.js");
|
|
36
|
+
const PathHelp_js_1 = __importStar(require("../PathHelp.js"));
|
|
37
|
+
class SwaggerUtil {
|
|
38
|
+
static writeMeta(conf, kind, path) {
|
|
39
|
+
if (kind === 'JSON') {
|
|
40
|
+
const p = Path.join(path || process.cwd(), 'openapi.json');
|
|
41
|
+
fs.writeFileSync(p, JSON.stringify(conf, null, 2));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const y = Path.join(path || process.cwd(), 'openapi.yml');
|
|
45
|
+
fs.writeFileSync(y, js_yaml_1.default.dump(conf));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
static readMeta(path) {
|
|
49
|
+
const file = fs.readFileSync(path, 'utf-8');
|
|
50
|
+
try {
|
|
51
|
+
return JSON.parse(file);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
static async serveMeta(conf, port, auth) {
|
|
58
|
+
const resFiles = (0, PathHelp_js_1.default)((0, PathHelp_js_1.getBaseFolder)(), '..', 'res', 'html');
|
|
59
|
+
const key = auth ? `?auth=${auth}` : '';
|
|
60
|
+
const app = (0, express_1.default)();
|
|
61
|
+
app.use('/', express_1.default.static(resFiles));
|
|
62
|
+
app.get('/spec', (req, res) => {
|
|
63
|
+
res.status(200).send(conf);
|
|
64
|
+
});
|
|
65
|
+
return new Promise((resolve) => {
|
|
66
|
+
const s = app.listen(port || 9000, () => {
|
|
67
|
+
console.log(`listen on http://localhost:${port || 9000}${key}#`);
|
|
68
|
+
resolve(s);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
static metaExtractor(root, npmPackageVersion, ...path) {
|
|
73
|
+
const rootMeta = (0, Swagger_js_1.getSwaggerMeta)(root);
|
|
74
|
+
if (!rootMeta) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
if (npmPackageVersion) {
|
|
78
|
+
const version = process.env.npm_package_version;
|
|
79
|
+
if (version) {
|
|
80
|
+
rootMeta.info.version = version;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return this.merge(rootMeta, path.map((el) => ({
|
|
84
|
+
path: (0, Swagger_js_1.getSPath)(el),
|
|
85
|
+
comp: (0, Swagger_js_1.getSComponent)(el),
|
|
86
|
+
})));
|
|
87
|
+
}
|
|
88
|
+
static merge(root, data) {
|
|
89
|
+
const out = root;
|
|
90
|
+
if (!out.paths) {
|
|
91
|
+
out.paths = {};
|
|
92
|
+
}
|
|
93
|
+
if (!out.components) {
|
|
94
|
+
out.components = {};
|
|
95
|
+
}
|
|
96
|
+
data.forEach(({ path, comp }) => {
|
|
97
|
+
if (path && out.paths) {
|
|
98
|
+
const keys = Object.keys(path.path);
|
|
99
|
+
for (const key of keys) {
|
|
100
|
+
if (key) {
|
|
101
|
+
const nKey = `${path.prefix || ''}${key}`;
|
|
102
|
+
const ac = path.path[key];
|
|
103
|
+
if (ac) {
|
|
104
|
+
const comps = Object.keys(ac);
|
|
105
|
+
if (!out.paths[nKey]) {
|
|
106
|
+
out.paths[nKey] = {};
|
|
107
|
+
}
|
|
108
|
+
if (out.paths[nKey]) {
|
|
109
|
+
for (const c of comps) {
|
|
110
|
+
const nC = c;
|
|
111
|
+
out.paths[nKey][nC] = ac[nC];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (comp && out.components) {
|
|
119
|
+
const keys = Object.keys(comp);
|
|
120
|
+
for (const key of keys) {
|
|
121
|
+
if (key) {
|
|
122
|
+
const nKey = key;
|
|
123
|
+
const ac = comp[nKey];
|
|
124
|
+
if (ac) {
|
|
125
|
+
const comps = Object.keys(ac);
|
|
126
|
+
if (!out.components[nKey]) {
|
|
127
|
+
out.components[nKey] = {};
|
|
128
|
+
}
|
|
129
|
+
if (out.components[nKey]) {
|
|
130
|
+
for (const c of comps) {
|
|
131
|
+
out.components[nKey][c] = ac[c];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
static mergeConfig(root, data) {
|
|
142
|
+
const out = root;
|
|
143
|
+
const path = new core_1.CMap();
|
|
144
|
+
const compSecurity = new core_1.CMap();
|
|
145
|
+
const compSchema = new core_1.CMap();
|
|
146
|
+
const compRespons = new core_1.CMap();
|
|
147
|
+
function fillKeys(obj, map) {
|
|
148
|
+
if (obj) {
|
|
149
|
+
const keys = Object.keys(obj);
|
|
150
|
+
for (const key of keys) {
|
|
151
|
+
if (!map.has(key)) {
|
|
152
|
+
map.set(key, obj[key]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (!out.paths) {
|
|
158
|
+
out.paths = {};
|
|
159
|
+
}
|
|
160
|
+
if (!out.components) {
|
|
161
|
+
out.components = {};
|
|
162
|
+
}
|
|
163
|
+
[root, ...data].forEach((sc) => {
|
|
164
|
+
fillKeys(sc.paths, path);
|
|
165
|
+
fillKeys(sc.components?.securitySchemes, compSecurity);
|
|
166
|
+
fillKeys(sc.components?.schemas, compSchema);
|
|
167
|
+
fillKeys(sc.components?.responses, compRespons);
|
|
168
|
+
});
|
|
169
|
+
if (path.size > 0) {
|
|
170
|
+
path.forEach((x, key) => {
|
|
171
|
+
out.paths[key] = x;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
if (compSecurity.size > 0) {
|
|
175
|
+
out.components.securitySchemes = {};
|
|
176
|
+
compSecurity.forEach((x, key) => {
|
|
177
|
+
out.components.securitySchemes[key] = x;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (compSchema.size > 0) {
|
|
181
|
+
out.components.schemas = {};
|
|
182
|
+
compSchema.forEach((x, key) => {
|
|
183
|
+
out.components.schemas[key] = x;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
if (compRespons.size > 0) {
|
|
187
|
+
out.components.responses = {};
|
|
188
|
+
compRespons.forEach((x, key) => {
|
|
189
|
+
out.components.responses[key] = x;
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.default = SwaggerUtil;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS FILE IS AUTOMATICALLY GENERATED
|
|
3
|
+
* DO NOT EDIT THIS FILE
|
|
4
|
+
*/
|
|
5
|
+
export type ErrorType = {
|
|
6
|
+
type: string;
|
|
7
|
+
global?: string[];
|
|
8
|
+
field?: {
|
|
9
|
+
key: string;
|
|
10
|
+
message: string;
|
|
11
|
+
}[];
|
|
12
|
+
};
|
|
13
|
+
export type HeaderType = string | string[] | number | undefined;
|
|
14
|
+
export type HandleRes<T> = {
|
|
15
|
+
success: boolean;
|
|
16
|
+
data: T | null;
|
|
17
|
+
code?: number;
|
|
18
|
+
error?: ErrorType;
|
|
19
|
+
headers?: Record<string, HeaderType>;
|
|
20
|
+
};
|
|
21
|
+
export type PathParam = {
|
|
22
|
+
[key: string]: string | number | undefined;
|
|
23
|
+
};
|
|
24
|
+
export declare function isErrorType(x: any): x is ErrorType;
|
|
25
|
+
export interface ConHandleConfig {
|
|
26
|
+
headers?: Record<string, string>;
|
|
27
|
+
param?: PathParam;
|
|
28
|
+
query?: PathParam;
|
|
29
|
+
}
|
|
30
|
+
export interface ConHandleResponse<T> {
|
|
31
|
+
code: number;
|
|
32
|
+
data: T | null;
|
|
33
|
+
headers: Record<string, HeaderType>;
|
|
34
|
+
}
|
|
35
|
+
export interface ConHandle {
|
|
36
|
+
get<T>(url: string, config?: ConHandleConfig): Promise<ConHandleResponse<T>>;
|
|
37
|
+
post<T, J>(url: string, body?: J, config?: ConHandleConfig): Promise<ConHandleResponse<T>>;
|
|
38
|
+
patch<T, J>(url: string, body?: J, config?: ConHandleConfig): Promise<ConHandleResponse<T>>;
|
|
39
|
+
delete<T>(url: string, config?: ConHandleConfig): Promise<ConHandleResponse<T>>;
|
|
40
|
+
}
|
|
41
|
+
export default class BaseCon {
|
|
42
|
+
api: string;
|
|
43
|
+
permanentHeader: undefined | Record<string, string>;
|
|
44
|
+
authorization: string | null;
|
|
45
|
+
disconnected: boolean;
|
|
46
|
+
failFlag: boolean;
|
|
47
|
+
logger: (arg: any) => void;
|
|
48
|
+
con: ConHandle;
|
|
49
|
+
reconnect: () => Promise<boolean>;
|
|
50
|
+
onReconnect: (con: BaseCon) => Promise<boolean>;
|
|
51
|
+
constructor(conf: {
|
|
52
|
+
con: ConHandle;
|
|
53
|
+
endpoint: string;
|
|
54
|
+
logger?: (arg: any) => void;
|
|
55
|
+
});
|
|
56
|
+
isConnected(): boolean;
|
|
57
|
+
token(): string;
|
|
58
|
+
p(path: string, config?: ConHandleConfig): string;
|
|
59
|
+
ping(): Promise<boolean>;
|
|
60
|
+
test(email: string, password: string): Promise<boolean>;
|
|
61
|
+
testToken(): Promise<boolean>;
|
|
62
|
+
connect(email: string, pw: string): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* Enable client before auth
|
|
65
|
+
*/
|
|
66
|
+
fakeEnableClient(): void;
|
|
67
|
+
handle<T, J>(type: 'POST' | 'GET' | 'PATCH' | 'DELETE', path: string, body?: J, config?: ConHandleConfig): Promise<HandleRes<T>>;
|
|
68
|
+
}
|