@takeshape/json-schema 11.52.0 → 11.55.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/dist/__tests__/schema-validator.test.d.ts +1 -0
- package/dist/__tests__/schema-validator.test.js +295 -0
- package/dist/converters/__tests__/schema-converter.test.d.ts +1 -0
- package/dist/converters/__tests__/schema-converter.test.js +1134 -0
- package/dist/converters/__tests__/search-shape-schema.json +495 -0
- package/dist/converters/index.d.ts +1 -2
- package/dist/converters/index.js +1 -16
- package/dist/converters/schema-converter.d.ts +0 -1
- package/dist/converters/schema-converter.js +540 -643
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -16
- package/dist/schema-validator.d.ts +1 -2
- package/dist/schema-validator.js +163 -189
- package/dist/utils/__tests__/references.test.d.ts +1 -0
- package/dist/utils/__tests__/references.test.js +121 -0
- package/dist/utils/__tests__/type-utils.test.d.ts +1 -0
- package/dist/utils/__tests__/type-utils.test.js +143 -0
- package/dist/utils/constants.d.ts +0 -1
- package/dist/utils/constants.js +49 -7
- package/dist/utils/index.d.ts +4 -5
- package/dist/utils/index.js +4 -49
- package/dist/utils/keys.d.ts +0 -1
- package/dist/utils/keys.js +5 -12
- package/dist/utils/references.d.ts +0 -1
- package/dist/utils/references.js +56 -57
- package/dist/utils/type-utils.d.ts +1 -2
- package/dist/utils/type-utils.js +36 -53
- package/dist/utils/types.d.ts +0 -1
- package/dist/utils/types.js +1 -5
- package/package.json +18 -25
- package/dist/converters/index.d.ts.map +0 -1
- package/dist/converters/schema-converter.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/schema-validator.d.ts.map +0 -1
- package/dist/utils/constants.d.ts.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/keys.d.ts.map +0 -1
- package/dist/utils/references.d.ts.map +0 -1
- package/dist/utils/type-utils.d.ts.map +0 -1
- package/dist/utils/types.d.ts.map +0 -1
- package/es/converters/index.js +0 -1
- package/es/converters/schema-converter.js +0 -654
- package/es/index.js +0 -1
- package/es/schema-validator.js +0 -207
- package/es/utils/constants.js +0 -1
- package/es/utils/index.js +0 -4
- package/es/utils/keys.js +0 -9
- package/es/utils/references.js +0 -66
- package/es/utils/type-utils.js +0 -36
- package/es/utils/types.js +0 -1
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { isAllOfSchema, isAnyOfSchema, isArraySchema, isEnumSchema, isListSchema, isObjectSchema, isOneOfSchema, isPropertySchema, isRefSchema, isSchema, isTupleSchema, isUnionSchema } from "../type-utils.js";
|
|
3
|
+
describe('isSchema', () => {
|
|
4
|
+
it('should return true for valid JSONSchema7', () => {
|
|
5
|
+
const schema = { type: 'object' };
|
|
6
|
+
expect(isSchema(schema)).toBe(true);
|
|
7
|
+
});
|
|
8
|
+
it('should return false for boolean schema', () => {
|
|
9
|
+
const schema = false;
|
|
10
|
+
expect(isSchema(schema)).toBe(false);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
describe('isOneOfSchema', () => {
|
|
14
|
+
it('should return true for oneOf schema', () => {
|
|
15
|
+
const schema = { oneOf: [{ type: 'string' }] };
|
|
16
|
+
expect(isOneOfSchema(schema)).toBe(true);
|
|
17
|
+
});
|
|
18
|
+
it('should return false for non-oneOf schema', () => {
|
|
19
|
+
const schema = { type: 'string' };
|
|
20
|
+
expect(isOneOfSchema(schema)).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
describe('isAnyOfSchema', () => {
|
|
24
|
+
it('should return true for anyOf schema', () => {
|
|
25
|
+
const schema = { anyOf: [{ type: 'string' }] };
|
|
26
|
+
expect(isAnyOfSchema(schema)).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
it('should return false for non-anyOf schema', () => {
|
|
29
|
+
const schema = { type: 'string' };
|
|
30
|
+
expect(isAnyOfSchema(schema)).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe('isAllOfSchema', () => {
|
|
34
|
+
it('should return true for allOf schema', () => {
|
|
35
|
+
const schema = { allOf: [{ type: 'string' }] };
|
|
36
|
+
expect(isAllOfSchema(schema)).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
it('should return false for non-allOf schema', () => {
|
|
39
|
+
const schema = { type: 'string' };
|
|
40
|
+
expect(isAllOfSchema(schema)).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('isUnionSchema', () => {
|
|
44
|
+
it('should return true for allOf/anyOf/oneOf schema', () => {
|
|
45
|
+
expect(isUnionSchema({ allOf: [{ type: 'string' }] })).toBe(true);
|
|
46
|
+
expect(isUnionSchema({ anyOf: [{ type: 'string' }] })).toBe(true);
|
|
47
|
+
expect(isUnionSchema({ oneOf: [{ type: 'string' }] })).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
it('should return false for non-allOf/anyOf/oneOf schema', () => {
|
|
50
|
+
const schema = { type: 'string' };
|
|
51
|
+
expect(isUnionSchema(schema)).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe('isObjectSchema', () => {
|
|
55
|
+
it('should return true for object schema', () => {
|
|
56
|
+
const schema = { type: 'object' };
|
|
57
|
+
expect(isObjectSchema(schema)).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
it('should return false for non-object schema', () => {
|
|
60
|
+
const schema = { type: 'string' };
|
|
61
|
+
expect(isObjectSchema(schema)).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe('isPropertySchema', () => {
|
|
65
|
+
it('should return true for an object schema with properties', () => {
|
|
66
|
+
const schema = { type: 'object', properties: {} };
|
|
67
|
+
expect(isPropertySchema(schema)).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
it('should return false for non-property schema', () => {
|
|
70
|
+
const schema = { type: 'object' };
|
|
71
|
+
expect(isPropertySchema(schema)).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
describe('isRefSchema', () => {
|
|
75
|
+
it('should return true for a schema with $ref', () => {
|
|
76
|
+
const schema = { $ref: '#/definitions/definition' };
|
|
77
|
+
expect(isRefSchema(schema)).toBe(true);
|
|
78
|
+
});
|
|
79
|
+
it('should return false for non-$ref schema', () => {
|
|
80
|
+
const schema = { type: 'string' };
|
|
81
|
+
expect(isRefSchema(schema)).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
describe('isEnumSchema', () => {
|
|
85
|
+
it('should return true for a schema with enums', () => {
|
|
86
|
+
const schema = { enum: ['value1', 'value2'] };
|
|
87
|
+
expect(isEnumSchema(schema)).toBe(true);
|
|
88
|
+
});
|
|
89
|
+
it('should return false for non-enum schema', () => {
|
|
90
|
+
const schema = { type: 'string' };
|
|
91
|
+
expect(isEnumSchema(schema)).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe('isArraySchema', () => {
|
|
95
|
+
it('should return true for an array schema', () => {
|
|
96
|
+
const schema = { type: 'array' };
|
|
97
|
+
expect(isArraySchema(schema)).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
it('should return false for non-array schema', () => {
|
|
100
|
+
const schema = { type: 'string' };
|
|
101
|
+
expect(isArraySchema(schema)).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe('isListSchema', () => {
|
|
105
|
+
it('should return true for an array list schema', () => {
|
|
106
|
+
const schema = {
|
|
107
|
+
type: 'array',
|
|
108
|
+
items: { type: 'string' }
|
|
109
|
+
};
|
|
110
|
+
expect(isListSchema(schema)).toBe(true);
|
|
111
|
+
});
|
|
112
|
+
it('should return false for partial list schema', () => {
|
|
113
|
+
const schema = { type: 'array' };
|
|
114
|
+
expect(isListSchema(schema)).toBe(false);
|
|
115
|
+
});
|
|
116
|
+
it('should return false for a tuple schema', () => {
|
|
117
|
+
const schema = {
|
|
118
|
+
type: 'array',
|
|
119
|
+
items: [{ type: 'string' }]
|
|
120
|
+
};
|
|
121
|
+
expect(isListSchema(schema)).toBe(false);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
describe('isTupleSchema', () => {
|
|
125
|
+
it('should return true for tuple schema', () => {
|
|
126
|
+
const schema = {
|
|
127
|
+
type: 'array',
|
|
128
|
+
items: [{ type: 'string' }]
|
|
129
|
+
};
|
|
130
|
+
expect(isTupleSchema(schema)).toBe(true);
|
|
131
|
+
});
|
|
132
|
+
it('should return false for partial array schema', () => {
|
|
133
|
+
const schema = { type: 'array' };
|
|
134
|
+
expect(isTupleSchema(schema)).toBe(false);
|
|
135
|
+
});
|
|
136
|
+
it('should return false for an array list schema', () => {
|
|
137
|
+
const schema = {
|
|
138
|
+
type: 'array',
|
|
139
|
+
items: { type: 'string' }
|
|
140
|
+
};
|
|
141
|
+
expect(isTupleSchema(schema)).toBe(false);
|
|
142
|
+
});
|
|
143
|
+
});
|
package/dist/utils/constants.js
CHANGED
|
@@ -1,7 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export const jsonSchema7Keys = [
|
|
2
|
+
'$id',
|
|
3
|
+
'$schema',
|
|
4
|
+
'$ref',
|
|
5
|
+
'$comment',
|
|
6
|
+
'title',
|
|
7
|
+
'description',
|
|
8
|
+
'default',
|
|
9
|
+
'readOnly',
|
|
10
|
+
'writeOnly',
|
|
11
|
+
'examples',
|
|
12
|
+
'multipleOf',
|
|
13
|
+
'maximum',
|
|
14
|
+
'exclusiveMaximum',
|
|
15
|
+
'minimum',
|
|
16
|
+
'exclusiveMinimum',
|
|
17
|
+
'maxLength',
|
|
18
|
+
'minLength',
|
|
19
|
+
'pattern',
|
|
20
|
+
'additionalItems',
|
|
21
|
+
'items',
|
|
22
|
+
'maxItems',
|
|
23
|
+
'minItems',
|
|
24
|
+
'uniqueItems',
|
|
25
|
+
'contains',
|
|
26
|
+
'maxProperties',
|
|
27
|
+
'minProperties',
|
|
28
|
+
'required',
|
|
29
|
+
'properties',
|
|
30
|
+
'patternProperties',
|
|
31
|
+
'additionalProperties',
|
|
32
|
+
'dependencies',
|
|
33
|
+
'propertyNames',
|
|
34
|
+
'const',
|
|
35
|
+
'enum',
|
|
36
|
+
'type',
|
|
37
|
+
'format',
|
|
38
|
+
'contentMediaType',
|
|
39
|
+
'contentEncoding',
|
|
40
|
+
'if',
|
|
41
|
+
'then',
|
|
42
|
+
'else',
|
|
43
|
+
'allOf',
|
|
44
|
+
'anyOf',
|
|
45
|
+
'oneOf',
|
|
46
|
+
'not',
|
|
47
|
+
'definitions',
|
|
48
|
+
'$defs'
|
|
49
|
+
];
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export * from './type-utils';
|
|
2
|
-
export * from './types';
|
|
3
|
-
export * from './references';
|
|
4
|
-
export * from './keys';
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
export * from './type-utils.ts';
|
|
2
|
+
export * from './types.ts';
|
|
3
|
+
export * from './references.ts';
|
|
4
|
+
export * from './keys.ts';
|
package/dist/utils/index.js
CHANGED
|
@@ -1,49 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
var _typeUtils = require("./type-utils");
|
|
7
|
-
Object.keys(_typeUtils).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _typeUtils[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _typeUtils[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _types = require("./types");
|
|
18
|
-
Object.keys(_types).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _types[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _types[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _references = require("./references");
|
|
29
|
-
Object.keys(_references).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _references[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _references[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
var _keys = require("./keys");
|
|
40
|
-
Object.keys(_keys).forEach(function (key) {
|
|
41
|
-
if (key === "default" || key === "__esModule") return;
|
|
42
|
-
if (key in exports && exports[key] === _keys[key]) return;
|
|
43
|
-
Object.defineProperty(exports, key, {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () {
|
|
46
|
-
return _keys[key];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
1
|
+
export * from "./type-utils.js";
|
|
2
|
+
export * from "./types.js";
|
|
3
|
+
export * from "./references.js";
|
|
4
|
+
export * from "./keys.js";
|
package/dist/utils/keys.d.ts
CHANGED
package/dist/utils/keys.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.pickJSONSchema7 = pickJSONSchema7;
|
|
7
|
-
var _pick = _interopRequireDefault(require("lodash/pick"));
|
|
8
|
-
var _constants = require("./constants");
|
|
9
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
1
|
+
import pick from 'lodash/pick.js';
|
|
2
|
+
import { jsonSchema7Keys } from "./constants.js";
|
|
10
3
|
/**
|
|
11
4
|
* Picks only valid JSON Schema 7 keys from the given schema.
|
|
12
5
|
*/
|
|
13
|
-
function pickJSONSchema7(schema) {
|
|
14
|
-
|
|
15
|
-
}
|
|
6
|
+
export function pickJSONSchema7(schema) {
|
|
7
|
+
return pick(schema, jsonSchema7Keys);
|
|
8
|
+
}
|
|
@@ -3,4 +3,3 @@ import type { JSONSchema7Definition } from 'json-schema';
|
|
|
3
3
|
* Get all the definitions that are referenced by other definitions.
|
|
4
4
|
*/
|
|
5
5
|
export declare function getReferenceMap(definitions: Record<string, JSONSchema7Definition>): Map<string, Set<string>>;
|
|
6
|
-
//# sourceMappingURL=references.d.ts.map
|
package/dist/utils/references.js
CHANGED
|
@@ -1,72 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getReferenceMap = getReferenceMap;
|
|
7
|
-
var _typeUtils = require("./type-utils");
|
|
1
|
+
import { isAllOfSchema, isAnyOfSchema, isOneOfSchema, isPropertySchema, isRefSchema, isSchema } from "./type-utils.js";
|
|
8
2
|
const SCHEMA_DEFINITION_PREFIX = ['#/definitions/', '#/$defs/'];
|
|
9
3
|
function collectRef(def, key, collect) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
if (isRefSchema(def)) {
|
|
5
|
+
collect(def.$ref, key);
|
|
6
|
+
}
|
|
7
|
+
else if (isSchema(def)) {
|
|
8
|
+
collectRefs(def, key, collect);
|
|
9
|
+
}
|
|
15
10
|
}
|
|
16
11
|
function collectRefs(def, key, collect) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
if (isPropertySchema(def)) {
|
|
13
|
+
for (const d of Object.values(def.properties)) {
|
|
14
|
+
collectRef(d, key, collect);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
else if (isAllOfSchema(def)) {
|
|
18
|
+
for (const d of def.allOf) {
|
|
19
|
+
collectRef(d, key, collect);
|
|
20
|
+
}
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
else if (isAnyOfSchema(def)) {
|
|
23
|
+
for (const d of def.anyOf) {
|
|
24
|
+
collectRef(d, key, collect);
|
|
25
|
+
}
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
else if (isOneOfSchema(def)) {
|
|
28
|
+
for (const d of def.oneOf) {
|
|
29
|
+
collectRef(d, key, collect);
|
|
30
|
+
}
|
|
28
31
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
else if (Array.isArray(def.items)) {
|
|
33
|
+
for (const d of def.items) {
|
|
34
|
+
collectRef(d, key, collect);
|
|
35
|
+
}
|
|
32
36
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
else if (def.items) {
|
|
38
|
+
if (isSchema(def.items) && isRefSchema(def.items)) {
|
|
39
|
+
collect(def.items.$ref, key);
|
|
40
|
+
}
|
|
36
41
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
collect(def.items.$ref, key);
|
|
42
|
+
else if (isRefSchema(def)) {
|
|
43
|
+
collect(def.$ref, key);
|
|
40
44
|
}
|
|
41
|
-
} else if ((0, _typeUtils.isRefSchema)(def)) {
|
|
42
|
-
collect(def.$ref, key);
|
|
43
|
-
}
|
|
44
45
|
}
|
|
45
|
-
|
|
46
46
|
/**
|
|
47
47
|
* Get all the definitions that are referenced by other definitions.
|
|
48
48
|
*/
|
|
49
|
-
function getReferenceMap(definitions) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
export function getReferenceMap(definitions) {
|
|
50
|
+
const references = new Map();
|
|
51
|
+
const addToReferenceMap = (ref, key) => {
|
|
52
|
+
const refKey = ref.replace(SCHEMA_DEFINITION_PREFIX[0], '').replace(SCHEMA_DEFINITION_PREFIX[1], '');
|
|
53
|
+
const refSet = references.get(key) ?? new Set();
|
|
54
|
+
// Circular reference
|
|
55
|
+
if (key === refKey) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
refSet.add(refKey);
|
|
59
|
+
references.set(key, refSet);
|
|
60
|
+
const refDef = definitions[refKey];
|
|
61
|
+
if (refDef && isSchema(refDef)) {
|
|
62
|
+
collectRefs(refDef, key, addToReferenceMap);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
for (const [key, def] of Object.entries(definitions)) {
|
|
66
|
+
if (isSchema(def)) {
|
|
67
|
+
collectRefs(def, key, addToReferenceMap);
|
|
68
|
+
}
|
|
58
69
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const refDef = definitions[refKey];
|
|
62
|
-
if (refDef && (0, _typeUtils.isSchema)(refDef)) {
|
|
63
|
-
collectRefs(refDef, key, addToReferenceMap);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
for (const [key, def] of Object.entries(definitions)) {
|
|
67
|
-
if ((0, _typeUtils.isSchema)(def)) {
|
|
68
|
-
collectRefs(def, key, addToReferenceMap);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return references;
|
|
72
|
-
}
|
|
70
|
+
return references;
|
|
71
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JSONSchema7, JSONSchema7Definition } from 'json-schema';
|
|
2
|
-
import type { AllOfSchema, AnyOfSchema, ArraySchema, EnumSchema, ListSchema, ObjectSchema, OneOfSchema, PropertySchema, RefSchema, TupleSchema } from './types';
|
|
2
|
+
import type { AllOfSchema, AnyOfSchema, ArraySchema, EnumSchema, ListSchema, ObjectSchema, OneOfSchema, PropertySchema, RefSchema, TupleSchema } from './types.ts';
|
|
3
3
|
export declare function isSchema(schema: JSONSchema7Definition): schema is JSONSchema7;
|
|
4
4
|
export declare function isOneOfSchema(schema: JSONSchema7Definition): schema is OneOfSchema;
|
|
5
5
|
export declare function isAnyOfSchema(schema: JSONSchema7Definition): schema is AnyOfSchema;
|
|
@@ -12,4 +12,3 @@ export declare function isListSchema(schema: JSONSchema7Definition): schema is L
|
|
|
12
12
|
export declare function isTupleSchema(schema: JSONSchema7Definition): schema is TupleSchema;
|
|
13
13
|
export declare function isEnumSchema(schema: JSONSchema7Definition): schema is EnumSchema;
|
|
14
14
|
export declare function isRefSchema(schema: JSONSchema7Definition): schema is RefSchema;
|
|
15
|
-
//# sourceMappingURL=type-utils.d.ts.map
|
package/dist/utils/type-utils.js
CHANGED
|
@@ -1,53 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return isObjectSchema(schema) && typeof schema.properties === 'object';
|
|
38
|
-
}
|
|
39
|
-
function isArraySchema(schema) {
|
|
40
|
-
return isSchema(schema) && schema.type === 'array';
|
|
41
|
-
}
|
|
42
|
-
function isListSchema(schema) {
|
|
43
|
-
return isArraySchema(schema) && typeof schema.items === 'object' && !Array.isArray(schema.items);
|
|
44
|
-
}
|
|
45
|
-
function isTupleSchema(schema) {
|
|
46
|
-
return isArraySchema(schema) && Array.isArray(schema.items);
|
|
47
|
-
}
|
|
48
|
-
function isEnumSchema(schema) {
|
|
49
|
-
return Boolean(isSchema(schema) && schema.enum);
|
|
50
|
-
}
|
|
51
|
-
function isRefSchema(schema) {
|
|
52
|
-
return Boolean(isSchema(schema) && schema.$ref);
|
|
53
|
-
}
|
|
1
|
+
export function isSchema(schema) {
|
|
2
|
+
return typeof schema !== 'boolean';
|
|
3
|
+
}
|
|
4
|
+
export function isOneOfSchema(schema) {
|
|
5
|
+
return isSchema(schema) && Array.isArray(schema.oneOf);
|
|
6
|
+
}
|
|
7
|
+
export function isAnyOfSchema(schema) {
|
|
8
|
+
return isSchema(schema) && Array.isArray(schema.anyOf);
|
|
9
|
+
}
|
|
10
|
+
export function isAllOfSchema(schema) {
|
|
11
|
+
return isSchema(schema) && Array.isArray(schema.allOf);
|
|
12
|
+
}
|
|
13
|
+
export function isUnionSchema(schema) {
|
|
14
|
+
return isOneOfSchema(schema) || isAnyOfSchema(schema) || isAllOfSchema(schema);
|
|
15
|
+
}
|
|
16
|
+
export function isObjectSchema(schema) {
|
|
17
|
+
return isSchema(schema) && schema.type === 'object';
|
|
18
|
+
}
|
|
19
|
+
export function isPropertySchema(schema) {
|
|
20
|
+
return isObjectSchema(schema) && typeof schema.properties === 'object';
|
|
21
|
+
}
|
|
22
|
+
export function isArraySchema(schema) {
|
|
23
|
+
return isSchema(schema) && schema.type === 'array';
|
|
24
|
+
}
|
|
25
|
+
export function isListSchema(schema) {
|
|
26
|
+
return isArraySchema(schema) && typeof schema.items === 'object' && !Array.isArray(schema.items);
|
|
27
|
+
}
|
|
28
|
+
export function isTupleSchema(schema) {
|
|
29
|
+
return isArraySchema(schema) && Array.isArray(schema.items);
|
|
30
|
+
}
|
|
31
|
+
export function isEnumSchema(schema) {
|
|
32
|
+
return Boolean(isSchema(schema) && schema.enum);
|
|
33
|
+
}
|
|
34
|
+
export function isRefSchema(schema) {
|
|
35
|
+
return Boolean(isSchema(schema) && schema.$ref);
|
|
36
|
+
}
|
package/dist/utils/types.d.ts
CHANGED
package/dist/utils/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/json-schema",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.55.0",
|
|
4
4
|
"description": "JSON Schema validator",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -9,39 +9,36 @@
|
|
|
9
9
|
},
|
|
10
10
|
"license": "UNLICENSED",
|
|
11
11
|
"author": "asprouse",
|
|
12
|
+
"type": "module",
|
|
12
13
|
"exports": {
|
|
13
14
|
".": {
|
|
14
15
|
"types": "./dist/index.d.ts",
|
|
15
|
-
"import": "./
|
|
16
|
-
"require": "./dist/index.js",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
17
|
"default": "./dist/index.js"
|
|
18
18
|
},
|
|
19
19
|
"./converters": {
|
|
20
20
|
"types": "./dist/converters/index.d.ts",
|
|
21
|
-
"import": "./
|
|
22
|
-
"require": "./dist/converters/index.js",
|
|
21
|
+
"import": "./dist/converters/index.js",
|
|
23
22
|
"default": "./dist/converters/index.js"
|
|
24
23
|
},
|
|
25
24
|
"./utils": {
|
|
26
25
|
"types": "./dist/utils/index.d.ts",
|
|
27
|
-
"import": "./
|
|
28
|
-
"require": "./dist/utils/index.js",
|
|
26
|
+
"import": "./dist/utils/index.js",
|
|
29
27
|
"default": "./dist/utils/index.js"
|
|
30
28
|
}
|
|
31
29
|
},
|
|
32
30
|
"main": "dist/index.js",
|
|
33
|
-
"module": "
|
|
31
|
+
"module": "dist/index.js",
|
|
34
32
|
"types": "dist/index.d.ts",
|
|
35
33
|
"files": [
|
|
36
|
-
"dist"
|
|
37
|
-
"es"
|
|
34
|
+
"dist"
|
|
38
35
|
],
|
|
39
36
|
"dependencies": {
|
|
40
|
-
"ajv": "
|
|
41
|
-
"ajv-formats": "
|
|
37
|
+
"ajv": "8.13.0",
|
|
38
|
+
"ajv-formats": "3.0.1",
|
|
42
39
|
"lodash": "^4.17.21",
|
|
43
40
|
"minimatch": "^3.0.4",
|
|
44
|
-
"@takeshape/util": "11.
|
|
41
|
+
"@takeshape/util": "11.55.0"
|
|
45
42
|
},
|
|
46
43
|
"devDependencies": {
|
|
47
44
|
"@types/json-schema": "^7.0.7",
|
|
@@ -52,25 +49,21 @@
|
|
|
52
49
|
"node": ">=20"
|
|
53
50
|
},
|
|
54
51
|
"scripts": {
|
|
55
|
-
"build": "
|
|
52
|
+
"build": "tsc --build tsconfig.build.json",
|
|
56
53
|
"prebuild:ci": "pnpm clean",
|
|
57
|
-
"build:ci": "pnpm build
|
|
58
|
-
"
|
|
59
|
-
"build:es": "cross-env BABEL_MODULES=es babel src --out-dir es --extensions \".js,.ts\" --ignore '**/__tests__'",
|
|
60
|
-
"build:js": "cross-env BABEL_MODULES=commonjs babel src --out-dir dist --extensions \".js,.ts\" --ignore '**/__tests__'",
|
|
61
|
-
"build:types": "tsc --emitDeclarationOnly --project tsconfig.build.json",
|
|
62
|
-
"build:types:ci": "mkdir -p \"${GITHUB_WORKSPACE}/typecheck-results/${npm_package_name#*\\/}\" && tsc --emitDeclarationOnly --project tsconfig.build.json --pretty false | typescript-jest-junit-reporter | tee \"${GITHUB_WORKSPACE}/typecheck-results/${npm_package_name#*\\/}/typescript-results.xml\"",
|
|
63
|
-
"clean": "del-cli dist es build *.tsbuildinfo",
|
|
54
|
+
"build:ci": "pnpm build --noCheck",
|
|
55
|
+
"clean": "del-cli dist coverage *.tsbuildinfo",
|
|
64
56
|
"lint": "pnpm lint:biome && pnpm lint:eslint",
|
|
65
57
|
"lint:biome": "biome check",
|
|
66
58
|
"lint:eslint": "eslint src -c ../../eslint.config.mjs",
|
|
67
|
-
"lint:ci": "pnpm lint:ci:biome",
|
|
59
|
+
"lint:ci": "pnpm lint:ci:biome; pnpm lint:ci:eslint",
|
|
68
60
|
"lint:ci:biome": "mkdir -p \"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}\" && biome check --diagnostic-level error --reporter=junit > \"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}/biome-results.xml\"",
|
|
69
61
|
"lint:ci:eslint": "pnpm lint:eslint --quiet --format json -o \"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}/eslint-results.json\"",
|
|
70
|
-
"test": "
|
|
62
|
+
"test": "TZ=UTC vitest run",
|
|
71
63
|
"test-changed": "pnpm run test --changedSince=master",
|
|
72
|
-
"test:ci": "
|
|
64
|
+
"test:ci": "TZ=UTC vitest run --reporter=default --reporter=junit --outputFile=\"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}/vitest-results.xml\" --coverage.enabled --coverage.reportsDirectory=\"${GITHUB_WORKSPACE}/coverage/${npm_package_name#*\\/}\"",
|
|
73
65
|
"todo": "leasot 'src/**/*.{js,jsx,ts,tsx}'",
|
|
74
|
-
"typecheck": "tsc --noEmit"
|
|
66
|
+
"typecheck": "tsc --noEmit",
|
|
67
|
+
"typecheck:ci": "mkdir -p \"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}\" && tsc --noEmit --project tsconfig.build.json --pretty false | typescript-jest-junit-reporter | tee \"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}/typescript-results.xml\""
|
|
75
68
|
}
|
|
76
69
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/converters/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-converter.d.ts","sourceRoot":"","sources":["../../../src/converters/schema-converter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAA0C,MAAM,aAAa,CAAC;AA2BvF,MAAM,MAAM,qBAAqB,GAAG;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,EAAE,qBAAqB,CAAC;CAC9B,CAAC;AAEF,oBAAY,sBAAsB;IAChC,MAAM,WAAW;IACjB,UAAU,gBAAgB;CAC3B;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC;;OAEG;IACH,MAAM,CAAC,EAAE,sBAAsB,CAAC;IAChC;;OAEG;IACH,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAC;IACrC;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAeF,qBAAa,eAAe;;IACnB,QAAQ,EAAE,MAAM,EAAE,CAAM;IACxB,KAAK,EAAE,qBAAqB,CAIjC;IAeF,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,GAAE,uBAA4B;IAIzE,SAAS,aAAa,cAAc,EAAE,WAAW,EAAE,OAAO,GAAE,uBAA4B;IA4BxF,OAAO,CAAC,GAAG;IAmEX,OAAO,CAAC,aAAa;IAmFrB,OAAO,CAAC,kBAAkB;IAe1B,OAAO,CAAC,gBAAgB;IAcxB,OAAO,CAAC,kBAAkB;IAmB1B,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,WAAW;IAqBnB,OAAO,CAAC,gBAAgB;IAyBxB,OAAO,CAAC,mBAAmB;IA4C3B,OAAO,CAAC,mBAAmB;IA6D3B,OAAO,CAAC,kBAAkB;IA8C1B,OAAO,CAAC,2BAA2B;IAgBnC,OAAO,CAAC,kBAAkB;IAe1B,OAAO,CAAC,kBAAkB;IAqB1B,OAAO,CAAC,kBAAkB;IAe1B,OAAO,CAAC,gBAAgB;IA6CxB,OAAO,CAAC,iBAAiB;IAiEzB,OAAO,CAAC,wBAAwB;CAiEjC"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|