UNPKG

@redocly/ajv

Version:

Another JSON Schema Validator

26 lines 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getSkipCondition = void 0; const codegen_1 = require("../compile/codegen"); const names_1 = require("../compile/names"); function getSkipCondition(schema, prop) { var _a; const propSchema = (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[prop]; if (!propSchema) return undefined; const hasReadOnly = propSchema.readOnly === true; const hasWriteOnly = propSchema.writeOnly === true; if (!hasReadOnly && !hasWriteOnly) return undefined; const conditions = []; const apiContext = (0, codegen_1._) `typeof ${names_1.default.this} == "object" && ${names_1.default.this} && ${names_1.default.this}.apiContext`; if (hasReadOnly) { conditions.push((0, codegen_1._) `${apiContext} === "request"`); } if (hasWriteOnly) { conditions.push((0, codegen_1._) `${apiContext} === "response"`); } return (0, codegen_1.or)(...conditions); } exports.getSkipCondition = getSkipCondition; //# sourceMappingURL=oasContext.js.map