vona-module-a-openapi 5.0.38 → 5.0.39
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/.metadata/index.d.ts +19 -0
- package/dist/bean/bean.openapi.d.ts +7 -0
- package/dist/index.js +76 -51
- package/dist/service/openapi.d.ts +5 -4
- package/package.json +3 -3
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
/** bean: begin */
|
|
2
|
+
export * from '../bean/bean.openapi.ts';
|
|
3
|
+
import 'vona';
|
|
4
|
+
declare module 'vona' {
|
|
5
|
+
}
|
|
6
|
+
declare module 'vona-module-a-openapi' {
|
|
7
|
+
interface BeanOpenapi {
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/** bean: end */
|
|
11
|
+
/** bean: begin */
|
|
12
|
+
import type { BeanOpenapi } from '../bean/bean.openapi.ts';
|
|
13
|
+
import 'vona';
|
|
14
|
+
declare module 'vona' {
|
|
15
|
+
interface IBeanRecordGlobal {
|
|
16
|
+
'openapi': BeanOpenapi;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** bean: end */
|
|
1
20
|
/** service: begin */
|
|
2
21
|
export * from '../service/openapi.ts';
|
|
3
22
|
import 'vona';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Constructable } from 'vona';
|
|
2
|
+
import type { IOpenapiObject } from 'vona-module-a-openapiutils';
|
|
3
|
+
import { BeanBase } from 'vona';
|
|
4
|
+
export declare class BeanOpenapi extends BeanBase {
|
|
5
|
+
generateJsonOfClass<K extends keyof IOpenapiObject>(schemaClass: Constructable, version?: K): Promise<IOpenapiObject[K]>;
|
|
6
|
+
generateJsonOfClasses<K extends keyof IOpenapiObject>(schemaClasses: Constructable[], version?: K): Promise<IOpenapiObject[K]>;
|
|
7
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,20 @@
|
|
|
1
1
|
import { registerMappedClassMetadataKey, appMetadata, appResource, cast, deepExtend, BeanInfo, BeanBase, LocaleModuleNameSeparator, HttpStatus, BeanSimple, BeanScopeBase, useApp, beanFullNameFromOnionName } from 'vona';
|
|
2
|
-
import
|
|
2
|
+
import { OpenAPIRegistry, OpenApiGeneratorV3, OpenApiGeneratorV31 } from '@cabloy/zod-to-openapi';
|
|
3
|
+
import { Bean, Service, Scope } from 'vona-module-a-bean';
|
|
4
|
+
import { SymbolDecoratorRule, SymbolOpenApiOptions } from 'vona-module-a-openapiutils';
|
|
5
|
+
import { z } from 'zod';
|
|
3
6
|
import { isEmptyObject, isClass, isNil } from '@cabloy/utils';
|
|
7
|
+
import { ZodMetadata } from '@cabloy/zod-openapi';
|
|
8
|
+
import * as ModuleInfo from '@cabloy/module-info';
|
|
4
9
|
import { toUpperCaseFirstChar } from '@cabloy/word-utils';
|
|
10
|
+
import { translateError } from '@cabloy/zod-errors-custom';
|
|
5
11
|
import { getInnerTypeName, coerceWithNil } from '@cabloy/zod-query';
|
|
6
|
-
import { OpenApiGeneratorV3, OpenApiGeneratorV31, OpenAPIRegistry } from '@cabloy/zod-to-openapi';
|
|
7
|
-
import { Service, Scope } from 'vona-module-a-bean';
|
|
8
12
|
import { Caching } from 'vona-module-a-caching';
|
|
9
|
-
import { SymbolDecoratorRule, SymbolOpenApiOptions } from 'vona-module-a-openapiutils';
|
|
10
13
|
import { SymbolRequestMappingHandler } from 'vona-module-a-web';
|
|
11
|
-
import { z } from 'zod';
|
|
12
|
-
import { ZodMetadata } from '@cabloy/zod-openapi';
|
|
13
14
|
import { SummerCache, BeanSummerCacheBase } from 'vona-module-a-summer';
|
|
14
15
|
import 'openapi3-ts/oas30';
|
|
15
16
|
import 'openapi3-ts/oas31';
|
|
16
17
|
|
|
17
|
-
function _applyDecoratedDescriptor(i, e, r, n, l) {
|
|
18
|
-
var a = {};
|
|
19
|
-
return Object.keys(n).forEach(function (i) {
|
|
20
|
-
a[i] = n[i];
|
|
21
|
-
}), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = true), a = r.slice().reverse().reduce(function (r, n) {
|
|
22
|
-
return n(i, e, r) || r;
|
|
23
|
-
}, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function bodySchemaWrapperDefault(bodySchema) {
|
|
27
|
-
return z.object({
|
|
28
|
-
code: z.string(),
|
|
29
|
-
message: z.string(),
|
|
30
|
-
data: bodySchema
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
18
|
function getTargetDecoratorRules(target, disableRegisterMetadata) {
|
|
35
19
|
if (!disableRegisterMetadata) {
|
|
36
20
|
registerMappedClassMetadataKey(target, SymbolDecoratorRule, {
|
|
@@ -191,6 +175,52 @@ function _createSchemaObject(rules, options) {
|
|
|
191
175
|
return schema;
|
|
192
176
|
}
|
|
193
177
|
|
|
178
|
+
var _dec$3, _dec2$3, _class$3;
|
|
179
|
+
let BeanOpenapi = (_dec$3 = Bean(), _dec2$3 = BeanInfo({
|
|
180
|
+
module: "a-openapi"
|
|
181
|
+
}), _dec$3(_class$3 = _dec2$3(_class$3 = class BeanOpenapi extends BeanBase {
|
|
182
|
+
// need not cache
|
|
183
|
+
async generateJsonOfClass(schemaClass, version = 'V31') {
|
|
184
|
+
return await this.generateJsonOfClasses([schemaClass], version);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// need not cache
|
|
188
|
+
async generateJsonOfClasses(schemaClasses, version = 'V31') {
|
|
189
|
+
const registry = new OpenAPIRegistry();
|
|
190
|
+
// schema: independent
|
|
191
|
+
let counter = 0;
|
|
192
|
+
for (const schemaClass of schemaClasses) {
|
|
193
|
+
const schema = $schema(schemaClass);
|
|
194
|
+
let beanFullName = appResource.getBeanFullName(schemaClass);
|
|
195
|
+
if (!beanFullName) {
|
|
196
|
+
beanFullName = `${schemaClass.name}_${counter++}`;
|
|
197
|
+
}
|
|
198
|
+
registry.register(beanFullName, schema);
|
|
199
|
+
}
|
|
200
|
+
const generator = version === 'V30' ? new OpenApiGeneratorV3(registry.definitions) : new OpenApiGeneratorV31(registry.definitions);
|
|
201
|
+
const apiObj = generator.generateDocument(this.scope.config.generateDocument[version]);
|
|
202
|
+
this.scope.service.openapi.translate(apiObj, 'rest');
|
|
203
|
+
return apiObj;
|
|
204
|
+
}
|
|
205
|
+
}) || _class$3) || _class$3);
|
|
206
|
+
|
|
207
|
+
function _applyDecoratedDescriptor(i, e, r, n, l) {
|
|
208
|
+
var a = {};
|
|
209
|
+
return Object.keys(n).forEach(function (i) {
|
|
210
|
+
a[i] = n[i];
|
|
211
|
+
}), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = true), a = r.slice().reverse().reduce(function (r, n) {
|
|
212
|
+
return n(i, e, r) || r;
|
|
213
|
+
}, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function bodySchemaWrapperDefault(bodySchema) {
|
|
217
|
+
return z.object({
|
|
218
|
+
code: z.string(),
|
|
219
|
+
message: z.string(),
|
|
220
|
+
data: bodySchema
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
194
224
|
const SymbolRouteHandlersArgumentsMeta = Symbol('SymbolRouteHandlersArgumentsMeta');
|
|
195
225
|
const SymbolRouteHandlersArgumentsValue = Symbol('SymbolRouteHandlersArgumentsValue');
|
|
196
226
|
|
|
@@ -221,7 +251,7 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
|
|
|
221
251
|
const registry = this._collectRegistry();
|
|
222
252
|
const generator = version === 'V30' ? new OpenApiGeneratorV3(registry.definitions) : new OpenApiGeneratorV31(registry.definitions);
|
|
223
253
|
const apiObj = generator.generateDocument(this.scope.config.generateDocument[version]);
|
|
224
|
-
this.
|
|
254
|
+
this.translate(apiObj, 'api');
|
|
225
255
|
return apiObj;
|
|
226
256
|
}
|
|
227
257
|
async generateJsonOfControllerAction(controller, actionKey, version = 'V31') {
|
|
@@ -231,34 +261,10 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
|
|
|
231
261
|
this._collectController(registry, beanOptions.module, controller, actionKey);
|
|
232
262
|
const generator = version === 'V30' ? new OpenApiGeneratorV3(registry.definitions) : new OpenApiGeneratorV31(registry.definitions);
|
|
233
263
|
const apiObj = generator.generateDocument(this.scope.config.generateDocument[version]);
|
|
234
|
-
this.
|
|
235
|
-
return apiObj;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// need not cache
|
|
239
|
-
async generateJsonOfClass(schemaClass, version = 'V31') {
|
|
240
|
-
return await this.generateJsonOfClasses([schemaClass], version);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// need not cache
|
|
244
|
-
async generateJsonOfClasses(schemaClasses, version = 'V31') {
|
|
245
|
-
const registry = new OpenAPIRegistry();
|
|
246
|
-
// schema: independent
|
|
247
|
-
let counter = 0;
|
|
248
|
-
for (const schemaClass of schemaClasses) {
|
|
249
|
-
const schema = $schema(schemaClass);
|
|
250
|
-
let beanFullName = appResource.getBeanFullName(schemaClass);
|
|
251
|
-
if (!beanFullName) {
|
|
252
|
-
beanFullName = `${schemaClass.name}_${counter++}`;
|
|
253
|
-
}
|
|
254
|
-
registry.register(beanFullName, schema);
|
|
255
|
-
}
|
|
256
|
-
const generator = version === 'V30' ? new OpenApiGeneratorV3(registry.definitions) : new OpenApiGeneratorV31(registry.definitions);
|
|
257
|
-
const apiObj = generator.generateDocument(this.scope.config.generateDocument[version]);
|
|
258
|
-
this._translate(apiObj, 'rest');
|
|
264
|
+
this.translate(apiObj, 'rest');
|
|
259
265
|
return apiObj;
|
|
260
266
|
}
|
|
261
|
-
|
|
267
|
+
translate(apiObj, generateJsonScene) {
|
|
262
268
|
// paths
|
|
263
269
|
if (apiObj.paths) {
|
|
264
270
|
for (const key in apiObj.paths) {
|
|
@@ -294,6 +300,8 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
|
|
|
294
300
|
schema.description = schema.title;
|
|
295
301
|
delete schema.title;
|
|
296
302
|
}
|
|
303
|
+
// errorMessage
|
|
304
|
+
this._translateErrorMessages(schema);
|
|
297
305
|
// properties
|
|
298
306
|
const properties = cast(schema).properties;
|
|
299
307
|
if (properties && typeof properties === 'object') {
|
|
@@ -308,6 +316,23 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
|
|
|
308
316
|
this._translateSchema(items, generateJsonScene);
|
|
309
317
|
}
|
|
310
318
|
}
|
|
319
|
+
_translateErrorMessages(obj) {
|
|
320
|
+
if (!obj.errorMessage) return;
|
|
321
|
+
for (const key in obj.errorMessage) {
|
|
322
|
+
let error = obj.errorMessage[key];
|
|
323
|
+
if (typeof error === 'function') {
|
|
324
|
+
error = error();
|
|
325
|
+
}
|
|
326
|
+
const scope = Object.assign({}, obj);
|
|
327
|
+
if (!isNil(obj.minLength)) scope.minimum = obj.minLength;
|
|
328
|
+
if (!isNil(obj.exclusiveMinimum)) scope.minimum = obj.exclusiveMinimum;
|
|
329
|
+
if (!isNil(obj.maxLength)) scope.maximum = obj.maxLength;
|
|
330
|
+
if (!isNil(obj.exclusiveMaximum)) scope.maximum = obj.exclusiveMaximum;
|
|
331
|
+
obj.errorMessage[key] = translateError((text, ...args) => {
|
|
332
|
+
return this.app.meta.text(text, ...args);
|
|
333
|
+
}, error, scope);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
311
336
|
_translateStrings(obj, keys) {
|
|
312
337
|
for (const key of keys) {
|
|
313
338
|
this._translateString(obj, key);
|
|
@@ -1050,4 +1075,4 @@ const OrderBusinessBase = 1000;
|
|
|
1050
1075
|
const OrderUnknownBase = 10000;
|
|
1051
1076
|
const OrderMaxBase = 100000;
|
|
1052
1077
|
|
|
1053
|
-
export { $locale, $schema, $schemaLazy, Api, Main, OrderBusinessBase, OrderCoreBase, OrderMaxBase, OrderUnknownBase, ScopeModuleAOpenapi, ServiceOpenapi, SummerCacheJson, SymbolRouteHandlersArgumentsMeta, SymbolRouteHandlersArgumentsValue, SymbolSchemaDynamicRefId, addSchemaDynamic, bodySchemaWrapperDefault, config, getSchemaDynamic, getSchemasDynamic, getTargetDecoratorRuleColumns, getTargetDecoratorRuleColumnsMap, getTargetDecoratorRules, locales, makeSchemaLike, makeSchemaLikes, mergeFieldOpenapiMetadata, mergeFieldsOpenapiMetadata, prepareClassType, schemaRefCustomAdapter, v };
|
|
1078
|
+
export { $locale, $schema, $schemaLazy, Api, BeanOpenapi, Main, OrderBusinessBase, OrderCoreBase, OrderMaxBase, OrderUnknownBase, ScopeModuleAOpenapi, ServiceOpenapi, SummerCacheJson, SymbolRouteHandlersArgumentsMeta, SymbolRouteHandlersArgumentsValue, SymbolSchemaDynamicRefId, addSchemaDynamic, bodySchemaWrapperDefault, config, getSchemaDynamic, getSchemasDynamic, getTargetDecoratorRuleColumns, getTargetDecoratorRuleColumnsMap, getTargetDecoratorRules, locales, makeSchemaLike, makeSchemaLikes, mergeFieldOpenapiMetadata, mergeFieldsOpenapiMetadata, prepareClassType, schemaRefCustomAdapter, v };
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
import type { OpenAPIObject as OpenAPIObject30 } from 'openapi3-ts/oas30';
|
|
2
|
+
import type { OpenAPIObject as OpenAPIObject31 } from 'openapi3-ts/oas31';
|
|
1
3
|
import type { Constructable } from 'vona';
|
|
2
|
-
import type { IOpenapiObject } from 'vona-module-a-openapiutils';
|
|
4
|
+
import type { IOpenapiObject, TypeGenerateJsonScene } from 'vona-module-a-openapiutils';
|
|
3
5
|
import { BeanBase } from 'vona';
|
|
4
6
|
export declare class ServiceOpenapi extends BeanBase {
|
|
5
7
|
protected generateJsonCacheKey(args: any[], prop: string): string;
|
|
6
8
|
protected generateJsonOfControllerActionCacheKey(args: any[], prop: string): string;
|
|
7
9
|
generateJson<K extends keyof IOpenapiObject>(version?: K): Promise<IOpenapiObject[K]>;
|
|
8
10
|
generateJsonOfControllerAction<K extends keyof IOpenapiObject>(controller: Constructable, actionKey: string, version?: K): Promise<IOpenapiObject[K]>;
|
|
9
|
-
|
|
10
|
-
generateJsonOfClasses<K extends keyof IOpenapiObject>(schemaClasses: Constructable[], version?: K): Promise<IOpenapiObject[K]>;
|
|
11
|
-
private _translate;
|
|
11
|
+
translate(apiObj: OpenAPIObject30 | OpenAPIObject31, generateJsonScene: TypeGenerateJsonScene): void;
|
|
12
12
|
private _translateSchema;
|
|
13
|
+
private _translateErrorMessages;
|
|
13
14
|
private _translateStrings;
|
|
14
15
|
private _translateString;
|
|
15
16
|
private _collectRegistry;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vona-module-a-openapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.39",
|
|
5
5
|
"title": "a-openapi",
|
|
6
6
|
"vonaModule": {
|
|
7
7
|
"capabilities": {
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"static"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@cabloy/zod-openapi": "^1.0.
|
|
38
|
+
"@cabloy/zod-openapi": "^1.0.3",
|
|
39
39
|
"@cabloy/zod-query": "^2.0.1",
|
|
40
|
-
"@cabloy/zod-to-openapi": "^8.1.
|
|
40
|
+
"@cabloy/zod-to-openapi": "^8.1.4",
|
|
41
41
|
"@zhennann/currency": "^2.0.0",
|
|
42
42
|
"openapi3-ts": "^4.5.0",
|
|
43
43
|
"zod": "^4.1.5"
|