Last change
on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
716 bytes
|
Line | |
---|
1 | import {KeywordCxt} from "../../ajv"
|
---|
2 | import type {CodeKeywordDefinition} from "../../types"
|
---|
3 | import {alwaysValidSchema} from "../../compile/util"
|
---|
4 |
|
---|
5 | const def: CodeKeywordDefinition = {
|
---|
6 | keyword: "metadata",
|
---|
7 | schemaType: "object",
|
---|
8 | code(cxt: KeywordCxt) {
|
---|
9 | checkMetadata(cxt)
|
---|
10 | const {gen, schema, it} = cxt
|
---|
11 | if (alwaysValidSchema(it, schema)) return
|
---|
12 | const valid = gen.name("valid")
|
---|
13 | cxt.subschema({keyword: "metadata", jtdMetadata: true}, valid)
|
---|
14 | cxt.ok(valid)
|
---|
15 | },
|
---|
16 | }
|
---|
17 |
|
---|
18 | export function checkMetadata({it, keyword}: KeywordCxt, metadata?: boolean): void {
|
---|
19 | if (it.jtdMetadata !== metadata) {
|
---|
20 | throw new Error(`JTD: "${keyword}" cannot be used in this schema location`)
|
---|
21 | }
|
---|
22 | }
|
---|
23 |
|
---|
24 | export default def
|
---|
Note:
See
TracBrowser
for help on using the repository browser.