vona-module-a-openapi 5.0.60 → 5.0.62

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 CHANGED
@@ -1,4 +1,5 @@
1
1
  import { BeanInfo, BeanBase, appResource, beanFullNameFromOnionName, cast, appMetadata, BeanSimple, BeanScopeBase } from 'vona';
2
+ import { __decorate, __metadata } from 'tslib';
2
3
  import { OpenAPIRegistry, OpenApiGeneratorV3, OpenApiGeneratorV31 } from '@cabloy/zod-to-openapi';
3
4
  import { Bean, Service, Scope } from 'vona-module-a-bean';
4
5
  import { Caching } from 'vona-module-a-caching';
@@ -15,30 +16,12 @@ import { ZodMetadata } from '@cabloy/zod-openapi';
15
16
  import 'openapi3-ts/oas30';
16
17
  import 'openapi3-ts/oas31';
17
18
 
18
- function _applyDecoratedDescriptor(i, e, r, n, l) {
19
- var a = {};
20
- return Object.keys(n).forEach(function (i) {
21
- a[i] = n[i];
22
- }), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = true), a = r.slice().reverse().reduce(function (r, n) {
23
- return n(i, e, r) || r;
24
- }, 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;
25
- }
26
-
27
- var _dec$3, _dec2$3, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class$3, _class2;
28
- let BeanOpenapi = (_dec$3 = Bean(), _dec2$3 = BeanInfo({
29
- module: "a-openapi"
30
- }), _dec3 = Caching.get({
31
- cacheName: 'a-openapi:json',
32
- cacheKeyFn: 'generateJsonCacheKey'
33
- }), _dec4 = Reflect.metadata("design:type", Function), _dec5 = Reflect.metadata("design:paramtypes", [typeof K === "undefined" ? Object : K]), _dec6 = Caching.get({
34
- cacheName: 'a-openapi:json',
35
- cacheKeyFn: 'generateJsonOfControllerActionCacheKey'
36
- }), _dec7 = Reflect.metadata("design:type", Function), _dec8 = Reflect.metadata("design:paramtypes", [typeof Constructable === "undefined" ? Object : Constructable, String, typeof K === "undefined" ? Object : K]), _dec$3(_class$3 = _dec2$3(_class$3 = (_class2 = class BeanOpenapi extends BeanBase {
19
+ var _a, _b;
20
+ let BeanOpenapi = class BeanOpenapi extends BeanBase {
37
21
  // need not cache
38
22
  async generateJsonOfClass(schemaClass, version = 'V31') {
39
23
  return await this.generateJsonOfClasses([schemaClass], version);
40
24
  }
41
-
42
25
  // need not cache
43
26
  async generateJsonOfClasses(schemaClasses, version = 'V31') {
44
27
  const registry = new OpenAPIRegistry();
@@ -86,13 +69,22 @@ let BeanOpenapi = (_dec$3 = Bean(), _dec2$3 = BeanInfo({
86
69
  this.scope.service.openapi.translate(apiObj, 'rest');
87
70
  return apiObj;
88
71
  }
89
- }, _applyDecoratedDescriptor(_class2.prototype, "generateJson", [_dec3, _dec4, _dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "generateJson"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "generateJsonOfControllerAction", [_dec6, _dec7, _dec8], Object.getOwnPropertyDescriptor(_class2.prototype, "generateJsonOfControllerAction"), _class2.prototype), _class2)) || _class$3) || _class$3);
72
+ };
73
+ __decorate([Caching.get({
74
+ cacheName: 'a-openapi:json',
75
+ cacheKeyFn: 'generateJsonCacheKey'
76
+ }), __metadata("design:type", Function), __metadata("design:paramtypes", [typeof (_a = typeof K !== "undefined" && K) === "function" ? _a : Object]), __metadata("design:returntype", Promise)], BeanOpenapi.prototype, "generateJson", null);
77
+ __decorate([Caching.get({
78
+ cacheName: 'a-openapi:json',
79
+ cacheKeyFn: 'generateJsonOfControllerActionCacheKey'
80
+ }), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, String, typeof (_b = typeof K !== "undefined" && K) === "function" ? _b : Object]), __metadata("design:returntype", Promise)], BeanOpenapi.prototype, "generateJsonOfControllerAction", null);
81
+ BeanOpenapi = __decorate([Bean(), BeanInfo({
82
+ module: "a-openapi"
83
+ })], BeanOpenapi);
90
84
 
91
- var _dec$2, _dec2$2, _class$2;
92
85
  const __ArgumentTypes = ['param', 'query', 'body', 'headers', 'fields', 'field', 'files', 'file'];
93
- let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
94
- module: "a-openapi"
95
- }), _dec$2(_class$2 = _dec2$2(_class$2 = class ServiceOpenapi extends BeanBase {
86
+ const symbolJsxRenderTranslated = Symbol('symbolJsxRenderTranslated');
87
+ let ServiceOpenapi = class ServiceOpenapi extends BeanBase {
96
88
  async clearAllCaches() {
97
89
  const cacheOpenapiSchema = this.bean.summer.cache(beanFullNameFromOnionName('a-openapi:json', 'summerCache'));
98
90
  await cacheOpenapiSchema.clear();
@@ -110,10 +102,14 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
110
102
  const methodObj = pathObj[method];
111
103
  // parameters
112
104
  for (const parameterObj of methodObj.parameters || []) {
113
- this._translateSchema(parameterObj.schema, generateJsonScene);
105
+ if (parameterObj.schema) {
106
+ parameterObj.schema = this._translateSchema(parameterObj.schema, generateJsonScene);
107
+ }
114
108
  }
115
109
  // requestBody
116
- this._translateSchema(methodObj.requestBody?.content?.['application/json']?.schema, generateJsonScene);
110
+ if (methodObj.requestBody?.content?.['application/json']?.schema) {
111
+ methodObj.requestBody.content['application/json'].schema = this._translateSchema(methodObj.requestBody.content['application/json'].schema, generateJsonScene);
112
+ }
117
113
  }
118
114
  }
119
115
  }
@@ -121,12 +117,13 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
121
117
  if (apiObj.components?.schemas) {
122
118
  for (const key in apiObj.components.schemas) {
123
119
  const schema = apiObj.components.schemas[key];
124
- this._translateSchema(schema, generateJsonScene);
120
+ if (schema) {
121
+ apiObj.components.schemas[key] = this._translateSchema(schema, generateJsonScene);
122
+ }
125
123
  }
126
124
  }
127
125
  }
128
126
  _translateSchema(schema, generateJsonScene) {
129
- if (!schema) return;
130
127
  if (schema.type === 'object' && schema.required === undefined) schema.required = [];
131
128
  // serializerTransforms
132
129
  delete schema.serializerTransforms;
@@ -148,19 +145,25 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
148
145
  }
149
146
  // errorMessage
150
147
  this._translateErrorMessages(schema);
148
+ // jsxRender
149
+ this._translateJsxRenders(schema);
151
150
  // properties
152
151
  const properties = cast(schema).properties;
153
152
  if (properties && typeof properties === 'object') {
154
153
  for (const prop in properties) {
155
154
  const propObj = properties[prop];
156
- this._translateSchema(propObj, generateJsonScene);
155
+ if (propObj) {
156
+ properties[prop] = this._translateSchema(propObj, generateJsonScene);
157
+ }
157
158
  }
158
159
  }
159
160
  // items
160
161
  const items = cast(schema).items;
161
162
  if (items && typeof items === 'object') {
162
- this._translateSchema(items, generateJsonScene);
163
+ cast(schema).items = this._translateSchema(items, generateJsonScene);
163
164
  }
165
+ // ok
166
+ return schema;
164
167
  }
