vona-module-a-openapi 5.0.31 → 5.0.33
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/index.js +57 -29
- package/dist/lib/utils.d.ts +6 -2
- package/dist/types/rest.d.ts +1 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { registerMappedClassMetadataKey, appMetadata, appResource, cast, deepExtend, BeanInfo, BeanBase, LocaleModuleNameSeparator, HttpStatus, BeanSimple, BeanScopeBase, useApp, beanFullNameFromOnionName } from 'vona';
|
|
2
2
|
import * as ModuleInfo from '@cabloy/module-info';
|
|
3
|
-
import {
|
|
3
|
+
import { isEmptyObject, isClass, isNil } from '@cabloy/utils';
|
|
4
4
|
import { toUpperCaseFirstChar } from '@cabloy/word-utils';
|
|
5
5
|
import { getInnerTypeName, coerceWithNil } from '@cabloy/zod-query';
|
|
6
6
|
import { OpenApiGeneratorV3, OpenApiGeneratorV31, OpenAPIRegistry } from '@cabloy/zod-to-openapi';
|
|
7
7
|
import { Service, Scope } from 'vona-module-a-bean';
|
|
8
8
|
import { Caching } from 'vona-module-a-caching';
|
|
9
|
-
import { SymbolDecoratorRule,
|
|
9
|
+
import { SymbolDecoratorRule, SymbolOpenApiOptions } from 'vona-module-a-openapiutils';
|
|
10
10
|
import { SymbolRequestMappingHandler } from 'vona-module-a-web';
|
|
11
11
|
import { z } from 'zod';
|
|
12
12
|
import { ZodMetadata } from '@cabloy/zod-openapi';
|
|
@@ -31,21 +31,29 @@ function bodySchemaWrapperDefault(bodySchema) {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function getTargetDecoratorRules(target) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
function getTargetDecoratorRules(target, disableRegisterMetadata) {
|
|
35
|
+
if (!disableRegisterMetadata) {
|
|
36
|
+
registerMappedClassMetadataKey(target, SymbolDecoratorRule, {
|
|
37
|
+
partialClass: meta => {
|
|
38
|
+
return meta.optional();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
40
42
|
return appMetadata.getOwnMetadataMap(true, SymbolDecoratorRule, target);
|
|
41
43
|
}
|
|
42
44
|
function getTargetDecoratorRuleColumns(target) {
|
|
43
|
-
|
|
44
|
-
return
|
|
45
|
+
const rules = getTargetDecoratorRules(target, true);
|
|
46
|
+
return Object.keys(rules);
|
|
47
|
+
}
|
|
48
|
+
function getTargetDecoratorRuleColumnsMap(target) {
|
|
49
|
+
const columns = getTargetDecoratorRuleColumns(target);
|
|
50
|
+
const map = {};
|
|
51
|
+
for (const column of columns) {
|
|
52
|
+
map[column] = column;
|
|
53
|
+
}
|
|
54
|
+
return map;
|
|
45
55
|
}
|
|
46
56
|
function mergeFieldsOpenapiMetadata(target) {
|
|
47
|
-
// rules
|
|
48
|
-
const rules = getTargetDecoratorRules(target.prototype);
|
|
49
57
|
// beanOptions
|
|
50
58
|
const beanOptions = appResource.getBean(target);
|
|
51
59
|
const fields = cast(beanOptions?.options)?.fields;
|
|
@@ -53,18 +61,36 @@ function mergeFieldsOpenapiMetadata(target) {
|
|
|
53
61
|
for (const key in fields) {
|
|
54
62
|
const field = fields[key];
|
|
55
63
|
if (!field) continue;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
mergeFieldOpenapiMetadata(target.prototype, key, field);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// fieldRule maybe undefined
|
|
69
|
+
function mergeFieldOpenapiMetadata(target, prop, fieldRule) {
|
|
70
|
+
// rules
|
|
71
|
+
const rules = getTargetDecoratorRules(target);
|
|
72
|
+
// rule
|
|
73
|
+
const schemaCurrent = rules[prop];
|
|
74
|
+
const metadataCurrent = schemaCurrent ? ZodMetadata.getOpenapiMetadata(schemaCurrent) : undefined;
|
|
75
|
+
// merge
|
|
76
|
+
if (Object.prototype.hasOwnProperty.call(fieldRule, 'parseAsync')) {
|
|
77
|
+
const schema = fieldRule;
|
|
78
|
+
if (isEmptyObject(metadataCurrent)) {
|
|
79
|
+
rules[prop] = schema;
|
|
80
|
+
} else {
|
|
60
81
|
const metadataCustom = ZodMetadata.getOpenapiMetadata(schema);
|
|
61
|
-
rules[
|
|
82
|
+
rules[prop] = schema.openapi(deepExtend({}, metadataCurrent, metadataCustom));
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
if (schemaCurrent) {
|
|
86
|
+
if (!isEmptyObject(fieldRule)) {
|
|
87
|
+
rules[prop] = schemaCurrent.openapi(deepExtend({}, metadataCurrent, fieldRule));
|
|
88
|
+
}
|
|
62
89
|
} else {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
rules[key] = schemaCurrent.openapi(deepExtend({}, metadataCurrent, field));
|
|
90
|
+
if (isEmptyObject(fieldRule)) {
|
|
91
|
+
rules[prop] = z.any();
|
|
66
92
|
} else {
|
|
67
|
-
rules[
|
|
93
|
+
rules[prop] = z.any().openapi(fieldRule);
|
|
68
94
|
}
|
|
69
95
|
}
|
|
70
96
|
}
|
|
@@ -259,11 +285,13 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
|
|
|
259
285
|
_translateSchema(schema, generateJsonScene) {
|
|
260
286
|
if (!schema) return;
|
|
261
287
|
if (schema.type === 'object' && schema.required === undefined) schema.required = [];
|
|
288
|
+
// schema
|
|
262
289
|
this._translateStrings(schema, ['title', 'description']);
|
|
263
290
|
if (generateJsonScene === 'api' && !schema.description && schema.title) {
|
|
264
291
|
schema.description = schema.title;
|
|
265
292
|
delete schema.title;
|
|
266
293
|
}
|
|
294
|
+
// properties
|
|
267
295
|
const properties = cast(schema).properties;
|
|
268
296
|
if (properties && typeof properties === 'object') {
|
|
269
297
|
for (const prop in properties) {
|
|
@@ -271,6 +299,11 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
|
|
|
271
299
|
this._translateSchema(propObj, generateJsonScene);
|
|
272
300
|
}
|
|
273
301
|
}
|
|
302
|
+
// items
|
|
303
|
+
const items = cast(schema).items;
|
|
304
|
+
if (items && typeof items === 'object') {
|
|
305
|
+
this._translateSchema(items, generateJsonScene);
|
|
306
|
+
}
|
|
274
307
|
}
|
|
275
308
|
_translateStrings(obj, keys) {
|
|
276
309
|
for (const key of keys) {
|
|
@@ -618,14 +651,9 @@ let ScopeModuleAOpenapi = (_dec = Scope(), _dec2 = BeanInfo({
|
|
|
618
651
|
|
|
619
652
|
function Field(...schemaLikes) {
|
|
620
653
|
return function (target, prop) {
|
|
621
|
-
// rules
|
|
622
|
-
const rules = getTargetDecoratorRules(target);
|
|
623
|
-
// rule
|
|
624
654
|
const metaType = appMetadata.getDesignType(target, prop);
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
const columns = getTargetDecoratorRuleColumns(target);
|
|
628
|
-
columns[prop] = prop;
|
|
655
|
+
const schema = makeSchemaLikes(schemaLikes, metaType);
|
|
656
|
+
mergeFieldOpenapiMetadata(target, prop, schema);
|
|
629
657
|
};
|
|
630
658
|
}
|
|
631
659
|
|
|
@@ -962,4 +990,4 @@ const OrderBusinessBase = 1000;
|
|
|
962
990
|
const OrderUnknownBase = 10000;
|
|
963
991
|
const OrderMaxBase = 100000;
|
|
964
992
|
|
|
965
|
-
export { $schema, $schemaLazy, Api, Main, OrderBusinessBase, OrderCoreBase, OrderMaxBase, OrderUnknownBase, ScopeModuleAOpenapi, ServiceOpenapi, SummerCacheJson, SymbolRouteHandlersArgumentsMeta, SymbolRouteHandlersArgumentsValue, SymbolSchemaDynamicRefId, addSchemaDynamic, bodySchemaWrapperDefault, config, getSchemaDynamic, getSchemasDynamic, getTargetDecoratorRuleColumns, getTargetDecoratorRules, makeSchemaLike, makeSchemaLikes, mergeFieldsOpenapiMetadata, prepareClassType, schemaRefCustomAdapter, v };
|
|
993
|
+
export { $schema, $schemaLazy, Api, Main, OrderBusinessBase, OrderCoreBase, OrderMaxBase, OrderUnknownBase, ScopeModuleAOpenapi, ServiceOpenapi, SummerCacheJson, SymbolRouteHandlersArgumentsMeta, SymbolRouteHandlersArgumentsValue, SymbolSchemaDynamicRefId, addSchemaDynamic, bodySchemaWrapperDefault, config, getSchemaDynamic, getSchemasDynamic, getTargetDecoratorRuleColumns, getTargetDecoratorRuleColumnsMap, getTargetDecoratorRules, makeSchemaLike, makeSchemaLikes, mergeFieldOpenapiMetadata, mergeFieldsOpenapiMetadata, prepareClassType, schemaRefCustomAdapter, v };
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { Constructable } from 'vona';
|
|
2
2
|
import type { TypeDecoratorRules } from 'vona-module-a-openapiutils';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import type { TypeOpenapiMetadata } from '../types/rest.ts';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
export declare function getTargetDecoratorRules(target: object, disableRegisterMetadata?: boolean): TypeDecoratorRules;
|
|
6
|
+
export declare function getTargetDecoratorRuleColumns(target: object): string[];
|
|
7
|
+
export declare function getTargetDecoratorRuleColumnsMap(target: object): Record<string, string>;
|
|
5
8
|
export declare function mergeFieldsOpenapiMetadata(target: Constructable): void;
|
|
9
|
+
export declare function mergeFieldOpenapiMetadata(target: object, prop: string, fieldRule?: TypeOpenapiMetadata | z.ZodType): void;
|
|
6
10
|
export declare function prepareClassType<T>(classType: (() => Constructable<T>) | Constructable<T>): Constructable<T>;
|
package/dist/types/rest.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export interface ISchemaObjectExtensionFieldRest {
|
|
|
17
17
|
form?: Omit<ISchemaObjectExtensionFieldRest, 'table' | 'form'>;
|
|
18
18
|
}
|
|
19
19
|
export interface ISchemaObjectExtensionField {
|
|
20
|
+
exclude?: boolean;
|
|
20
21
|
rest?: ISchemaObjectExtensionFieldRest;
|
|
21
22
|
query?: ISchemaObjectExtensionFieldQuery;
|
|
22
23
|
captcha?: ISchemaObjectExtensionFieldCaptcha;
|
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.33",
|
|
5
5
|
"title": "a-openapi",
|
|
6
6
|
"vonaModule": {
|
|
7
7
|
"capabilities": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"static"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@cabloy/zod-errors-custom": "^2.0.
|
|
38
|
+
"@cabloy/zod-errors-custom": "^2.0.2",
|
|
39
39
|
"@cabloy/zod-openapi": "^1.0.1",
|
|
40
40
|
"@cabloy/zod-query": "^2.0.1",
|
|
41
41
|
"@cabloy/zod-to-openapi": "^8.1.1",
|