vona-module-a-openapi 5.0.59 → 5.0.61

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
- import { BeanInfo, BeanBase, appResource, beanFullNameFromOnionName, cast, LocaleModuleNameSeparator, appMetadata, BeanSimple, BeanScopeBase } from 'vona';
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();
@@ -108,13 +100,16 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
108
100
  const pathObj = apiObj.paths[key];
109
101
  for (const method in pathObj) {
110
102
  const methodObj = pathObj[method];
111
- this._translateStrings(methodObj, ['description', 'summary']);
112
103
  // parameters
113
104
  for (const parameterObj of methodObj.parameters || []) {
114
- this._translateSchema(parameterObj.schema, generateJsonScene);
105
+ if (parameterObj.schema) {
106
+ parameterObj.schema = this._translateSchema(parameterObj.schema, generateJsonScene);
107
+ }
115
108
  }
116
109
  // requestBody
117
- 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
+ }
118
113
  }
119
114
  }
120
115
  }
@@ -122,12 +117,13 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
122
117
  if (apiObj.components?.schemas) {
123
118
  for (const key in apiObj.components.schemas) {
124
119
  const schema = apiObj.components.schemas[key];
125
- this._translateSchema(schema, generateJsonScene);
120
+ if (schema) {
121
+ apiObj.components.schemas[key] = this._translateSchema(schema, generateJsonScene);
122
+ }
126
123
  }
127
124
  }
128
125
  }
129
126
  _translateSchema(schema, generateJsonScene) {
130
- if (!schema) return;
131
127
  if (schema.type === 'object' && schema.required === undefined) schema.required = [];
132
128
  // serializerTransforms
133
129
  delete schema.serializerTransforms;
@@ -143,26 +139,31 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
143
139
  }
144
140
  }
145
141
  // schema
146
- this._translateStrings(schema, ['title', 'description']);
147
142
  if (generateJsonScene === 'api' && !schema.description && schema.title) {
148
143
  schema.description = schema.title;
149
144
  delete schema.title;
150
145
  }
151
146
  // errorMessage
152
147
  this._translateErrorMessages(schema);
148
+ // jsxRender
149
+ this._translateJsxRenders(schema);
153
150
  // properties
154
151
  const properties = cast(schema).properties;
155
152
  if (properties && typeof properties === 'object') {
156
153
  for (const prop in properties) {
157
154
  const propObj = properties[prop];
158
- this._translateSchema(propObj, generateJsonScene);
155
+ if (propObj) {
156
+ properties[prop] = this._translateSchema(propObj, generateJsonScene);
157
+ }
159
158
  }
160
159
  }
161
160
  // items
162
161
  const items = cast(schema).items;
163
162
  if (items && typeof items === 'object') {
164
- this._translateSchema(items, generateJsonScene);
163
+ cast(schema).items = this._translateSchema(items, generateJsonScene);
165
164
  }
165
+ // ok
166
+ return schema;
166
167
  }
167
168
  _translateErrorMessages(obj) {
168
169
  if (!obj.errorMessage) return;
@@ -181,16 +182,35 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
181
182
  }, error, scope);
182
183
  }
183
184
  }
184
- _translateStrings(obj, keys) {
185
- for (const key of keys) {
186
- this._translateString(obj, key);
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);
187
194
  }
188
195
  }
189
- _translateString(obj, key) {
190
- if (!obj) return;
191
- if (obj[key] && obj[key].includes(LocaleModuleNameSeparator)) {
192
- obj[key] = this.app.meta.text(obj[key]);
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
+ }
193
212
  }
213
+ return componentNew;
194
214
  }
195
215
  collectRegistry() {
196
216
  const registry = new OpenAPIRegistry();
@@ -243,22 +263,18 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
243
263
  _registerControllerAction(registry, info, controller, beanOptions, _controllerBeanFullName, controllerPath, controllerOpenApiOptions, actionKey, _desc) {
244
264
  // app
245
265
  const app = this.app;
246
-
247
266
  // action options: should not extend controllerOpenApiOptions
248
267
  const actionOpenApiOptions = appMetadata.getMetadata(SymbolOpenApiOptions, controller.prototype, actionKey);
249
268
  if (actionOpenApiOptions?.exclude) return;
250
-
251
269
  // actionPath/actionMethod
252
270
  if (!appMetadata.hasMetadata(SymbolRequestMappingHandler, controller.prototype, actionKey)) return;
253
271
  const handlerMetadata = appMetadata.getMetadata(SymbolRequestMappingHandler, controller.prototype, actionKey);
254
272
  const actionPath = handlerMetadata.path || '';
255
273
  const actionMethod = handlerMetadata.method || 'get';
256
-
257
274
  // routePath
258
275
  const routePath = app.util.combineApiPathControllerAndAction(info.relativeName, controllerPath, actionPath, true, true);
259
276
  // :id -> {id}
260
277
  const routePath2 = routePath.replace(/:([^/]+)/g, '{$1}');
261
-
262
278
  // tags
263
279
  let tags = actionOpenApiOptions?.tags ?? controllerOpenApiOptions?.tags;
264
280
  if (!tags || tags.length === 0) {
@@ -435,16 +451,19 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
435
451
  }
436
452
  return objHeaders;
437
453
  }
438
- }) || _class$2) || _class$2);
454
+ };
455
+ ServiceOpenapi = __decorate([Service(), BeanInfo({
456
+ module: "a-openapi"
457
+ })], ServiceOpenapi);
439
458
 
