@takeshape/json-schema 11.64.0 → 11.69.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.
|
@@ -262,7 +262,7 @@ describe('SchemaConverter', () => {
|
|
|
262
262
|
expect(result.stats).toEqual({ propertiesCount: 1, stringLength: 4695, enumValuesCount: 600 });
|
|
263
263
|
expect(result.warnings.length).toEqual(0);
|
|
264
264
|
});
|
|
265
|
-
test('removes keys
|
|
265
|
+
test('removes keys not included in propertyKeys', () => {
|
|
266
266
|
const exampleSchema = {
|
|
267
267
|
type: 'object',
|
|
268
268
|
properties: {
|
|
@@ -274,7 +274,7 @@ describe('SchemaConverter', () => {
|
|
|
274
274
|
};
|
|
275
275
|
const result = SchemaConverter.convert(exampleSchema, {
|
|
276
276
|
target: SchemaConversionTarget.JSONSchema,
|
|
277
|
-
|
|
277
|
+
propertyFilter: (key) => key === 'id' || key === 'name'
|
|
278
278
|
});
|
|
279
279
|
expect(result.schema).toEqual({
|
|
280
280
|
properties: {
|
|
@@ -408,7 +408,7 @@ describe('SchemaConverter', () => {
|
|
|
408
408
|
const result = SchemaConverter.convert(searchShapeSchemaJson, {
|
|
409
409
|
target: SchemaConversionTarget.JSONSchema,
|
|
410
410
|
inlineDefinitions: false,
|
|
411
|
-
|
|
411
|
+
propertyFilter: (key) => !key.startsWith('_') && key !== 'where'
|
|
412
412
|
});
|
|
413
413
|
expect(result.stats).toEqual({ propertiesCount: 10, stringLength: 87, enumValuesCount: 0 });
|
|
414
414
|
expect(result.warnings).toEqual([]);
|
|
@@ -882,7 +882,7 @@ describe('SchemaConverter', () => {
|
|
|
882
882
|
};
|
|
883
883
|
const result = SchemaConverter.convert(exampleSchema, {
|
|
884
884
|
target: SchemaConversionTarget.OpenAI,
|
|
885
|
-
|
|
885
|
+
propertyFilter: (key) => key === 'id' || key === 'name'
|
|
886
886
|
});
|
|
887
887
|
expect(result.schema).toEqual({
|
|
888
888
|
additionalProperties: false,
|
|
@@ -1043,7 +1043,7 @@ describe('SchemaConverter', () => {
|
|
|
1043
1043
|
const result = SchemaConverter.convert(searchShapeSchemaJson, {
|
|
1044
1044
|
target: SchemaConversionTarget.OpenAI,
|
|
1045
1045
|
inlineDefinitions: false,
|
|
1046
|
-
|
|
1046
|
+
propertyFilter: (key) => !key.startsWith('_') && key !== 'where'
|
|
1047
1047
|
});
|
|
1048
1048
|
expect(result.stats).toEqual({ propertiesCount: 10, stringLength: 87, enumValuesCount: 0 });
|
|
1049
1049
|
expect(result.warnings).toEqual([]);
|
|
@@ -19,9 +19,9 @@ export type SchemaConversionOptions = {
|
|
|
19
19
|
*/
|
|
20
20
|
target?: SchemaConversionTarget;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Keys to include
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
propertyFilter?: (key: string) => boolean;
|
|
25
25
|
/**
|
|
26
26
|
* @default false
|
|
27
27
|
*/
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { assert, ensureArray } from '@takeshape/util';
|
|
2
2
|
import intersection from 'lodash/intersection.js';
|
|
3
3
|
import uniq from 'lodash/uniq.js';
|
|
4
|
-
import { Minimatch } from 'minimatch';
|
|
5
4
|
import { getReferenceMap, isAllOfSchema, isAnyOfSchema, isArraySchema, isEnumSchema, isListSchema, isObjectSchema, isOneOfSchema, isPropertySchema, isRefSchema, isTupleSchema, pickJSONSchema7 } from "../utils/index.js";
|
|
6
5
|
export var SchemaConversionTarget;
|
|
7
6
|
(function (SchemaConversionTarget) {
|
|
@@ -30,12 +29,12 @@ export class SchemaConverter {
|
|
|
30
29
|
return new SchemaConverter(schema, options).run();
|
|
31
30
|
}
|
|
32
31
|
constructor(originalSchema, options = {}) {
|
|
33
|
-
const {
|
|
32
|
+
const { propertyFilter, target = SchemaConversionTarget.JSONSchema, inlineDefinitions = false, maxDepth = 5, allowUnknownKeys = false } = options;
|
|
34
33
|
this.#config = {
|
|
35
34
|
target,
|
|
36
35
|
maxDepth,
|
|
37
36
|
allowUnknownKeys,
|
|
38
|
-
|
|
37
|
+
propertyFilter,
|
|
39
38
|
inlineDefinitions
|
|
40
39
|
};
|
|
41
40
|
const { $defs, definitions, ...schema } = originalSchema;
|
|
@@ -280,7 +279,7 @@ export class SchemaConverter {
|
|
|
280
279
|
}
|
|
281
280
|
processObjectSchema(context, schema) {
|
|
282
281
|
const { depth, path, processingMode } = context;
|
|
283
|
-
const { target,
|
|
282
|
+
const { target, propertyFilter } = this.#config;
|
|
284
283
|
const newSchema = this.initializeNewSchema(schema, {
|
|
285
284
|
type: 'object'
|
|
286
285
|
});
|
|
@@ -290,8 +289,8 @@ export class SchemaConverter {
|
|
|
290
289
|
if (schema.properties) {
|
|
291
290
|
// Process each property
|
|
292
291
|
for (const [key, property] of Object.entries(schema.properties)) {
|
|
293
|
-
// Skip properties that
|
|
294
|
-
if (
|
|
292
|
+
// Skip properties that are not in propertyKeys
|
|
293
|
+
if (propertyFilter && !propertyFilter(key)) {
|
|
295
294
|
continue;
|
|
296
295
|
}
|
|
297
296
|
newSchemaProperties[key] = this.processSchema({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/json-schema",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.69.0",
|
|
4
4
|
"description": "JSON Schema validator",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"ajv-formats": "3.0.1",
|
|
39
39
|
"lodash": "^4.17.21",
|
|
40
40
|
"minimatch": "^3.0.4",
|
|
41
|
-
"@takeshape/util": "11.
|
|
41
|
+
"@takeshape/util": "11.69.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/json-schema": "^7.0.7",
|