How to use @loopback/repository-json-schema - 5 common examples

To help you get started, we’ve selected a few @loopback/repository-json-schema 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 / openapi-v3 / src / controller-spec.ts View on Github external
function generateOpenAPISchema(spec: ControllerSpec, tsType: Function) {
  if (!spec.components) {
    spec.components = {};
  }
  if (!spec.components.schemas) {
    spec.components.schemas = {};
  }
  if (tsType.name in spec.components.schemas) {
    // Preserve user-provided definitions
    debug('    skipping type %j as already defined', tsType.name || tsType);
    return;
  }
  const jsonSchema = getJsonSchema(tsType);
  const openapiSchema = jsonToSchemaObject(jsonSchema);

  assignRelatedSchemas(spec, openapiSchema.definitions);
  delete openapiSchema.definitions;

  debug('    defining schema for %j: %j', tsType.name, openapiSchema);
  spec.components.schemas[tsType.name] = openapiSchema;
}
github strongloop / loopback-next / packages / openapi-v2 / src / controller-spec.ts View on Github external
debug(`  inferring schema object for method %s`, op);
    const paramTypes = MetadataInspector.getDesignTypeForMethod(
      constructor.prototype,
      op,
    ).parameterTypes;

    const isComplexType = (ctor: Function) =>
      !_.includes([String, Number, Boolean, Array, Object], ctor) &&
      !isReadableStream(ctor);

    for (const p of paramTypes) {
      if (isComplexType(p)) {
        if (!spec.definitions) {
          spec.definitions = {};
        }
        const jsonSchema = getJsonSchema(p);
        const openapiSchema = jsonToSchemaObject(jsonSchema);

        if (openapiSchema.definitions) {
          for (const key in openapiSchema.definitions) {
            spec.definitions[key] = openapiSchema.definitions[key];
          }
          delete openapiSchema.definitions;
        }

        spec.definitions[p.name] = openapiSchema;
        break;
      }
    }
  }
  return spec;
}
github strongloop / loopback-next / packages / openapi-v3 / src / filter-schema.ts View on Github external
export function getFilterSchemaFor(modelCtor: typeof Model): SchemaObject {
  const jsonSchema = getFilterJsonSchemaFor(modelCtor);
  const schema = jsonToSchemaObject(jsonSchema);
  return schema;
}
github strongloop / loopback-next / packages / openapi-v3 / src / controller-spec.ts View on Github external
export function getModelSchemaRef(
  modelCtor: Function & {prototype: T},
  options?: JsonSchemaOptions,
): SchemaRef {
  const jsonSchema = getJsonSchemaRef(modelCtor, options);
  return jsonToSchemaObject(jsonSchema) as SchemaRef;
}
github strongloop / loopback-next / packages / openapi-v3 / src / filter-schema.ts View on Github external
export function getWhereSchemaFor(modelCtor: typeof Model): SchemaObject {
  const jsonSchema = getWhereJsonSchemaFor(modelCtor);
  const schema = jsonToSchemaObject(jsonSchema);
  return schema;
}

@loopback/repository-json-schema

Converts TS classes into JSON Schemas using TypeScript's reflection API

MIT
Latest version published 2 days ago

Package Health Score

95 / 100
Full package analysis