@grandlinex/swagger-mate 1.2.2 → 1.3.2
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/dist/cjs/Swagger/Client/ClientUtil.d.ts +18 -4
- package/dist/cjs/Swagger/Client/ClientUtil.js +51 -8
- package/dist/cjs/Swagger/Client/InterfaceTemplate.js +1 -1
- package/dist/cjs/Swagger/Client/SwaggerClient.js +5 -5
- package/dist/cjs/Swagger/Meta/SwaggerTypes.d.ts +1 -0
- package/dist/cjs/Swagger/Path/SPathUtil.d.ts +173 -2
- package/dist/cjs/Swagger/Path/SPathUtil.js +261 -5
- package/dist/cjs/Swagger/SwaggerUtil.d.ts +18 -2
- package/dist/cjs/Swagger/SwaggerUtil.js +32 -5
- package/dist/cjs/Swagger/annotation/index.d.ts +8 -3
- package/dist/cjs/Swagger/debug/BaseCon.d.ts +115 -11
- package/dist/cjs/Swagger/debug/BaseCon.js +142 -38
- package/dist/cjs/cli.js +5 -1
- package/dist/mjs/Swagger/Client/ClientUtil.d.ts +18 -4
- package/dist/mjs/Swagger/Client/ClientUtil.js +50 -8
- package/dist/mjs/Swagger/Client/InterfaceTemplate.js +2 -2
- package/dist/mjs/Swagger/Client/SwaggerClient.js +5 -5
- package/dist/mjs/Swagger/Meta/SwaggerTypes.d.ts +1 -0
- package/dist/mjs/Swagger/Path/SPathUtil.d.ts +173 -2
- package/dist/mjs/Swagger/Path/SPathUtil.js +261 -5
- package/dist/mjs/Swagger/SwaggerUtil.d.ts +18 -2
- package/dist/mjs/Swagger/SwaggerUtil.js +33 -6
- package/dist/mjs/Swagger/annotation/index.d.ts +8 -3
- package/dist/mjs/Swagger/debug/BaseCon.d.ts +115 -11
- package/dist/mjs/Swagger/debug/BaseCon.js +142 -38
- package/dist/mjs/cli.js +5 -1
- package/package.json +10 -8
- package/res/html/rapi-doc/index.html +28 -0
- package/res/html/rapi-doc/rapidoc-min.js +3915 -0
- package/res/html/{index.html → swagger-ui/index.html} +11 -3
- package/res/html/swagger-ui/swagger-ui-bundle.js +2 -0
- package/res/html/swagger-ui/swagger-ui-standalone-preset.js +2 -0
- package/res/html/swagger-ui/swagger-ui.css +3 -0
- package/res/templates/class/BaseCon.ts +160 -61
- package/res/html/swagger-ui-bundle.js +0 -2
- package/res/html/swagger-ui-standalone-preset.js +0 -2
- package/res/html/swagger-ui.css +0 -3
|
@@ -12,13 +12,20 @@ const form_data_1 = __importDefault(require("form-data"));
|
|
|
12
12
|
function isErrorType(x) {
|
|
13
13
|
return x && typeof x === 'object' && x.type === 'error';
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* BaseCon provides a minimal client for interacting with an HTTP backend.
|
|
17
|
+
* It manages connection state, authentication tokens, and reconnection
|
|
18
|
+
* logic while delegating actual HTTP requests to a supplied {@link ConHandle}.
|
|
19
|
+
*
|
|
20
|
+
* @class
|
|
21
|
+
*/
|
|
15
22
|
class BaseCon {
|
|
16
23
|
constructor(conf) {
|
|
17
24
|
this.api = conf.endpoint;
|
|
18
|
-
this.logger = conf.logger
|
|
25
|
+
this.logger = conf.logger ?? console.log;
|
|
19
26
|
this.disconnected = true;
|
|
27
|
+
this.noAuth = false;
|
|
20
28
|
this.authorization = null;
|
|
21
|
-
this.failFlag = false;
|
|
22
29
|
this.con = conf.con;
|
|
23
30
|
this.reconnect = async () => {
|
|
24
31
|
this.disconnected = true;
|
|
@@ -27,10 +34,40 @@ class BaseCon {
|
|
|
27
34
|
this.onReconnect = () => Promise.resolve(true);
|
|
28
35
|
this.handle = this.handle.bind(this);
|
|
29
36
|
}
|
|
30
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves the API endpoint.
|
|
39
|
+
*
|
|
40
|
+
* @return {string} The API endpoint string.
|
|
41
|
+
*/
|
|
42
|
+
getApiEndpoint() {
|
|
43
|
+
return this.api;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Sets the API endpoint URL used by the client.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} endpoint - The full URL of the API endpoint.
|
|
49
|
+
* @returns {void}
|
|
50
|
+
*/
|
|
51
|
+
setApiEndpoint(endpoint) {
|
|
52
|
+
this.api = endpoint;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Indicates whether the instance is considered connected.
|
|
56
|
+
*
|
|
57
|
+
* The instance is regarded as connected when it either does not require authentication
|
|
58
|
+
* (`noAuth` is true) or it has an authorization token set (`authorization` is not null),
|
|
59
|
+
* and it is not currently marked as disconnected.
|
|
60
|
+
*
|
|
61
|
+
* @return {boolean} `true` if the instance is connected, `false` otherwise.
|
|
62
|
+
*/
|
|
31
63
|
isConnected() {
|
|
32
|
-
return this.authorization !== null && !this.disconnected;
|
|
64
|
+
return (this.noAuth || this.authorization !== null) && !this.disconnected;
|
|
33
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns the current authorization token.
|
|
68
|
+
*
|
|
69
|
+
* @return {string} The authorization token or an empty string if none is set.
|
|
70
|
+
*/
|
|
34
71
|
token() {
|
|
35
72
|
return this.authorization || '';
|
|
36
73
|
}
|
|
@@ -56,35 +93,34 @@ class BaseCon {
|
|
|
56
93
|
}
|
|
57
94
|
return `${this.api}${pp}`;
|
|
58
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Sends a ping request to the API to verify connectivity and version availability.
|
|
98
|
+
*
|
|
99
|
+
* @return {boolean} `true` if the API responded with a 200 status code and a valid version object; `false` otherwise.
|
|
100
|
+
*/
|
|
59
101
|
async ping() {
|
|
60
102
|
try {
|
|
61
103
|
const version = await this.con.get(this.p('/version'));
|
|
62
|
-
return version.data?.api
|
|
104
|
+
return version.data?.api !== undefined && version.code === 200;
|
|
63
105
|
}
|
|
64
106
|
catch (e) {
|
|
65
107
|
this.logger('ping failed');
|
|
66
108
|
return false;
|
|
67
109
|
}
|
|
68
110
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
this.logger('cant connect to backend');
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
this.logger('test ping failed');
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
111
|
+
/**
|
|
112
|
+
* Validates the current authentication token by performing a ping and a test request
|
|
113
|
+
* to the backend. The method first ensures connectivity via {@link ping}. If the ping
|
|
114
|
+
* succeeds, it attempts to retrieve a token from the `/test/auth` endpoint using the
|
|
115
|
+
* current token in the `Authorization` header. The operation is considered successful
|
|
116
|
+
* if the response status code is 200 or 201.
|
|
117
|
+
*
|
|
118
|
+
* If any step fails, an error is logged and the method returns {@code false}. On
|
|
119
|
+
* success, it returns {@code true}.
|
|
120
|
+
*
|
|
121
|
+
* @return {Promise<boolean>} A promise that resolves to {@code true} if the token
|
|
122
|
+
* test succeeds, otherwise {@code false}.
|
|
123
|
+
*/
|
|
88
124
|
async testToken() {
|
|
89
125
|
const ping = await this.ping();
|
|
90
126
|
if (ping) {
|
|
@@ -104,7 +140,59 @@ class BaseCon {
|
|
|
104
140
|
this.logger('test ping failed');
|
|
105
141
|
return false;
|
|
106
142
|
}
|
|
107
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Attempts to establish a connection to the backend without authentication.
|
|
145
|
+
*
|
|
146
|
+
* This method sends a ping request. If the ping succeeds, it clears any
|
|
147
|
+
* existing authorization data, marks the instance as connected,
|
|
148
|
+
* enables the no‑authentication mode, and returns `true`. If the ping
|
|
149
|
+
* fails, it logs a warning, clears authorization, marks the instance
|
|
150
|
+
* as disconnected, and returns `false`.
|
|
151
|
+
*
|
|
152
|
+
* @return {Promise<boolean>} `true` when a connection is successfully
|
|
153
|
+
* established without authentication, otherwise `false`.
|
|
154
|
+
*/
|
|
155
|
+
async connectNoAuth() {
|
|
156
|
+
const ping = await this.ping();
|
|
157
|
+
if (ping) {
|
|
158
|
+
this.authorization = null;
|
|
159
|
+
this.disconnected = false;
|
|
160
|
+
this.noAuth = true;
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
this.logger('cant connect to backend');
|
|
164
|
+
this.authorization = null;
|
|
165
|
+
this.disconnected = true;
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Forces a connection using the provided bearer token.
|
|
170
|
+
*
|
|
171
|
+
* @param {string} token The token to be used for authentication.
|
|
172
|
+
* @returns {void}
|
|
173
|
+
*/
|
|
174
|
+
forceConnectWithToken(token) {
|
|
175
|
+
this.authorization = `Bearer ${token}`;
|
|
176
|
+
this.disconnected = false;
|
|
177
|
+
this.noAuth = false;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Establishes a connection to the backend using the supplied credentials.
|
|
181
|
+
* Performs a health‑check ping first; if successful, it requests an authentication
|
|
182
|
+
* token from the `/token` endpoint. When the token is obtained, the method
|
|
183
|
+
* updates internal state (authorization header, connection flags) and, unless
|
|
184
|
+
* a dry run is requested, sets up a reconnection routine. Any errors are
|
|
185
|
+
* logged and the method resolves to `false`.
|
|
186
|
+
*
|
|
187
|
+
* @param {string} email - The user's email address for authentication.
|
|
188
|
+
* @param {string} pw - The password (or token) for the specified user.
|
|
189
|
+
* @param {boolean} [dry=false] - If `true`, the method performs a dry run
|
|
190
|
+
* without persisting credentials or configuring reconnection logic.
|
|
191
|
+
*
|
|
192
|
+
* @returns Promise<boolean> `true` if the connection was successfully
|
|
193
|
+
* established, otherwise `false`.
|
|
194
|
+
*/
|
|
195
|
+
async connect(email, pw, dry = false) {
|
|
108
196
|
const ping = await this.ping();
|
|
109
197
|
if (ping) {
|
|
110
198
|
try {
|
|
@@ -112,13 +200,15 @@ class BaseCon {
|
|
|
112
200
|
username: email,
|
|
113
201
|
token: pw,
|
|
114
202
|
});
|
|
115
|
-
// TODO check token
|
|
116
203
|
if (token.code === 200 || token.code === 201) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
204
|
+
if (!dry) {
|
|
205
|
+
this.authorization = `Bearer ${token.data?.token}`;
|
|
206
|
+
this.disconnected = false;
|
|
207
|
+
this.noAuth = false;
|
|
208
|
+
this.reconnect = async () => {
|
|
209
|
+
return ((await this.connect(email, pw)) && (await this.testToken()));
|
|
210
|
+
};
|
|
211
|
+
}
|
|
122
212
|
return true;
|
|
123
213
|
}
|
|
124
214
|
}
|
|
@@ -129,17 +219,32 @@ class BaseCon {
|
|
|
129
219
|
this.logger('cant connect to backend');
|
|
130
220
|
this.authorization = null;
|
|
131
221
|
this.disconnected = true;
|
|
222
|
+
this.noAuth = false;
|
|
132
223
|
return false;
|
|
133
224
|
}
|
|
134
225
|
/**
|
|
135
|
-
*
|
|
226
|
+
* Performs an HTTP request using the client’s internal connection.
|
|
227
|
+
*
|
|
228
|
+
* The method verifies that the client is connected before attempting a request.
|
|
229
|
+
* It automatically injects the authorization token, permanent headers, and any
|
|
230
|
+
* headers supplied in `config`. If the request body is a `FormData` instance
|
|
231
|
+
* (or provides a `getHeaders` method), the appropriate form headers are added.
|
|
232
|
+
*
|
|
233
|
+
* Response handling:
|
|
234
|
+
* - `200` or `201`: returns `success: true` with the received data.
|
|
235
|
+
* - `498`: attempts to reconnect and retries the request once.
|
|
236
|
+
* - `401`: logs an authentication error, marks the client as disconnected.
|
|
237
|
+
* - `403` and other status codes: return `success: false` with the status code.
|
|
238
|
+
*
|
|
239
|
+
* @param {'POST'|'GET'|'PATCH'|'DELETE'} type The HTTP method to use.
|
|
240
|
+
* @param {string} path The endpoint path relative to the base URL.
|
|
241
|
+
* @param {J} [body] Optional request payload. May be `FormData` or a plain object.
|
|
242
|
+
* @param {ConHandleConfig} [config] Optional Axios-like configuration for the request.
|
|
243
|
+
* @returns {Promise<HandleRes<T>>} A promise that resolves to a `HandleRes` object
|
|
244
|
+
* containing the response data, status code, any error information, and headers.
|
|
136
245
|
*/
|
|
137
|
-
fakeEnableClient() {
|
|
138
|
-
this.authorization = 'DEBUG';
|
|
139
|
-
this.disconnected = false;
|
|
140
|
-
}
|
|
141
246
|
async handle(type, path, body, config) {
|
|
142
|
-
if (!this.
|
|
247
|
+
if (!this.isConnected()) {
|
|
143
248
|
this.logger('Disconnected');
|
|
144
249
|
return {
|
|
145
250
|
success: false,
|
|
@@ -246,7 +351,6 @@ class BaseCon {
|
|
|
246
351
|
};
|
|
247
352
|
case 401:
|
|
248
353
|
this.logger('AUTH NOT VALID');
|
|
249
|
-
this.disconnected = true;
|
|
250
354
|
return {
|
|
251
355
|
success: false,
|
|
252
356
|
data: null,
|
package/dist/cjs/cli.js
CHANGED
|
@@ -76,7 +76,11 @@ async function run() {
|
|
|
76
76
|
console.log('Serving Swagger Meta');
|
|
77
77
|
const auth = process.env.SW_AUTH || undefined;
|
|
78
78
|
const port = process.env.SW_PORT || undefined;
|
|
79
|
-
SwaggerUtil_js_1.default.serveMeta(conf,
|
|
79
|
+
SwaggerUtil_js_1.default.serveMeta(conf, {
|
|
80
|
+
port: port ? parseInt(port, 10) : undefined,
|
|
81
|
+
auth,
|
|
82
|
+
type: 'rapi-doc',
|
|
83
|
+
});
|
|
80
84
|
}
|
|
81
85
|
if (arg[arg.length - 2] === '--build') {
|
|
82
86
|
console.log('Building Swagger Meta');
|
|
@@ -3,6 +3,7 @@ export type IfMappingKeyType = {
|
|
|
3
3
|
key: string;
|
|
4
4
|
type: string;
|
|
5
5
|
required?: boolean;
|
|
6
|
+
nullable?: boolean;
|
|
6
7
|
};
|
|
7
8
|
export type IfMappingType = {
|
|
8
9
|
name: string;
|
|
@@ -10,15 +11,28 @@ export type IfMappingType = {
|
|
|
10
11
|
rawType?: string;
|
|
11
12
|
};
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
* Returns a string representation of the given value. If the value is falsy,
|
|
15
|
+
* an empty string is returned.
|
|
16
|
+
*
|
|
17
|
+
* @param e - The value to convert to a string.
|
|
18
|
+
* @returns The string representation of `e`, or an empty string if `e` is falsy.
|
|
15
19
|
*/
|
|
16
20
|
export declare function eS(e: any): string;
|
|
17
21
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
22
|
+
* Returns a type annotation delimiter based on whether a value is required.
|
|
23
|
+
*
|
|
24
|
+
* @param {boolean} [required] - Indicates if the value is required. If omitted or false, the value is considered optional.
|
|
25
|
+
* @returns {string} A colon (`:`) for required values or a question mark followed by a colon (`?:`) for optional values.
|
|
20
26
|
*/
|
|
21
27
|
export declare function rq(required?: boolean): string;
|
|
28
|
+
/**
|
|
29
|
+
* Returns a type representation based on whether the value should be nullable.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} type - The base type name to return when the value is not nullable.
|
|
32
|
+
* @param {boolean} nullable - Indicates if the type should be considered nullable. If `true`, the function returns a colon (`:`); if `false`, it returns the original type string.
|
|
33
|
+
* @return {string} The original type string when `nullable` is `false`, otherwise a colon (`:`) to represent a nullable type in the consuming context.
|
|
34
|
+
*/
|
|
35
|
+
export declare function rN(type: string, nullable?: boolean): string;
|
|
22
36
|
export declare function sK(e: string): string;
|
|
23
37
|
/**
|
|
24
38
|
* Cast first letter to uppercase
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { isSwaggerRef } from '../Meta/SwaggerTypes.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Returns a string representation of the given value. If the value is falsy,
|
|
4
|
+
* an empty string is returned.
|
|
5
|
+
*
|
|
6
|
+
* @param e - The value to convert to a string.
|
|
7
|
+
* @returns The string representation of `e`, or an empty string if `e` is falsy.
|
|
5
8
|
*/
|
|
6
9
|
export function eS(e) {
|
|
7
10
|
return e || '';
|
|
8
11
|
}
|
|
9
12
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
13
|
+
* Returns a type annotation delimiter based on whether a value is required.
|
|
14
|
+
*
|
|
15
|
+
* @param {boolean} [required] - Indicates if the value is required. If omitted or false, the value is considered optional.
|
|
16
|
+
* @returns {string} A colon (`:`) for required values or a question mark followed by a colon (`?:`) for optional values.
|
|
12
17
|
*/
|
|
13
18
|
export function rq(required) {
|
|
14
19
|
if (!required) {
|
|
@@ -16,6 +21,19 @@ export function rq(required) {
|
|
|
16
21
|
}
|
|
17
22
|
return ':';
|
|
18
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns a type representation based on whether the value should be nullable.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} type - The base type name to return when the value is not nullable.
|
|
28
|
+
* @param {boolean} nullable - Indicates if the type should be considered nullable. If `true`, the function returns a colon (`:`); if `false`, it returns the original type string.
|
|
29
|
+
* @return {string} The original type string when `nullable` is `false`, otherwise a colon (`:`) to represent a nullable type in the consuming context.
|
|
30
|
+
*/
|
|
31
|
+
export function rN(type, nullable) {
|
|
32
|
+
if (nullable) {
|
|
33
|
+
return `${type} | null`;
|
|
34
|
+
}
|
|
35
|
+
return type;
|
|
36
|
+
}
|
|
19
37
|
export function sK(e) {
|
|
20
38
|
if (e.indexOf(':') >= 0) {
|
|
21
39
|
return `'${e}'`;
|
|
@@ -85,20 +103,41 @@ export function transformInterface(operation, tag, schema) {
|
|
|
85
103
|
const prop = schema.properties[key];
|
|
86
104
|
const isRequired = schema.required && schema.required.includes(key);
|
|
87
105
|
if (!isSwaggerRef(prop)) {
|
|
106
|
+
const nullable = prop.nullable ?? false;
|
|
88
107
|
switch (prop.type) {
|
|
89
108
|
case 'number':
|
|
90
109
|
case 'integer':
|
|
91
|
-
cur.keys.push({
|
|
110
|
+
cur.keys.push({
|
|
111
|
+
key,
|
|
112
|
+
type: 'number',
|
|
113
|
+
required: isRequired,
|
|
114
|
+
nullable,
|
|
115
|
+
});
|
|
92
116
|
break;
|
|
93
117
|
case 'string':
|
|
94
|
-
cur.keys.push({
|
|
118
|
+
cur.keys.push({
|
|
119
|
+
key,
|
|
120
|
+
type: 'string',
|
|
121
|
+
required: isRequired,
|
|
122
|
+
nullable,
|
|
123
|
+
});
|
|
95
124
|
break;
|
|
96
125
|
case 'boolean':
|
|
97
|
-
cur.keys.push({
|
|
126
|
+
cur.keys.push({
|
|
127
|
+
key,
|
|
128
|
+
type: 'boolean',
|
|
129
|
+
required: isRequired,
|
|
130
|
+
nullable,
|
|
131
|
+
});
|
|
98
132
|
break;
|
|
99
133
|
case 'object':
|
|
100
134
|
if (!prop.properties) {
|
|
101
|
-
cur.keys.push({
|
|
135
|
+
cur.keys.push({
|
|
136
|
+
key,
|
|
137
|
+
type: 'any',
|
|
138
|
+
required: isRequired,
|
|
139
|
+
nullable,
|
|
140
|
+
});
|
|
102
141
|
}
|
|
103
142
|
else {
|
|
104
143
|
cur.keys.push({
|
|
@@ -115,6 +154,7 @@ export function transformInterface(operation, tag, schema) {
|
|
|
115
154
|
key,
|
|
116
155
|
type: `${typeByRef(prop.items.$ref)}[]`,
|
|
117
156
|
required: isRequired,
|
|
157
|
+
nullable,
|
|
118
158
|
});
|
|
119
159
|
}
|
|
120
160
|
else {
|
|
@@ -122,6 +162,7 @@ export function transformInterface(operation, tag, schema) {
|
|
|
122
162
|
key,
|
|
123
163
|
type: `${ifName(cur.name, `${key}Element`)}[]`,
|
|
124
164
|
required: isRequired,
|
|
165
|
+
nullable,
|
|
125
166
|
});
|
|
126
167
|
out.push(...transformInterface(cur.name, key, prop));
|
|
127
168
|
}
|
|
@@ -134,6 +175,7 @@ export function transformInterface(operation, tag, schema) {
|
|
|
134
175
|
key,
|
|
135
176
|
type: typeByRef(prop.$ref),
|
|
136
177
|
required: isRequired,
|
|
178
|
+
nullable: schema.nullable ?? false,
|
|
137
179
|
});
|
|
138
180
|
}
|
|
139
181
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/* eslint-disable prettier/prettier */
|
|
2
|
-
import { rq, S, sK } from './ClientUtil.js';
|
|
2
|
+
import { rq, S, sK, rN } from './ClientUtil.js';
|
|
3
3
|
function interfaceTemplate(IF_NAME, types, rawType) {
|
|
4
4
|
if (rawType) {
|
|
5
5
|
return `export type ${IF_NAME} = ${rawType};`;
|
|
6
6
|
}
|
|
7
7
|
return `export interface ${IF_NAME} {
|
|
8
|
-
${types.map(({ key, type, required }) => `${S(2)}${sK(key)}${rq(required)} ${type};`).join('\n')}
|
|
8
|
+
${types.map(({ key, type, required, nullable }) => `${S(2)}${sK(key)}${rq(required)} ${rN(type, nullable)};`).join('\n')}
|
|
9
9
|
}`;
|
|
10
10
|
}
|
|
11
11
|
export {
|
|
@@ -143,13 +143,13 @@ function createPackage(name, version, module) {
|
|
|
143
143
|
types: 'dist/index.d.ts',
|
|
144
144
|
module: module ? 'dist/index.js' : undefined,
|
|
145
145
|
type: module ? 'module' : undefined,
|
|
146
|
-
dependencies: {
|
|
147
|
-
'form-data': '4.0.4',
|
|
148
|
-
axios: '1.11.0',
|
|
149
|
-
},
|
|
150
146
|
devDependencies: {
|
|
151
147
|
'@types/node': '22.15.32',
|
|
152
|
-
typescript: '5.
|
|
148
|
+
typescript: '5.9.2',
|
|
149
|
+
},
|
|
150
|
+
peerDependencies: {
|
|
151
|
+
axios: '>=1.13.2',
|
|
152
|
+
'form-data': '>=4.0.5',
|
|
153
153
|
},
|
|
154
154
|
scripts: {
|
|
155
155
|
build: 'tsc',
|
|
@@ -2,15 +2,104 @@ import { CoreEntity } from '@grandlinex/core';
|
|
|
2
2
|
import { HttpStatusTypes } from '../Meta/SwaggerTypesStatic.js';
|
|
3
3
|
import { SKey, SSchemaEl, SwaggerContent, SwaggerRPathConfResponse, SwaggerRPathReqBody } from '../Meta/SwaggerTypes.js';
|
|
4
4
|
export default class SPathUtil {
|
|
5
|
+
/**
|
|
6
|
+
* Generates a default response mapping for the specified HTTP status types.
|
|
7
|
+
*
|
|
8
|
+
* @param {HttpStatusTypes[]} types - The HTTP status types for which default responses should be created.
|
|
9
|
+
* @return {SwaggerRPathConfResponse} An object mapping each provided status type to its default response definition. */
|
|
5
10
|
static defaultResponse(...types: HttpStatusTypes[]): SwaggerRPathConfResponse;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a request body definition for JSON content type using the provided schema.
|
|
13
|
+
*
|
|
14
|
+
* @param {SSchemaEl} schema - The JSON schema used for validating the request body.
|
|
15
|
+
* @return {SwaggerRPathReqBody} A Swagger path request body object specifying application/json content type with the provided schema.
|
|
16
|
+
*/
|
|
6
17
|
static jsonBody(schema: SSchemaEl): SwaggerRPathReqBody;
|
|
18
|
+
/**
|
|
19
|
+
* Builds a Swagger request body for `multipart/form-data` requests.
|
|
20
|
+
*
|
|
21
|
+
* @param {SSchemaEl} [schema] Optional schema describing the form data.
|
|
22
|
+
* If omitted, a default schema with a single binary `file` field is provided.
|
|
23
|
+
* @return {SwaggerRPathReqBody} Swagger request body definition with
|
|
24
|
+
* `multipart/form-data` content and the supplied or default schema. */
|
|
7
25
|
static formBody(schema?: SSchemaEl): SwaggerRPathReqBody;
|
|
26
|
+
/**
|
|
27
|
+
* Generates a Swagger content definition for the provided entity.
|
|
28
|
+
*
|
|
29
|
+
* @param {T} entity - The entity instance to derive the Swagger schema from.
|
|
30
|
+
* @param {boolean} [list] - When true, the schema will be wrapped in an array type, representing a list of entities.
|
|
31
|
+
*
|
|
32
|
+
* @returns {SwaggerContent|undefined} The Swagger content object for the entity, or `undefined` if the entity does not have a schema.
|
|
33
|
+
*/
|
|
8
34
|
static entityContent<T extends CoreEntity>(entity: T, list?: boolean): SwaggerContent | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* @template T extends CoreEntity
|
|
37
|
+
* @param {T} entity - The entity instance for which to build the response configuration.
|
|
38
|
+
* @param {boolean} [list] - Indicates whether the response should represent a list of entities.
|
|
39
|
+
* @param {boolean} [create] - Indicates whether the response corresponds to a creation operation (status code 201); otherwise 200.
|
|
40
|
+
* @returns {SwaggerRPathConfResponse} The Swagger response configuration object containing the appropriate status code and content.
|
|
41
|
+
*/
|
|
9
42
|
static entityResponse<T extends CoreEntity>(entity: T, list?: boolean, create?: boolean): SwaggerRPathConfResponse;
|
|
43
|
+
/**
|
|
44
|
+
* Builds a JSON schema reference path for the given component name.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} inp - The name of the schema component.
|
|
47
|
+
* @return {string} The JSON reference path formatted as `#/components/schemas/<inp>`.
|
|
48
|
+
*/
|
|
10
49
|
static schemaPath(inp: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a Swagger request body definition that references a schema.
|
|
52
|
+
*
|
|
53
|
+
* @param {string | CoreEntity} $ref
|
|
54
|
+
* Either the string reference to a schema or a `CoreEntity` instance whose
|
|
55
|
+
* class name will be used to build the reference path.
|
|
56
|
+
* @param {boolean} list
|
|
57
|
+
* If true, the referenced schema is wrapped in an array; otherwise the
|
|
58
|
+
* schema is used directly.
|
|
59
|
+
* @returns {SwaggerRPathReqBody}
|
|
60
|
+
* The request body object containing the appropriate content and schema
|
|
61
|
+
* configuration.
|
|
62
|
+
*/
|
|
63
|
+
static refRequest($ref: string | CoreEntity, list: boolean): SwaggerRPathReqBody;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a Swagger response configuration for a given HTTP status code.
|
|
66
|
+
*
|
|
67
|
+
* @param {HttpStatusTypes} code - The primary HTTP status code for */
|
|
11
68
|
static refResponse(code: HttpStatusTypes, $ref: string | CoreEntity, list: boolean, ...addCodes: HttpStatusTypes[]): SwaggerRPathConfResponse;
|
|
69
|
+
/**
|
|
70
|
+
* Builds a Swagger response configuration object for a given HTTP status code and schema.
|
|
71
|
+
*
|
|
72
|
+
* @param {HttpStatusTypes} code - The primary HTTP status code for the response.
|
|
73
|
+
* @param {SSchemaEl} schema - The JSON schema definition for the response body.
|
|
74
|
+
* @param {boolean} list - If true, the schema is wrapped in an array for list responses.
|
|
75
|
+
* @param {...HttpStatusTypes} addCodes - Additional HTTP status codes for default responses.
|
|
76
|
+
* @return {SwaggerRPathConfResponse} The constructed response configuration object.
|
|
77
|
+
*/
|
|
12
78
|
static jsonResponse(code: HttpStatusTypes, schema: SSchemaEl, list: boolean, ...addCodes: HttpStatusTypes[]): SwaggerRPathConfResponse;
|
|
79
|
+
/**
|
|
80
|
+
* Generates a JSON schema representation from a CoreEntity instance.
|
|
81
|
+
*
|
|
82
|
+
* This method inspects the entity's metadata to construct a schema object
|
|
83
|
+
* describing the entity's shape. The resulting schema contains:
|
|
84
|
+
* - `type`: always `"object"`.
|
|
85
|
+
* - `description`: a string indicating the entity name.
|
|
86
|
+
* - `required`: an array of property names that are defined on the entity.
|
|
87
|
+
* - `properties`: an object mapping each property name to an object that
|
|
88
|
+
* includes the resolved database type and its nullability.
|
|
89
|
+
*
|
|
90
|
+
* If no metadata is found for the provided entity, the method returns `undefined`.
|
|
91
|
+
*
|
|
92
|
+
* @param {T} entity - The entity instance for which to create a schema.
|
|
93
|
+
* @returns {SSchemaEl | undefined} The generated schema object, or `undefined`
|
|
94
|
+
* if the entity's metadata could not be retrieved.
|
|
95
|
+
*/
|
|
13
96
|
static schemaFromEntity<T extends CoreEntity>(entity: T): SSchemaEl | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Generates a content schema object for the given entity. The schema contains a description derived from the entity metadata and a JSON content schema based on the entity's structure.
|
|
99
|
+
*
|
|
100
|
+
* @param {T} entity - The entity instance for which to generate the content schema. The generic type `T` must extend {@link CoreEntity}.
|
|
101
|
+
* @returns {{ description: string; content: { 'application/json': { schema: SSchemaEl } }; } | undefined} An object containing the content schema, or `undefined` if no metadata is available for the entity.
|
|
102
|
+
*/
|
|
14
103
|
static contentSchemaFromEntity<T extends CoreEntity>(entity: T): {
|
|
15
104
|
description: string;
|
|
16
105
|
content: {
|
|
@@ -20,9 +109,91 @@ export default class SPathUtil {
|
|
|
20
109
|
};
|
|
21
110
|
} | undefined;
|
|
22
111
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
112
|
+
* Generates a mapping from entity names to their corresponding schema objects.
|
|
113
|
+
*
|
|
114
|
+
* @param {CoreEntity[]} e The entities for which schema entries should be generated.
|
|
115
|
+
* @return {SKey<SSchemaEl>} An object whose keys are entity names and values are the schemas derived from those entities.
|
|
25
116
|
*/
|
|
26
117
|
static schemaEntryGen(...e: CoreEntity[]): SKey<SSchemaEl>;
|
|
118
|
+
/**
|
|
119
|
+
* Builds a JSON schema representation for an entity view that includes both the
|
|
120
|
+
* entity data and its related entity map.
|
|
121
|
+
*
|
|
122
|
+
* @param entity The primary entity used to construct the `dat` portion of the schema.
|
|
123
|
+
* @param entityMap The related entity map used to construct the `join_map` portion of the schema.
|
|
124
|
+
* @returns A {@link SSchemaEl} object schema with properties `i`, `dat`, and `join_map`.
|
|
125
|
+
*/
|
|
27
126
|
static schemaFromEntityView<A extends CoreEntity, B extends CoreEntity>(entity: A, entityMap: B): SSchemaEl;
|
|
127
|
+
/**
|
|
128
|
+
* Extends an entity schema object by merging additional schema options.
|
|
129
|
+
*
|
|
130
|
+
* @param {CoreEntity} entity
|
|
131
|
+
* The entity for which the schema should be extended.
|
|
132
|
+
*
|
|
133
|
+
* @param {...Object} options
|
|
134
|
+
* One or more objects defining schema extensions. Each object may contain:
|
|
135
|
+
* - `key` (string): The property key to add or extend.
|
|
136
|
+
* - `list` (boolean, optional): Indicates whether the property is a list.
|
|
137
|
+
* - `entity` (CoreEntity, optional): The entity type for the property.
|
|
138
|
+
* - `schema` (SSchemaEl, optional): A custom schema definition for the property.
|
|
139
|
+
* - `required` (boolean, optional): Whether the property is required.
|
|
140
|
+
*
|
|
141
|
+
* @return {SSchemaEl}
|
|
142
|
+
* The resulting schema element. If a single property is returned by
|
|
143
|
+
* `extendEntitySchema`, its schema is returned directly; otherwise an
|
|
144
|
+
* object schema with a type of `'object'` is returned.
|
|
145
|
+
*/
|
|
146
|
+
static extendEntitySchemaObject(entity: CoreEntity, ...options: {
|
|
147
|
+
key: string;
|
|
148
|
+
list?: boolean;
|
|
149
|
+
entity?: CoreEntity;
|
|
150
|
+
schema?: SSchemaEl;
|
|
151
|
+
required?: boolean;
|
|
152
|
+
}[]): SSchemaEl;
|
|
153
|
+
/**
|
|
154
|
+
* Extends the schema of a given {@link CoreEntity} with additional properties.
|
|
155
|
+
*
|
|
156
|
+
* @param {CoreEntity} entity
|
|
157
|
+
* The entity whose schema will be extended.
|
|
158
|
+
*
|
|
159
|
+
* @param {...{
|
|
160
|
+
* key: string,
|
|
161
|
+
* list?: boolean,
|
|
162
|
+
* entity?: CoreEntity,
|
|
163
|
+
* schema?: SSchemaEl,
|
|
164
|
+
* required?: boolean
|
|
165
|
+
* }} options
|
|
166
|
+
* One or more option objects specifying the extensions to apply. Each option
|
|
167
|
+
* may provide either a direct schema (`schema`) or an entity reference
|
|
168
|
+
* (`entity`). The `list` flag indicates whether the property should be
|
|
169
|
+
* represented as an array of the provided schema. The `required` flag
|
|
170
|
+
* adds the property to the schema’s required list.
|
|
171
|
+
*
|
|
172
|
+
* @returns {SKey<SSchemaEl>}
|
|
173
|
+
* An object containing the updated schema for the entity, keyed by the
|
|
174
|
+
* entity’s name. If the entity metadata cannot be found, an empty
|
|
175
|
+
* object is returned.
|
|
176
|
+
*/
|
|
177
|
+
static extendEntitySchema(entity: CoreEntity, ...options: {
|
|
178
|
+
key: string;
|
|
179
|
+
list?: boolean;
|
|
180
|
+
entity?: CoreEntity;
|
|
181
|
+
schema?: SSchemaEl;
|
|
182
|
+
required?: boolean;
|
|
183
|
+
}[]): SKey<SSchemaEl>;
|
|
184
|
+
/**
|
|
185
|
+
* Reduces the entity schema to a single schema element or a generic object.
|
|
186
|
+
*
|
|
187
|
+
* @param entity The entity whose schema should be reduced.
|
|
188
|
+
* @param keys Optional list of keys to include in the reduced schema. If omitted, all keys are considered.
|
|
189
|
+
* @return Returns the schema element of the sole key if only one key is present; otherwise, returns a generic object schema with type `'object'`. */
|
|
190
|
+
static reduceEntitySchemaObject<T extends CoreEntity>(entity: T, ...keys: (keyof T)[]): SSchemaEl;
|
|
191
|
+
/**
|
|
192
|
+
* Creates a reduced version of an entity's schema by excluding specified properties.
|
|
193
|
+
*
|
|
194
|
+
* @param {CoreEntity} entity - The entity whose schema is to be processed.
|
|
195
|
+
* @param {...string} keys - Property names to remove from the schema's `properties` and `required` lists.
|
|
196
|
+
*
|
|
197
|
+
* @returns */
|
|
198
|
+
static reduceEntitySchema<T extends CoreEntity>(entity: T, ...keys: (keyof T)[]): SKey<SSchemaEl>;
|
|
28
199
|
}
|