How to use the @tsed/common.PropertyRegistry.getProperties function in @tsed/common

To help you get started, we’ve selected a few @tsed/common 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 TypedProject / ts-express-decorators / packages / mongoose / src / utils / createSchema.ts View on Github external
export function buildMongooseSchema(target: any): MongooseSchema {
  const properties = PropertyRegistry.getProperties(target);
  const schema: MongooseSchema = {schema: {}, virtuals: new Map()};

  if (properties) {
    const properties = PropertyRegistry.getProperties(target);

    properties.forEach((propertyMetadata, key) => {
      if (MONGOOSE_RESERVED_KEYS.includes(key as string)) {
        return;
      }

      // Keeping the Mongoose Schema separate so it can overwrite everything once schema has been built.
      const schemaTypeOptions = propertyMetadata.store.get(MONGOOSE_SCHEMA) || {};

      if (isVirtualRef(schemaTypeOptions)) {
        schemaTypeOptions.justOne = !propertyMetadata.isArray;
        schema.virtuals.set(key as string, schemaTypeOptions);

        return;
      }
github TypedProject / ts-express-decorators / packages / mongoose / src / utils / createSchema.ts View on Github external
export function buildMongooseSchema(target: any): MongooseSchema {
  const properties = PropertyRegistry.getProperties(target);
  const schema: MongooseSchema = {schema: {}, virtuals: new Map()};

  if (properties) {
    const properties = PropertyRegistry.getProperties(target);

    properties.forEach((propertyMetadata, key) => {
      if (MONGOOSE_RESERVED_KEYS.includes(key as string)) {
        return;
      }

      // Keeping the Mongoose Schema separate so it can overwrite everything once schema has been built.
      const schemaTypeOptions = propertyMetadata.store.get(MONGOOSE_SCHEMA) || {};

      if (isVirtualRef(schemaTypeOptions)) {
        schemaTypeOptions.justOne = !propertyMetadata.isArray;
        schema.virtuals.set(key as string, schemaTypeOptions);
github TypedProject / ts-express-decorators / src / swagger / class / OpenApiModelSchemaBuilder.ts View on Github external
build(): this {
    const properties = PropertyRegistry.getProperties(this.target);
    const store = Store.from(this.target);
    const schema: Schema = this.getClassSchema();
    schema.type = "object";
    schema.properties = {};

    if (store.get("description")) {
      schema.description = schema.description || store.get("description");
    }

    if (schema.required && schema.required.length) {
      this._responses[400] = {description: "Missing required parameter"};
    }

    properties.forEach((property: PropertyMetadata) => {
      const propertyKey = property.name || property.propertyKey;
      schema.properties![String(propertyKey)] = this.createSchema(property);
github TypedProject / ts-express-decorators / src / mongoose / utils / buildMongooseSchema.ts View on Github external
export function buildMongooseSchema(target: any): mongoose.SchemaDefinition {
  const properties = PropertyRegistry.getProperties(target);
  const jsonSchema: any = JsonSchemesRegistry.getSchemaDefinition(target) || {};
  const mSchema: mongoose.SchemaDefinition = {};

  if (properties) {
    properties.forEach((propertyMetadata: PropertyMetadata, propertyKey: string) => {
      if (MONGOOSE_RESERVED_KEYS.indexOf(propertyKey) > -1) {
        return;
      }

      let definition = {
        required: propertyMetadata.required
          ? function() {
              return propertyMetadata.isRequired(this[propertyKey]);
            }
          : false
      };
github TypedProject / ts-express-decorators / packages / mongoose / src / utils / buildMongooseSchema.ts View on Github external
export function buildMongooseSchema(target: any): mongoose.SchemaDefinition {
  const properties = PropertyRegistry.getProperties(target);
  const jsonSchema: any = JsonSchemesRegistry.getSchemaDefinition(target) || {};
  const mSchema: mongoose.SchemaDefinition = {};

  if (properties) {
    properties.forEach((propertyMetadata: PropertyMetadata, propertyKey: string) => {
      if (MONGOOSE_RESERVED_KEYS.indexOf(propertyKey) > -1) {
        return;
      }

      let definition = {
        required: propertyMetadata.required
          ? function() {
              return propertyMetadata.isRequired(this[propertyKey]);
            }
          : false
      };