How to use the @loopback/repository.ModelMetadataHelper.getModelMetadata function in @loopback/repository

To help you get started, we’ve selected a few @loopback/repository examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strongloop / loopback-next / packages / repository-json-schema / src / build-schema.ts View on Github external
jsonSchemaOptions: JsonSchemaOptions = {},
): JSONSchema {
  const options = {...jsonSchemaOptions};
  options.visited = options.visited ?? {};
  options.optional = options.optional ?? [];
  const partial = options.partial && !options.optional.length;

  if (options.partial && !partial) {
    debug('Overriding "partial" option with "optional" option');
    delete options.partial;
  }

  debug('Creating schema for model %s', ctor.name);
  debug('JSON schema options: %o', options);

  const meta: ModelDefinition | {} = ModelMetadataHelper.getModelMetadata(ctor);

  // returns an empty object if metadata is an empty object
  if (!(meta instanceof ModelDefinition)) {
    return {};
  }

  debug('Model settings', meta.settings);

  const title = buildSchemaTitle(ctor, meta, options);

  if (options.visited[title]) return options.visited[title];

  const result: JSONSchema = {title};
  options.visited[title] = result;

  const descriptionSuffix = getDescriptionSuffix(options);