import {MetadataAccessor, MetadataInspector} from '@loopback/context'; import { JsonSchemaOptions, SchemaRef, getJsonSchemaRef, jsonToSchemaObject, } from '@loopback/openapi-v3'; /** * Metadata key used to set or retrieve repository JSON Schema */ export const OVERRIDE_MODEL_SCHEMA_KEY = MetadataAccessor.create< Function, ClassDecorator >('sourceloop:override-model-schema'); export function getModelSchemaRefSF( modelCtor: Function & {prototype: T}, options?: JsonSchemaOptions, ): SchemaRef { const cached = MetadataInspector.getClassMetadata( OVERRIDE_MODEL_SCHEMA_KEY, modelCtor, { ownMetadataOnly: true, }, ); const jsonSchema = getJsonSchemaRef(cached ?? modelCtor, options); return jsonToSchemaObject(jsonSchema) as SchemaRef; }