165
168
  _translateErrorMessages(obj) {
166
169
  if (!obj.errorMessage) return;
@@ -179,6 +182,36 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
179
182
  }, error, scope);
180
183
  }
181
184
  }
185
+ _translateJsxRenders(obj) {
186
+ if (obj.rest?.render) {
187
+ obj.rest.render = this._translateJsxRender(obj.rest.render);
188
+ }
189
+ if (obj.rest?.table?.render) {
190
+ obj.rest.table.render = this._translateJsxRender(obj.rest.table.render);
191
+ }
192
+ if (obj.rest?.form?.render) {
193
+ obj.rest.form.render = this._translateJsxRender(obj.rest.form.render);
194
+ }
195
+ }
196
+ _translateJsxRender(component) {
197
+ if (component[symbolJsxRenderTranslated] === true) return component;
198
+ const componentNew = {};
199
+ componentNew[symbolJsxRenderTranslated] = true;
200
+ componentNew.type = typeof component.type === 'function' ? component.type() : component.type;
201
+ componentNew.key = component.key;
202
+ componentNew.props = {
203
+ ...component.props
204
+ };
205
+ const children = componentNew.props.children;
206
+ if (children) {
207
+ if (Array.isArray(children)) {
208
+ componentNew.props.children = children.map(item => this._translateJsxRender(item));
209
+ } else if (typeof children === 'object' && !children.toJSON) {
210
+ componentNew.props.children = this._translateJsxRender(children);
211
+ }
212
+ }
213
+ return componentNew;
214
+ }
182
215
  collectRegistry() {
183
216
  const registry = new OpenAPIRegistry();
184
217
  // securitySchemes
@@ -230,22 +263,18 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
230
263
  _registerControllerAction(registry, info, controller, beanOptions, _controllerBeanFullName, controllerPath, controllerOpenApiOptions, actionKey, _desc) {
231
264
  // app
232
265
  const app = this.app;
233
-
234
266
  // action options: should not extend controllerOpenApiOptions
235
267
  const actionOpenApiOptions = appMetadata.getMetadata(SymbolOpenApiOptions, controller.prototype, actionKey);
236
268
  if (actionOpenApiOptions?.exclude) return;
237
-
238
269
  // actionPath/actionMethod
239
270
  if (!appMetadata.hasMetadata(SymbolRequestMappingHandler, controller.prototype, actionKey)) return;
240
271
  const handlerMetadata = appMetadata.getMetadata(SymbolRequestMappingHandler, controller.prototype, actionKey);
241
272
  const actionPath = handlerMetadata.path || '';
242
273
  const actionMethod = handlerMetadata.method || 'get';
243
-
244
274
  // routePath
245
275
  const routePath = app.util.combineApiPathControllerAndAction(info.relativeName, controllerPath, actionPath, true, true);
246
276
  // :id -> {id}
247
277
  const routePath2 = routePath.replace(/:([^/]+)/g, '{$1}');
248
-
249
278
  // tags
250
279
  let tags = actionOpenApiOptions?.tags ?? controllerOpenApiOptions?.tags;
251
280
  if (!tags || tags.length === 0) {
@@ -422,16 +451,19 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
422
451
  }
423
452
  return objHeaders;
424
453
  }
425
- }) || _class$2) || _class$2);
454
+ };
455
+ ServiceOpenapi = __decorate([Service(), BeanInfo({
456
+ module: "a-openapi"
457
+ })], ServiceOpenapi);
426
458
 