440
- var _dec$1, _dec2$1, _class$1;
441
- let SummerCacheJson = (_dec$1 = SummerCache({
459
+ let SummerCacheJson = class SummerCacheJson extends BeanSummerCacheBase {
460
+ async getNative(_key, _options) {}
461
+ };
462
+ SummerCacheJson = __decorate([SummerCache({
442
463
  preset: 'mem'
443
- }), _dec2$1 = BeanInfo({
464
+ }), BeanInfo({
444
465
  module: "a-openapi"
445
- }), _dec$1(_class$1 = _dec2$1(_class$1 = class SummerCacheJson extends BeanSummerCacheBase {
446
- async getNative(_key, _options) {}
447
- }) || _class$1) || _class$1);
466
+ })], SummerCacheJson);
448
467
 
449
468
  function config(_app) {
450
469
  return {
@@ -510,11 +529,10 @@ class Main extends BeanSimple {
510
529
  async configLoaded(_config) {}
511
530
  }
512
531
 
513
- var _dec, _dec2, _class;
514
- let ScopeModuleAOpenapi = (_dec = Scope(), _dec2 = BeanInfo({
532
+ let ScopeModuleAOpenapi = class ScopeModuleAOpenapi extends BeanScopeBase {};
533
+ ScopeModuleAOpenapi = __decorate([Scope(), BeanInfo({
515
534
  module: "a-openapi"
516
- }), _dec(_class = _dec2(_class = class ScopeModuleAOpenapi extends BeanScopeBase {}) || _class) || _class);
517
-
535
+ })], ScopeModuleAOpenapi);
518
536
  /** scope: end */
519
537
 
520
538
  export { BeanOpenapi, Main, ScopeModuleAOpenapi, ServiceOpenapi, SummerCacheJson, config, schemaRefCustomAdapter };
@@ -9,8 +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 _translateStrings;
13
- private _translateString;
12
+ private _translateJsxRenders;
13
+ private _translateJsxRender;
14
14
  collectRegistry(): OpenAPIRegistry;
15
15
  collectController(registry: OpenAPIRegistry, moduleName: string, controller: Constructable, actionKey?: string): void;
16
16
  private _registerControllerAction;
@@ -1,5 +1,6 @@
1
1
  import type { ZodOpenAPIMetadata } from '@cabloy/zod-to-openapi';
2
2
  import type { CurrencyOptions } from '@zhennann/currency';
3
+ import type { ILocaleMagic } from 'vona';
3
4
  import type { IOpenApiOptions } from 'vona-module-a-openapiutils';
4
5
  import type { z } from 'zod';
5
6
  import type { TypeResourceActionRowRecordRender } from './actions.ts';
@@ -30,7 +31,10 @@ declare module 'openapi3-ts/oas31' {
30
31
  export type TypeFieldRenderComponent = (keyof IComponentRecord) | (keyof TypeResourceActionRowRecordRender) | 'text' | 'textarea' | 'select' | 'checkbox' | 'radio' | 'switch' | 'image' | 'file' | 'color' | 'password' | 'email' | 'url';
31
32
  export type TypeFieldRenderComponentProvider = (keyof IComponentRecord) | (keyof TypeResourceActionRowRecordRender) | 'input' | 'textarea' | 'select';
32
33
  export type TypeSchemaScene = 'table' | 'form';
33
- export type TypeOpenapiMetadata<T extends z.ZodType = z.ZodType> = Partial<ZodOpenAPIMetadata<z.input<T>>>;
34
+ export type TypeOpenapiMetadata<T extends z.ZodType = z.ZodType> = Omit<Partial<ZodOpenAPIMetadata<z.input<T>>>, 'title' | 'description'> & {
35
+ title?: string | ILocaleMagic;
36
+ description?: string | ILocaleMagic;
37
+ };
34
38
  export type TypeEntityOptionsFields<T extends {}, More extends string | undefined = never> = {
35
39
  [key in ((keyof T) | (More extends string ? More : never))]?: TypeOpenapiMetadata | z.ZodType;
36
40
  };
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.59",
4
+ "version": "5.0.61",
5
5
  "title": "a-openapi",
6
6
  "vonaModule": {
7
7
  "capabilities": {
@@ -35,9 +35,9 @@
35
35
  "dist"
36
36
  ],
37
37
  "dependencies": {
38
- "@cabloy/zod-openapi": "^1.0.7",
38
+ "@cabloy/zod-openapi": "^1.0.8",
39
39
  "@cabloy/zod-query": "^2.0.4",
40
- "@cabloy/zod-to-openapi": "^8.1.4",
40
+ "@cabloy/zod-to-openapi": "^8.1.5",
41
41
  "@zhennann/currency": "^2.0.0",
42
42
  "openapi3-ts": "^4.5.0",
43
43
  "zod": "^4.1.13"