| 505 | |
| 506 | // Validate schema against its meta-schema |
| 507 | validateSchema(schema: AnySchema, throwOrLogError?: boolean): boolean | Promise<unknown> { |
| 508 | if (typeof schema == "boolean") return true |
| 509 | let $schema: string | AnySchemaObject | undefined |
| 510 | $schema = schema.$schema |
| 511 | if ($schema !== undefined && typeof $schema != "string") { |
| 512 | throw new Error("$schema must be a string") |
| 513 | } |
| 514 | $schema = $schema || this.opts.defaultMeta || this.defaultMeta() |
| 515 | if (!$schema) { |
| 516 | this.logger.warn("meta-schema not available") |
| 517 | this.errors = null |
| 518 | return true |
| 519 | } |
| 520 | const valid = this.validate($schema, schema) |
| 521 | if (!valid && throwOrLogError) { |
| 522 | const message = "schema is invalid: " + this.errorsText() |
| 523 | if (this.opts.validateSchema === "log") this.logger.error(message) |
| 524 | else throw new Error(message) |
| 525 | } |
| 526 | return valid |
| 527 | } |
| 528 | |
| 529 | // Get compiled schema by `key` or `ref`. |
| 530 | // (`key` that was passed to `addSchema` or full schema reference - `schema.$id` or resolved id) |