@tsofist/schema-forge 1.33.0 → 1.34.0
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/lib/generator/types-generator.js +13 -2
- package/lib/generator.spec.js +35 -0
- package/lib/validator.d.ts +16 -1
- package/package.json +6 -6
|
@@ -162,7 +162,7 @@ function processAPIInterfaceDeclaration(statement, context) {
|
|
|
162
162
|
const interfaceDesc = (0, tsc_1.readJSDocDescription)(statement, allowUseFallbackDescription);
|
|
163
163
|
const interfaceDeprecated = (0, typescript_1.getTextOfJSDocComment)((0, typescript_1.getJSDocDeprecatedTag)(statement)?.comment);
|
|
164
164
|
function onSignature(method, memberName, memberDescription, deprecated) {
|
|
165
|
-
const minArgsNum = method.parameters
|
|
165
|
+
const minArgsNum = countRequiredParams(method.parameters);
|
|
166
166
|
const maxArgsNum = method.parameters.length;
|
|
167
167
|
const argsNames = [];
|
|
168
168
|
const argsTypesText = method.parameters
|
|
@@ -199,7 +199,7 @@ function processAPIInterfaceDeclaration(statement, context) {
|
|
|
199
199
|
` * @description Arguments for ${comment} ${argsNames.length ? `(${argsNamesText})` : ''}`,
|
|
200
200
|
` * @comment ${comment}`,
|
|
201
201
|
` *`,
|
|
202
|
-
|
|
202
|
+
` * @minItems ${minArgsNum}`,
|
|
203
203
|
` * @maxItems ${maxArgsNum}`,
|
|
204
204
|
` */`,
|
|
205
205
|
`export type ${definitionNameArgs} = readonly [\n${argsTypesText}\n];`,
|
|
@@ -290,3 +290,14 @@ function processAPIInterfaceDeclaration(statement, context) {
|
|
|
290
290
|
context.fileContent.push(interfaceText.stringify('\n'));
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
|
+
function countRequiredParams(params) {
|
|
294
|
+
let result = 0;
|
|
295
|
+
for (const param of params) {
|
|
296
|
+
if (param.questionToken != null)
|
|
297
|
+
break;
|
|
298
|
+
if (param.dotDotDotToken != null)
|
|
299
|
+
(0, error_1.raise)('Rest arguments are not supported yet');
|
|
300
|
+
result++;
|
|
301
|
+
}
|
|
302
|
+
return result;
|
|
303
|
+
}
|
package/lib/generator.spec.js
CHANGED
|
@@ -276,6 +276,38 @@ describe('generator for a3', () => {
|
|
|
276
276
|
expect(props.propWithGeneric).toBeTruthy();
|
|
277
277
|
expect(props.propWithGeneric.$ref).toStrictEqual('#/definitions/NonEmptyString');
|
|
278
278
|
});
|
|
279
|
+
it('optional args in API methods should works', () => {
|
|
280
|
+
{
|
|
281
|
+
const props = forgeSchemaResult.schema.definitions?.API_methodG0_Args;
|
|
282
|
+
expect(props).toBeTruthy();
|
|
283
|
+
expect(props.minItems).toStrictEqual(0);
|
|
284
|
+
expect(props.maxItems).toStrictEqual(1);
|
|
285
|
+
}
|
|
286
|
+
{
|
|
287
|
+
const props = forgeSchemaResult.schema.definitions?.API_methodG1_Args;
|
|
288
|
+
expect(props).toBeTruthy();
|
|
289
|
+
expect(props.minItems).toStrictEqual(0);
|
|
290
|
+
expect(props.maxItems).toStrictEqual(2);
|
|
291
|
+
}
|
|
292
|
+
{
|
|
293
|
+
const props = forgeSchemaResult.schema.definitions?.API_methodG2_Args;
|
|
294
|
+
expect(props).toBeTruthy();
|
|
295
|
+
expect(props.minItems).toStrictEqual(1);
|
|
296
|
+
expect(props.maxItems).toStrictEqual(2);
|
|
297
|
+
}
|
|
298
|
+
// {
|
|
299
|
+
// const props = forgeSchemaResult!.schema.definitions?.API_methodG3_Args;
|
|
300
|
+
// expect(props).toBeTruthy();
|
|
301
|
+
// expect(props.minItems).toStrictEqual(0);
|
|
302
|
+
// expect(props.maxItems).toBeUndefined();
|
|
303
|
+
// }
|
|
304
|
+
// {
|
|
305
|
+
// const props = forgeSchemaResult!.schema.definitions?.API_methodG4_Args;
|
|
306
|
+
// expect(props).toBeTruthy();
|
|
307
|
+
// expect(props.minItems).toStrictEqual(1);
|
|
308
|
+
// expect(props.maxItems).toBeUndefined();
|
|
309
|
+
// }
|
|
310
|
+
});
|
|
279
311
|
it('extends should works', () => {
|
|
280
312
|
const props = forgeSchemaResult.schema.definitions?.BAPI_InterfaceDeclaration.properties;
|
|
281
313
|
expect(props).toBeTruthy();
|
|
@@ -290,6 +322,9 @@ describe('generator for a3', () => {
|
|
|
290
322
|
'methodE1',
|
|
291
323
|
'methodE2',
|
|
292
324
|
'methodF',
|
|
325
|
+
'methodG0',
|
|
326
|
+
'methodG1',
|
|
327
|
+
'methodG2',
|
|
293
328
|
'methodY',
|
|
294
329
|
]);
|
|
295
330
|
});
|
package/lib/validator.d.ts
CHANGED
|
@@ -4,7 +4,22 @@ import { SchemaDefinitionInfo, SchemaForgeDefinitionRef, SchemaForgeValidationCo
|
|
|
4
4
|
export type SchemaForgeValidator = ReturnType<typeof createSchemaForgeValidator>;
|
|
5
5
|
export declare function createSchemaForgeValidator(engineOptions?: Options, useAdditionalFormats?: boolean): {
|
|
6
6
|
readonly rev: number;
|
|
7
|
-
clone: (options?: Omit<Options, "schemas">, onSchema?: (value: SchemaObject) => SchemaObject) =>
|
|
7
|
+
clone: (options?: Omit<Options, "schemas">, onSchema?: (value: SchemaObject) => SchemaObject) => {
|
|
8
|
+
readonly rev: number;
|
|
9
|
+
clone: /*elided*/ any;
|
|
10
|
+
removeSchema: (schemaIdentity?: AnySchema | SchemaForgeDefinitionRef | RegExp) => void;
|
|
11
|
+
hasValidator: (ref: SchemaForgeDefinitionRef) => boolean;
|
|
12
|
+
getValidator: <TData = unknown>(ref: SchemaForgeDefinitionRef | AnySchema) => SchemaForgeValidationFunction<TData> | undefined;
|
|
13
|
+
getSchema: (ref: SchemaForgeDefinitionRef) => AnySchema | undefined;
|
|
14
|
+
getRootSchema: (schemaId: string) => (SchemaObject & {
|
|
15
|
+
definitions?: AnySchema;
|
|
16
|
+
}) | undefined;
|
|
17
|
+
addSchema: (schema: Schema[]) => void;
|
|
18
|
+
validateBySchema: (ref: SchemaForgeDefinitionRef, data: unknown, instancePath?: string) => SchemaForgeValidationResult;
|
|
19
|
+
checkBySchema: <T = unknown, Ctx extends SchemaForgeValidationContextBase = SchemaForgeValidationContextBase>(ref: SchemaForgeDefinitionRef, data: unknown, context?: Ctx) => data is T;
|
|
20
|
+
validationErrorsText: (errors: Nullable<SchemaForgeValidationReport>, options?: ErrorsTextOptions) => string;
|
|
21
|
+
listDefinitions: (predicate?: (info: SchemaDefinitionInfo) => boolean) => SchemaDefinitionInfo[];
|
|
22
|
+
};
|
|
8
23
|
removeSchema: (schemaIdentity?: AnySchema | SchemaForgeDefinitionRef | RegExp) => void;
|
|
9
24
|
hasValidator: (ref: SchemaForgeDefinitionRef) => boolean;
|
|
10
25
|
getValidator: <TData = unknown>(ref: SchemaForgeDefinitionRef | AnySchema) => SchemaForgeValidationFunction<TData> | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsofist/schema-forge",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.34.0",
|
|
4
4
|
"description": "Generate JSON schema from TypeScript types",
|
|
5
5
|
"author": "Andrew Berdnikov <tsofistgudmen@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"test:watch": "jest --watch"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@faker-js/faker": "^9.
|
|
24
|
-
"@tsofist/stem": "^1.
|
|
23
|
+
"@faker-js/faker": "^9.3.0",
|
|
24
|
+
"@tsofist/stem": "^1.45.1",
|
|
25
25
|
"ajv": "^8.17.1",
|
|
26
26
|
"ajv-formats": "^3.0.1",
|
|
27
27
|
"json-schema-faker": "^0.5.8",
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
"tslib": "^2.8.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tsofist/web-buddy": "^1.
|
|
32
|
+
"@tsofist/web-buddy": "^1.21.0",
|
|
33
33
|
"@types/jest": "^29.5.14",
|
|
34
|
-
"@types/node": "^20.17.
|
|
34
|
+
"@types/node": "^20.17.10",
|
|
35
35
|
"@types/supertest": "^6.0.2",
|
|
36
36
|
"jest": "^29.7.0",
|
|
37
37
|
"rimraf": "^6.0.1",
|
|
38
38
|
"supertest": "^7.0.0",
|
|
39
39
|
"ts-jest": "^29.2.5",
|
|
40
|
-
"typescript": "~5.
|
|
40
|
+
"typescript": "~5.7.2"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"registry": "https://registry.npmjs.org/",
|