vona-module-a-openapi 5.0.27 → 5.0.29
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 +34 -2
- package/dist/service/openapi.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { registerMappedClassMetadataKey, appMetadata, appResource, cast, deepExtend, BeanInfo, BeanBase, LocaleModuleNameSeparator, HttpStatus, BeanSimple, BeanScopeBase } from 'vona';
|
|
1
|
+
import { registerMappedClassMetadataKey, appMetadata, appResource, cast, deepExtend, BeanInfo, BeanBase, LocaleModuleNameSeparator, HttpStatus, BeanSimple, BeanScopeBase, useApp } from 'vona';
|
|
2
2
|
import { OpenApiGeneratorV3, OpenApiGeneratorV31, OpenAPIRegistry } from '@asteasolutions/zod-to-openapi';
|
|
3
3
|
import * as ModuleInfo from '@cabloy/module-info';
|
|
4
4
|
import { isClass, isEmptyObject, isNil } from '@cabloy/utils';
|
|
@@ -200,6 +200,30 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
|
|
|
200
200
|
this._translate(apiObj, 'rest');
|
|
201
201
|
return apiObj;
|
|
202
202
|
}
|
|
203
|
+
|
|
204
|
+
// need not cache
|
|
205
|
+
async generateJsonOfClass(schemaClass, version = 'V31') {
|
|
206
|
+
return await this.generateJsonOfClasses([schemaClass], version);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// need not cache
|
|
210
|
+
async generateJsonOfClasses(schemaClasses, version = 'V31') {
|
|
211
|
+
const registry = new OpenAPIRegistry();
|
|
212
|
+
// schema: independent
|
|
213
|
+
let counter = 0;
|
|
214
|
+
for (const schemaClass of schemaClasses) {
|
|
215
|
+
const schema = $schema(schemaClass);
|
|
216
|
+
let beanFullName = appResource.getBeanFullName(schemaClass);
|
|
217
|
+
if (!beanFullName) {
|
|
218
|
+
beanFullName = `${schemaClass.name}_${counter++}`;
|
|
219
|
+
}
|
|
220
|
+
registry.register(beanFullName, schema);
|
|
221
|
+
}
|
|
222
|
+
const generator = version === 'V30' ? new OpenApiGeneratorV3(registry.definitions) : new OpenApiGeneratorV31(registry.definitions);
|
|
223
|
+
const apiObj = generator.generateDocument(this.scope.config.generateDocument[version]);
|
|
224
|
+
this._translate(apiObj, 'rest');
|
|
225
|
+
return apiObj;
|
|
226
|
+
}
|
|
203
227
|
_translate(apiObj, generateJsonScene) {
|
|
204
228
|
// paths
|
|
205
229
|
if (apiObj.paths) {
|
|
@@ -813,8 +837,16 @@ function schemaMax(max, message) {
|
|
|
813
837
|
};
|
|
814
838
|
}
|
|
815
839
|
function schemaTableIdentity() {
|
|
840
|
+
const app = useApp();
|
|
841
|
+
const ormConfig = app.util.getModuleConfigRaw('a-orm');
|
|
842
|
+
const _identityType = ormConfig?.table.identityType ?? 'string';
|
|
816
843
|
return function (_schema) {
|
|
817
|
-
|
|
844
|
+
if (_identityType === 'string') {
|
|
845
|
+
return z.string();
|
|
846
|
+
} else if (_identityType === 'number') {
|
|
847
|
+
return z.number();
|
|
848
|
+
}
|
|
849
|
+
throw new Error('not support');
|
|
818
850
|
};
|
|
819
851
|
}
|
|
820
852
|
function schemaBigNumber() {
|
|
@@ -6,6 +6,8 @@ export declare class ServiceOpenapi extends BeanBase {
|
|
|
6
6
|
protected generateJsonOfControllerActionCacheKey(args: any[], prop: string): string;
|
|
7
7
|
generateJson<K extends keyof IOpenapiObject>(version?: K): Promise<IOpenapiObject[K]>;
|
|
8
8
|
generateJsonOfControllerAction<K extends keyof IOpenapiObject>(controller: Constructable, actionKey: string, version?: K): Promise<IOpenapiObject[K]>;
|
|
9
|
+
generateJsonOfClass<K extends keyof IOpenapiObject>(schemaClass: Constructable, version?: K): Promise<IOpenapiObject[K]>;
|
|
10
|
+
generateJsonOfClasses<K extends keyof IOpenapiObject>(schemaClasses: Constructable[], version?: K): Promise<IOpenapiObject[K]>;
|
|
9
11
|
private _translate;
|
|
10
12
|
private _translateSchema;
|
|
11
13
|
private _translateStrings;
|