source: trip-planner-front/node_modules/ajv/lib/vocabularies/jtd/metadata.ts@ fa375fe

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 
1import {KeywordCxt} from "../../ajv"
2import type {CodeKeywordDefinition} from "../../types"
3import {alwaysValidSchema} from "../../compile/util"
4
5const 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
18export 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
24export default def
Note: See TracBrowser for help on using the repository browser.