| 529 | // Get compiled schema by `key` or `ref`. |
| 530 | // (`key` that was passed to `addSchema` or full schema reference - `schema.$id` or resolved id) |
| 531 | getSchema<T = unknown>(keyRef: string): AnyValidateFunction<T> | undefined { |
| 532 | let sch |
| 533 | while (typeof (sch = getSchEnv.call(this, keyRef)) == "string") keyRef = sch |
| 534 | if (sch === undefined) { |
| 535 | const {schemaId} = this.opts |
| 536 | const root = new SchemaEnv({schema: {}, schemaId}) |
| 537 | sch = resolveSchema.call(this, root, keyRef) |
| 538 | if (!sch) return |
| 539 | this.refs[keyRef] = sch |
| 540 | } |
| 541 | return (sch.validate || this._compileSchemaEnv(sch)) as AnyValidateFunction<T> | undefined |
| 542 | } |
| 543 | |
| 544 | // Remove cached schema(s). |
| 545 | // If no parameter is passed all schemas but meta-schemas are removed. |