allRequired.ts 469 B

123456789101112131415161718
  1. import type {MacroKeywordDefinition} from "ajv"
  2. export default function getDef(): MacroKeywordDefinition {
  3. return {
  4. keyword: "allRequired",
  5. type: "object",
  6. schemaType: "boolean",
  7. macro(schema: boolean, parentSchema) {
  8. if (!schema) return true
  9. const required = Object.keys(parentSchema.properties)
  10. if (required.length === 0) return true
  11. return {required}
  12. },
  13. dependencies: ["properties"],
  14. }
  15. }
  16. module.exports = getDef