UNPKG

@redocly/ajv

Version:

Another JSON Schema Validator

23 lines (18 loc) 615 B
import type {CodeKeywordDefinition, KeywordErrorDefinition} from "../../types" import type {KeywordCxt} from "../../compile/validate" import {_, str} from "../../compile/codegen" import N from "../../compile/names" const error: KeywordErrorDefinition = { message: () => str`must NOT be present in response context`, } const def: CodeKeywordDefinition = { keyword: "writeOnly", schemaType: "boolean", error, code(cxt: KeywordCxt) { if (cxt.schema !== true) return const apiContext = _`(${N.this} && ${N.this}.apiContext)` cxt.fail(_`${apiContext} === "response"`) }, } export default def