z-schema 9.0.1 → 10.0.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/README.md +123 -191
- package/cjs/index.d.ts +33 -9
- package/cjs/index.js +4799 -3984
- package/dist/errors.js +5 -0
- package/dist/format-validators.js +65 -0
- package/dist/json-schema-versions.js +5 -0
- package/dist/json-schema.js +11 -4
- package/dist/json-validation.js +151 -10
- package/dist/report.js +2 -3
- package/dist/schema-cache.js +23 -2
- package/dist/schema-compiler.js +25 -10
- package/dist/schema-validator.js +66 -45
- package/dist/schemas/draft-06-hyper-schema.json +132 -0
- package/dist/schemas/draft-06-links.json +43 -0
- package/dist/schemas/draft-06-schema.json +155 -0
- package/dist/types/errors.d.ts +4 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/json-schema-versions.d.ts +23 -0
- package/dist/types/json-schema.d.ts +5 -9
- package/dist/types/json-validation.d.ts +3 -3
- package/dist/types/report.d.ts +3 -3
- package/dist/types/schema-cache.d.ts +1 -1
- package/dist/types/schema-compiler.d.ts +1 -1
- package/dist/types/schema-validator.d.ts +1 -1
- package/dist/types/utils/what-is.d.ts +1 -0
- package/dist/types/z-schema-base.d.ts +1 -1
- package/dist/types/z-schema-options.d.ts +1 -1
- package/dist/types/z-schema-reader.d.ts +1 -1
- package/dist/types/z-schema-versions.d.ts +1 -0
- package/dist/types/z-schema.d.ts +10 -1
- package/dist/utils/schema-regex.js +4 -3
- package/dist/utils/what-is.js +4 -1
- package/dist/z-schema-base.js +4 -5
- package/dist/z-schema-options.js +3 -1
- package/dist/z-schema-versions.js +27 -0
- package/dist/z-schema.js +21 -7
- package/package.json +2 -2
- package/src/errors.ts +6 -0
- package/src/format-validators.ts +65 -0
- package/src/index.ts +2 -1
- package/src/json-schema-versions.ts +34 -0
- package/src/json-schema.ts +22 -16
- package/src/json-validation.ts +183 -13
- package/src/report.ts +5 -6
- package/src/schema-cache.ts +25 -3
- package/src/schema-compiler.ts +25 -11
- package/src/schema-validator.ts +128 -62
- package/src/schemas/draft-06-hyper-schema.json +133 -0
- package/src/schemas/draft-06-links.json +43 -0
- package/src/schemas/draft-06-schema.json +155 -0
- package/src/utils/schema-regex.ts +5 -3
- package/src/utils/what-is.ts +5 -1
- package/src/z-schema-base.ts +5 -6
- package/src/z-schema-options.ts +3 -2
- package/src/z-schema-reader.ts +1 -1
- package/src/z-schema-versions.ts +38 -0
- package/src/z-schema.ts +27 -11
- package/umd/ZSchema.js +5100 -4285
- package/umd/ZSchema.min.js +1 -1
package/README.md
CHANGED
|
@@ -1,281 +1,213 @@
|
|
|
1
|
-
# z-schema
|
|
1
|
+
# z-schema
|
|
2
|
+
|
|
3
|
+
JSON Schema validator for Node.js and browsers. Supports **draft-04** and **draft-06** (default).
|
|
2
4
|
|
|
3
5
|
[](https://www.npmjs.com/package/z-schema)
|
|
4
6
|
|
|
5
7
|
[](https://coveralls.io/github/zaggino/z-schema?branch=main)
|
|
6
8
|
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
- [What](#what)
|
|
10
|
-
- [Versions](#versions)
|
|
11
|
-
- [Getting started](#getting-started)
|
|
12
|
-
- [Usage](#usage)
|
|
13
|
-
- [Features](#features)
|
|
14
|
-
- [Options](#options)
|
|
15
|
-
- [Contributing](#contributing)
|
|
16
|
-
- [Contributors](#contributors)
|
|
17
|
-
|
|
18
|
-
## What
|
|
19
|
-
|
|
20
|
-
What is a JSON Schema? Find here: [https://json-schema.org/](https://json-schema.org/)
|
|
21
|
-
|
|
22
|
-
## Versions
|
|
9
|
+
## Install
|
|
23
10
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
- v9 - new api, `new ZSchema()` replaced by `ZSchema.create()` for initialization
|
|
11
|
+
```bash
|
|
12
|
+
npm install z-schema
|
|
13
|
+
```
|
|
28
14
|
|
|
29
|
-
|
|
15
|
+
Requires **Node.js 22** or later.
|
|
30
16
|
|
|
31
|
-
|
|
17
|
+
## Quick Start
|
|
32
18
|
|
|
33
|
-
### ESM
|
|
19
|
+
### ESM / TypeScript
|
|
34
20
|
|
|
35
21
|
```typescript
|
|
36
22
|
import ZSchema from 'z-schema';
|
|
23
|
+
|
|
37
24
|
const validator = ZSchema.create();
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
validator.validate({ name: 'Alice' }, { type: 'object', properties: { name: { type: 'string' } } });
|
|
28
|
+
console.log('Valid');
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.log('Invalid:', error.details);
|
|
31
|
+
}
|
|
38
32
|
```
|
|
39
33
|
|
|
40
|
-
###
|
|
34
|
+
### CommonJS
|
|
41
35
|
|
|
42
36
|
```javascript
|
|
43
37
|
const ZSchema = require('z-schema');
|
|
44
38
|
const validator = ZSchema.create();
|
|
45
39
|
```
|
|
46
40
|
|
|
47
|
-
### Browser
|
|
41
|
+
### Browser (UMD)
|
|
48
42
|
|
|
49
43
|
```html
|
|
50
|
-
<script
|
|
51
|
-
<script
|
|
52
|
-
|
|
44
|
+
<script src="z-schema/umd/ZSchema.min.js"></script>
|
|
45
|
+
<script>
|
|
46
|
+
const validator = ZSchema.create();
|
|
53
47
|
try {
|
|
54
|
-
validator.validate('
|
|
55
|
-
console.log('Validation passed');
|
|
48
|
+
validator.validate('hello', { type: 'string' });
|
|
56
49
|
} catch (error) {
|
|
57
|
-
console.log(
|
|
50
|
+
console.log(error.details);
|
|
58
51
|
}
|
|
59
52
|
</script>
|
|
60
53
|
```
|
|
61
54
|
|
|
62
|
-
### CLI
|
|
55
|
+
### CLI
|
|
63
56
|
|
|
64
57
|
```bash
|
|
65
58
|
npm install --global z-schema
|
|
66
|
-
z-schema --help
|
|
67
59
|
z-schema mySchema.json
|
|
68
|
-
z-schema mySchema.json
|
|
69
|
-
z-schema --strictMode mySchema.json
|
|
60
|
+
z-schema mySchema.json myData.json
|
|
61
|
+
z-schema --strictMode mySchema.json myData.json
|
|
70
62
|
```
|
|
71
63
|
|
|
72
64
|
## Usage
|
|
73
65
|
|
|
74
|
-
###
|
|
66
|
+
### Sync Validation (Throw Mode)
|
|
75
67
|
|
|
76
|
-
|
|
68
|
+
By default, `validate` throws a `ValidateError` on failure. The error has a `details` array with structured error info.
|
|
77
69
|
|
|
78
|
-
```
|
|
79
|
-
const
|
|
80
|
-
{
|
|
81
|
-
id: 'personDetails',
|
|
82
|
-
type: 'object',
|
|
83
|
-
properties: {
|
|
84
|
-
firstName: { type: 'string' },
|
|
85
|
-
lastName: { type: 'string' },
|
|
86
|
-
},
|
|
87
|
-
required: ['firstName', 'lastName'],
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
id: 'addressDetails',
|
|
91
|
-
type: 'object',
|
|
92
|
-
properties: {
|
|
93
|
-
street: { type: 'string' },
|
|
94
|
-
city: { type: 'string' },
|
|
95
|
-
},
|
|
96
|
-
required: ['street', 'city'],
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
id: 'personWithAddress',
|
|
100
|
-
allOf: [{ $ref: 'personDetails' }, { $ref: 'addressDetails' }],
|
|
101
|
-
},
|
|
102
|
-
];
|
|
70
|
+
```typescript
|
|
71
|
+
const validator = ZSchema.create();
|
|
103
72
|
|
|
104
73
|
try {
|
|
105
|
-
validator.
|
|
106
|
-
console.log('All schemas are valid and compiled');
|
|
74
|
+
validator.validate(json, schema);
|
|
107
75
|
} catch (error) {
|
|
108
|
-
console.log('
|
|
76
|
+
console.log(error.name); // 'z-schema validation error'
|
|
77
|
+
console.log(error.message); // summary message
|
|
78
|
+
console.log(error.details); // array of { code, message, path, ... }
|
|
109
79
|
}
|
|
110
80
|
```
|
|
111
81
|
|
|
112
|
-
### Sync
|
|
82
|
+
### Sync Validation (Safe Mode)
|
|
113
83
|
|
|
114
|
-
|
|
84
|
+
Use `ZSchema.create({ safe: true })` to get a result object instead of exceptions.
|
|
115
85
|
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
validator.validate(json, schema);
|
|
119
|
-
// validation passed
|
|
120
|
-
} catch (error) {
|
|
121
|
-
// this will return a native error object with name and message
|
|
122
|
-
console.log(error.name); // 'z-schema validation error'
|
|
123
|
-
console.log(error.message); // common error message
|
|
124
|
-
// this will return an array of validation errors encountered
|
|
125
|
-
console.log(error.details); // array of detailed errors
|
|
126
|
-
}
|
|
86
|
+
```typescript
|
|
87
|
+
const validator = ZSchema.create({ safe: true });
|
|
127
88
|
|
|
128
|
-
|
|
129
|
-
const result = validator.validateSafe(json, schema);
|
|
89
|
+
const result = validator.validate(json, schema);
|
|
130
90
|
if (!result.valid) {
|
|
131
|
-
console.log(result.
|
|
91
|
+
console.log(result.err); // ValidateError with .details
|
|
132
92
|
}
|
|
133
|
-
|
|
134
|
-
...
|
|
135
93
|
```
|
|
136
94
|
|
|
137
|
-
### Async
|
|
95
|
+
### Async Validation
|
|
138
96
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
- **Async validation**: User ID against a database
|
|
142
|
-
- **Async validation**: Postcode against an external service
|
|
143
|
-
- **Sync validation**: Phone number format
|
|
97
|
+
Pass `{ async: true }` to support async format validators. The `validate` method returns a Promise.
|
|
144
98
|
|
|
145
99
|
```typescript
|
|
146
|
-
|
|
147
|
-
import db from './db';
|
|
148
|
-
|
|
149
|
-
// Initialize ZSchema
|
|
150
|
-
const validator = ZSchema.create();
|
|
151
|
-
|
|
152
|
-
// Register async and sync format validators
|
|
153
|
-
validator.registerFormat('user-exists', async (input: unknown): Promise<boolean> => {
|
|
154
|
-
if (typeof input !== 'number') return false;
|
|
155
|
-
const user = await db.getUserById(input);
|
|
156
|
-
return user != null;
|
|
157
|
-
});
|
|
158
|
-
validator.registerFormat('valid-postcode', async (input: unknown): Promise<boolean> => {
|
|
159
|
-
if (typeof input !== 'string') return false;
|
|
160
|
-
const postcode = await db.getPostcode(input);
|
|
161
|
-
return postcode != null;
|
|
162
|
-
});
|
|
163
|
-
validator.registerFormat('phone-number', (input: unknown): boolean => {
|
|
164
|
-
if (typeof input !== 'string') return false;
|
|
165
|
-
const phoneRegex = /^\+?[1-9]\d{1,14}$/;
|
|
166
|
-
return phoneRegex.test(input);
|
|
167
|
-
});
|
|
100
|
+
const validator = ZSchema.create({ async: true });
|
|
168
101
|
|
|
169
|
-
// Define the JSON Schema
|
|
170
|
-
const personSchema = {
|
|
171
|
-
$schema: 'http://json-schema.org/draft-04/schema#',
|
|
172
|
-
type: 'object',
|
|
173
|
-
required: ['personId', 'address'],
|
|
174
|
-
properties: {
|
|
175
|
-
personId: {
|
|
176
|
-
type: 'number',
|
|
177
|
-
format: 'user-exists',
|
|
178
|
-
},
|
|
179
|
-
address: {
|
|
180
|
-
type: 'object',
|
|
181
|
-
required: ['postcode', 'phone'],
|
|
182
|
-
properties: {
|
|
183
|
-
postcode: {
|
|
184
|
-
type: 'string',
|
|
185
|
-
format: 'valid-postcode',
|
|
186
|
-
},
|
|
187
|
-
phone: {
|
|
188
|
-
type: 'string',
|
|
189
|
-
format: 'phone-number',
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
// Example payload
|
|
197
|
-
const payload = {
|
|
198
|
-
personId: 'user123',
|
|
199
|
-
address: {
|
|
200
|
-
postcode: 'SW1A 1AA',
|
|
201
|
-
phone: '+441234567890',
|
|
202
|
-
},
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
// Validate asynchronously
|
|
206
102
|
try {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
console.log(
|
|
210
|
-
} catch (err) {
|
|
211
|
-
console.log('❌ Validation failed:', err);
|
|
103
|
+
await validator.validate(json, schema);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.log(error.details);
|
|
212
106
|
}
|
|
213
107
|
|
|
214
|
-
//
|
|
215
|
-
const
|
|
216
|
-
const
|
|
217
|
-
if (
|
|
218
|
-
console.log(
|
|
219
|
-
} else {
|
|
220
|
-
console.log('❌ Validation failed:', res.err);
|
|
108
|
+
// Or combine with safe mode:
|
|
109
|
+
const safeValidator = ZSchema.create({ async: true, safe: true });
|
|
110
|
+
const result = await safeValidator.validate(json, schema);
|
|
111
|
+
if (!result.valid) {
|
|
112
|
+
console.log(result.err);
|
|
221
113
|
}
|
|
222
114
|
```
|
|
223
115
|
|
|
224
|
-
###
|
|
116
|
+
### Schema Compilation
|
|
225
117
|
|
|
226
|
-
|
|
227
|
-
Otherwise you'll get `UNRESOLVABLE_REFERENCE` error when trying to compile a schema.
|
|
118
|
+
Pre-compile schemas at startup to validate `$ref` references and cache compiled schemas.
|
|
228
119
|
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
120
|
+
```typescript
|
|
121
|
+
const validator = ZSchema.create();
|
|
122
|
+
|
|
123
|
+
const schemas = [
|
|
124
|
+
{ id: 'person', type: 'object', properties: { name: { type: 'string' } }, required: ['name'] },
|
|
125
|
+
{ id: 'team', type: 'object', properties: { lead: { $ref: 'person' } } },
|
|
126
|
+
];
|
|
233
127
|
|
|
234
128
|
try {
|
|
235
|
-
validator.
|
|
236
|
-
// This won't reach here due to unresolvable reference
|
|
129
|
+
validator.validateSchema(schemas);
|
|
237
130
|
} catch (error) {
|
|
238
|
-
|
|
239
|
-
console.log(error.details[0].code); // "UNRESOLVABLE_REFERENCE"
|
|
131
|
+
console.log('Schema errors:', error.details);
|
|
240
132
|
}
|
|
133
|
+
```
|
|
241
134
|
|
|
242
|
-
|
|
243
|
-
request(requiredUrl, function (error, response, body) {
|
|
135
|
+
### Custom Format Validators
|
|
244
136
|
|
|
245
|
-
|
|
137
|
+
Register custom format validators for sync or async checks.
|
|
246
138
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
// validation passed
|
|
250
|
-
} catch (error) {
|
|
251
|
-
// shouldn't happen after setting remote reference
|
|
252
|
-
}
|
|
139
|
+
```typescript
|
|
140
|
+
const validator = ZSchema.create();
|
|
253
141
|
|
|
254
|
-
|
|
142
|
+
// Sync format
|
|
143
|
+
validator.registerFormat('uppercase', (value: unknown): boolean => {
|
|
144
|
+
return typeof value === 'string' && value === value.toUpperCase();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Async format
|
|
148
|
+
validator.registerFormat('user-exists', async (value: unknown): Promise<boolean> => {
|
|
149
|
+
if (typeof value !== 'number') return false;
|
|
150
|
+
const user = await db.getUserById(value);
|
|
151
|
+
return user != null;
|
|
152
|
+
});
|
|
255
153
|
```
|
|
256
154
|
|
|
257
|
-
|
|
155
|
+
### Remote References
|
|
258
156
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
157
|
+
If your schemas reference remote URIs, register them before validation.
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
const validator = ZSchema.create();
|
|
161
|
+
|
|
162
|
+
// Register a remote schema manually
|
|
163
|
+
validator.setRemoteReference('http://example.com/person.json', personSchema);
|
|
164
|
+
|
|
165
|
+
// Or set a schema reader to load them automatically
|
|
166
|
+
ZSchema.setSchemaReader((uri: string) => {
|
|
167
|
+
const filePath = path.resolve(__dirname, 'schemas', uri + '.json');
|
|
168
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
263
169
|
});
|
|
264
170
|
```
|
|
265
171
|
|
|
172
|
+
## Version History
|
|
173
|
+
|
|
174
|
+
| Version | Changes |
|
|
175
|
+
| ------- | ------------------------------------------------------------------------------------------------- |
|
|
176
|
+
| **v10** | Default version is **draft-06**. Implemented draft-06 tests from JSON Schema Test suite. |
|
|
177
|
+
| **v9** | New factory API: `ZSchema.create()` replaces `new ZSchema()`. Default draft is **draft-06**. |
|
|
178
|
+
| **v8** | Schemas without `$schema` default to draft-04. Use `{ version: 'none' }` for the old v7 behavior. |
|
|
179
|
+
| **v7** | Rewritten in TypeScript/ESM. Passes all JSON Schema Test Suite tests for draft-04. |
|
|
180
|
+
| **v6** | Legacy version. Draft-04 support. |
|
|
181
|
+
|
|
266
182
|
## Features
|
|
267
183
|
|
|
268
|
-
See [
|
|
184
|
+
See [docs/features.md](docs/features.md) for the full feature list.
|
|
269
185
|
|
|
270
186
|
## Options
|
|
271
187
|
|
|
272
|
-
See [
|
|
188
|
+
See [docs/options.md](docs/options.md) for all constructor and per-call options.
|
|
189
|
+
|
|
190
|
+
## Documentation
|
|
191
|
+
|
|
192
|
+
| Document | Description |
|
|
193
|
+
| -------------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
194
|
+
| [docs/usage.md](docs/usage.md) | Detailed usage guide with all validation modes, error handling, and advanced features |
|
|
195
|
+
| [docs/options.md](docs/options.md) | Constructor options and per-call validation options |
|
|
196
|
+
| [docs/features.md](docs/features.md) | Feature catalog with examples |
|
|
197
|
+
| [docs/architecture.md](docs/architecture.md) | Internal architecture, module structure, and public API reference |
|
|
198
|
+
| [docs/conventions.md](docs/conventions.md) | Code style, naming, and formatting conventions |
|
|
199
|
+
| [docs/testing.md](docs/testing.md) | Test framework, running tests, and writing new tests |
|
|
200
|
+
| [docs/contributing.md](docs/contributing.md) | PR workflow and contribution guidelines |
|
|
273
201
|
|
|
274
202
|
## Contributing
|
|
275
203
|
|
|
276
|
-
|
|
204
|
+
This repository uses submodules. Clone with:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
git clone --recursive https://github.com/zaggino/z-schema.git
|
|
208
|
+
```
|
|
277
209
|
|
|
278
|
-
|
|
210
|
+
See [docs/contributing.md](docs/contributing.md) for the full contribution guide.
|
|
279
211
|
|
|
280
212
|
## Contributors
|
|
281
213
|
|
package/cjs/index.d.ts
CHANGED
|
@@ -112,9 +112,9 @@ declare class Report {
|
|
|
112
112
|
getSchemaPath(): Array<string | number>;
|
|
113
113
|
getSchemaId(): string | undefined;
|
|
114
114
|
hasError(errCode: string, errParams: Array<any>): boolean;
|
|
115
|
-
addError(errCode: ErrorCode, errParams?: ErrorParam[], subReports?: Report | Report[], schema?: JsonSchema, keyword?: keyof JsonSchema): void;
|
|
115
|
+
addError(errCode: ErrorCode, errParams?: ErrorParam[], subReports?: Report | Report[], schema?: JsonSchema | boolean, keyword?: keyof JsonSchema): void;
|
|
116
116
|
getJson(): unknown;
|
|
117
|
-
addCustomError(errorCode: ErrorCode, errorMessage: string, params?: ErrorParam[], subReports?: Report | Report[], schema?: JsonSchema, keyword?: keyof JsonSchema): void;
|
|
117
|
+
addCustomError(errorCode: ErrorCode, errorMessage: string, params?: ErrorParam[], subReports?: Report | Report[], schema?: JsonSchema | boolean, keyword?: keyof JsonSchema): void;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
type ErrorCode = keyof typeof Errors;
|
|
@@ -162,6 +162,10 @@ declare const Errors: {
|
|
|
162
162
|
ASYNC_TIMEOUT: string;
|
|
163
163
|
PARENT_SCHEMA_VALIDATION_FAILED: string;
|
|
164
164
|
REMOTE_NOT_VALID: string;
|
|
165
|
+
SCHEMA_IS_FALSE: string;
|
|
166
|
+
CONST: string;
|
|
167
|
+
CONTAINS: string;
|
|
168
|
+
PROPERTY_NAMES: string;
|
|
165
169
|
};
|
|
166
170
|
declare class ValidateError extends Error {
|
|
167
171
|
name: string;
|
|
@@ -244,11 +248,10 @@ declare class SchemaCompiler {
|
|
|
244
248
|
compileArrayOfSchemasLoop(mainReport: Report, arr: JsonSchemaInternal[]): number;
|
|
245
249
|
}
|
|
246
250
|
|
|
247
|
-
|
|
248
|
-
interface JsonSchema {
|
|
251
|
+
interface JsonSchemaCommon {
|
|
249
252
|
$ref?: string;
|
|
250
|
-
id?: string;
|
|
251
253
|
$schema?: string;
|
|
254
|
+
id?: string;
|
|
252
255
|
title?: string;
|
|
253
256
|
description?: string;
|
|
254
257
|
default?: unknown;
|
|
@@ -256,12 +259,9 @@ interface JsonSchema {
|
|
|
256
259
|
type?: string | string[];
|
|
257
260
|
properties?: Record<string, JsonSchema>;
|
|
258
261
|
patternProperties?: Record<string, JsonSchema>;
|
|
259
|
-
dependencies?: Record<string, string[]>;
|
|
260
262
|
multipleOf?: number;
|
|
261
263
|
minimum?: number;
|
|
262
|
-
exclusiveMinimum?: boolean;
|
|
263
264
|
maximum?: number;
|
|
264
|
-
exclusiveMaximum?: boolean;
|
|
265
265
|
minLength?: number;
|
|
266
266
|
maxLength?: number;
|
|
267
267
|
pattern?: string;
|
|
@@ -274,6 +274,7 @@ interface JsonSchema {
|
|
|
274
274
|
maxProperties?: number;
|
|
275
275
|
required?: string[];
|
|
276
276
|
additionalProperties?: boolean | JsonSchema;
|
|
277
|
+
dependencies?: Record<string, string[] | JsonSchema>;
|
|
277
278
|
enum?: Array<unknown>;
|
|
278
279
|
format?: string;
|
|
279
280
|
allOf?: JsonSchema[];
|
|
@@ -291,12 +292,29 @@ interface ZSchemaInternalProperties {
|
|
|
291
292
|
__$validationOptions?: ZSchemaOptions;
|
|
292
293
|
__$visited?: boolean;
|
|
293
294
|
}
|
|
294
|
-
|
|
295
|
+
|
|
296
|
+
type JsonSchemaVersion = 'draft-04' | 'draft-06';
|
|
297
|
+
type JsonSchema = JsonSchemaDraft4 | JsonSchemaDraft6;
|
|
298
|
+
type JsonSchemaInternal = JsonSchema & ZSchemaInternalProperties;
|
|
299
|
+
interface JsonSchemaDraft4 extends JsonSchemaCommon {
|
|
300
|
+
exclusiveMaximum?: boolean;
|
|
301
|
+
exclusiveMinimum?: boolean;
|
|
302
|
+
}
|
|
303
|
+
interface JsonSchemaDraft6 extends JsonSchemaCommon {
|
|
304
|
+
$id?: string;
|
|
305
|
+
examples?: unknown[];
|
|
306
|
+
const?: unknown;
|
|
307
|
+
contains?: JsonSchema;
|
|
308
|
+
propertyNames?: JsonSchema;
|
|
309
|
+
exclusiveMaximum?: number;
|
|
310
|
+
exclusiveMinimum?: number;
|
|
295
311
|
}
|
|
296
312
|
|
|
297
313
|
type SchemaReader = (uri: string) => JsonSchema;
|
|
298
314
|
|
|
299
315
|
declare class ZSchema extends ZSchemaBase {
|
|
316
|
+
/** @deprecated Use ZSchema.create() instead. */
|
|
317
|
+
private constructor();
|
|
300
318
|
static registerFormat(name: string, validatorFunction: FormatValidatorFn): void;
|
|
301
319
|
static unregisterFormat(name: string): void;
|
|
302
320
|
static getRegisteredFormats(): string[];
|
|
@@ -325,14 +343,20 @@ declare class ZSchema extends ZSchemaBase {
|
|
|
325
343
|
validateSchemaSafe(schemaOrArr: JsonSchema | JsonSchema[]): ValidateResponse;
|
|
326
344
|
}
|
|
327
345
|
declare class ZSchemaSafe extends ZSchemaBase {
|
|
346
|
+
/** @deprecated Use ZSchema.create() instead. */
|
|
347
|
+
private constructor();
|
|
328
348
|
validate(json: unknown, schema: JsonSchema | string, options?: ValidateOptions): ValidateResponse;
|
|
329
349
|
validateSchema(schemaOrArr: JsonSchema | JsonSchema[]): ValidateResponse;
|
|
330
350
|
}
|
|
331
351
|
declare class ZSchemaAsync extends ZSchemaBase {
|
|
352
|
+
/** @deprecated Use ZSchema.create() instead. */
|
|
353
|
+
private constructor();
|
|
332
354
|
validate(json: unknown, schema: JsonSchema | string, options?: ValidateOptions): Promise<true>;
|
|
333
355
|
validateSchema(schemaOrArr: JsonSchema | JsonSchema[]): true;
|
|
334
356
|
}
|
|
335
357
|
declare class ZSchemaAsyncSafe extends ZSchemaBase {
|
|
358
|
+
/** @deprecated Use ZSchema.create() instead. */
|
|
359
|
+
private constructor();
|
|
336
360
|
validate(json: unknown, schema: JsonSchema | string, options?: ValidateOptions): Promise<ValidateResponse>;
|
|
337
361
|
validateSchema(schemaOrArr: JsonSchema | JsonSchema[]): ValidateResponse;
|
|
338
362
|
}
|