427
- var _dec$1, _dec2$1, _class$1;
428
- let SummerCacheJson = (_dec$1 = SummerCache({
459
+ let SummerCacheJson = class SummerCacheJson extends BeanSummerCacheBase {
460
+ async getNative(_key, _options) {}
461
+ };
462
+ SummerCacheJson = __decorate([SummerCache({
429
463
  preset: 'mem'
430
- }), _dec2$1 = BeanInfo({
464
+ }), BeanInfo({
431
465
  module: "a-openapi"
432
- }), _dec$1(_class$1 = _dec2$1(_class$1 = class SummerCacheJson extends BeanSummerCacheBase {
433
- async getNative(_key, _options) {}
434
- }) || _class$1) || _class$1);
466
+ })], SummerCacheJson);
435
467
 
436
468
  function config(_app) {
437
469
  return {
@@ -497,11 +529,10 @@ class Main extends BeanSimple {
497
529
  async configLoaded(_config) {}
498
530
  }
499
531
 
500
- var _dec, _dec2, _class;
501
- let ScopeModuleAOpenapi = (_dec = Scope(), _dec2 = BeanInfo({
532
+ let ScopeModuleAOpenapi = class ScopeModuleAOpenapi extends BeanScopeBase {};
533
+ ScopeModuleAOpenapi = __decorate([Scope(), BeanInfo({
502
534
  module: "a-openapi"
503
- }), _dec(_class = _dec2(_class = class ScopeModuleAOpenapi extends BeanScopeBase {}) || _class) || _class);
504
-
535
+ })], ScopeModuleAOpenapi);
505
536
  /** scope: end */
506
537
 
507
538
  export { BeanOpenapi, Main, ScopeModuleAOpenapi, ServiceOpenapi, SummerCacheJson, config, schemaRefCustomAdapter };
@@ -9,6 +9,8 @@ export declare class ServiceOpenapi extends BeanBase {
9
9
  translate(apiObj: OpenAPIObject30 | OpenAPIObject31, generateJsonScene: TypeGenerateJsonScene): void;
10
10
  private _translateSchema;
11
11
  private _translateErrorMessages;
12
+ private _translateJsxRenders;
13
+ private _translateJsxRender;
12
14
  collectRegistry(): OpenAPIRegistry;
13
15
  collectController(registry: OpenAPIRegistry, moduleName: string, controller: Constructable, actionKey?: string): void;
14
16
  private _registerControllerAction;
@@ -13,6 +13,9 @@ export interface ISchemaObjectExtensionFieldRest {
13
13
  currency?: CurrencyOptions | boolean;
14
14
  visible?: boolean;
15
15
  order?: number;
16
+ label?: string;
17
+ class?: any;
18
+ classContainer?: any;
16
19
  table?: Omit<ISchemaObjectExtensionFieldRest, 'table' | 'form'>;
17
20
  form?: Omit<ISchemaObjectExtensionFieldRest, 'table' | 'form'>;
18
21
  }
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.60",
4
+ "version": "5.0.62",
5
5
  "title": "a-openapi",
6
6
  "vonaModule": {
7
7
  "capabilities": {