How to use the @loopback/repository.property.array 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 / loopback4-example-shopping / packages / shopping / src / models / order.model.ts View on Github external
@property({
    type: 'string',
    id: true,
  })
  orderId?: string;

  // Each order belongs to a user, indentified by its id (userId)
  @belongsTo(() => User)
  userId: string;

  @property({
    type: 'number',
  })
  total?: number;

  @property.array(ShoppingCartItem, {required: true})
  products: ShoppingCartItem[];

  constructor(data?: Partial) {
    super(data);
  }
}
github strongloop / loopback-next / packages / repository-json-schema / src / __tests__ / integration / build-schema.integration.ts View on Github external
it('properly converts primitive array properties', () => {
        @model()
        class TestModel {
          @property.array(Number)
          numArr: number[];
        }

        const jsonSchema = modelToJsonSchema(TestModel);
        expect(jsonSchema.properties).to.deepEqual({
          numArr: {
            type: 'array',
            items: {
              type: 'number',
            },
          },
        });
        expectValidJsonSchema(jsonSchema);
      });
github strongloop / loopback-next / packages / repository-json-schema / src / __tests__ / integration / build-schema.integration.ts View on Github external
it('properly converts optional primitive array properties', () => {
        @model()
        class TestModel {
          @property.array('number')
          numArr?: number[];
        }

        const jsonSchema = modelToJsonSchema(TestModel);
        expect(jsonSchema.properties).to.deepEqual({
          numArr: {
            type: 'array',
            items: {
              type: 'number',
            },
          },
        });
        expectValidJsonSchema(jsonSchema);
      });
github strongloop / loopback-next / packages / repository-json-schema / src / __tests__ / unit / build-schema.unit.ts View on Github external
it('allows recursive model definition', () => {
      @model()
      class ReportState extends Model {
        @property.array(ReportState, {})
        states: ReportState[];

        @property({
          type: 'string',
        })
        benchmarkId?: string;

        @property({
          type: 'string',
        })
        color?: string;

        constructor(data?: Partial) {
          super(data);
        }
      }
github strongloop / loopback-next / packages / repository-json-schema / src / __tests__ / integration / build-schema.integration.ts View on Github external
it('properly converts properties with recursive arrays', () => {
        @model()
        class RecursiveArray {
          @property.array(Array)
          recArr: string[][];
        }

        const jsonSchema = modelToJsonSchema(RecursiveArray);
        expect(jsonSchema.properties).to.eql({
          recArr: {
            type: 'array',
            items: {
              type: 'array',
            },
          },
        });
      });
github strongloop / loopback-next / packages / repository-json-schema / src / __tests__ / integration / build-schema.integration.ts View on Github external
it('properly converts decorated custom array type with a resolver', () => {
          @model()
          class Address {
            @property()
            city: string;
          }

          @model()
          class TestModel {
            @property.array(() => Address)
            addresses: Address[];
          }

          const jsonSchema = modelToJsonSchema(TestModel);
          expect(jsonSchema.properties).to.deepEqual({
            addresses: {
              type: 'array',
              items: {$ref: '#/definitions/Address'},
            },
          });
          expect(jsonSchema.definitions).to.deepEqual({
            Address: {
              title: 'Address',
              properties: {
                city: {
                  type: 'string',
github strongloop / loopback-next / packages / repository-json-schema / src / __tests__ / integration / build-schema.integration.ts View on Github external
it('creates definitions only at the root level of the schema', () => {
          @model()
          class CustomTypeFoo {
            @property()
            prop: string;
          }

          @model()
          class CustomTypeBar {
            @property.array(CustomTypeFoo)
            prop: CustomTypeFoo[];
          }

          @model()
          class TestModel {
            @property()
            cusBar: CustomTypeBar;
          }

          const jsonSchema = modelToJsonSchema(TestModel);
          const schemaProps = jsonSchema.properties;
          const schemaDefs = jsonSchema.definitions;
          expect(schemaProps).to.deepEqual({
            cusBar: {
              $ref: '#/definitions/CustomTypeBar',
            },
github strongloop / loopback4-example-shopping / packages / shopping / src / models / shopping-cart.model.ts View on Github external
import {Entity, model, property, belongsTo} from '@loopback/repository';
import {ShoppingCartItem} from './shopping-cart-item.model';
import {User} from './user.model';

@model()
export class ShoppingCart extends Entity {
  /**
   * Each shopping cart belongs to a user, indentified by its id (userId)
   */
  @belongsTo(() => User)
  userId: string;

  /**
   * Items in the shopping cart
   */
  @property.array(ShoppingCartItem)
  items?: ShoppingCartItem[];

  constructor(data?: Partial) {
    super(data);
  }
}
github gobackhuoxing / first-web-game-lb4 / firstgame / src / models / character.model.ts View on Github external
@model()
export class Character extends Entity {
  @property({
    type: 'string',
    id: true,
    required: true,
  })
  email?: string;

  @property({
    type: 'string',
    required: true,
  })
  password: string;

  @property.array(String)
  permissions: String[];

  @property({
    type: 'string',
    required: true,
  })
  name: string;

  @property({
    type: 'number',
    default: 1,
  })
  level?: number;

  @property({
    type: 'number',
github johnwalicki / IoT-AssetTracking-Perishable-Network-Blockchain / Blockchain / web-app / app / src / models / response-message.model.ts View on Github external
import { model, property, AnyType } from '@loopback/repository';

@model({ name: 'ResponseMessage' })
//the red squiggly is OK here :)
export class ResponseMessage {

  constructor(data?: Partial) {
    if (data != null && typeof data === 'object') {
      Object.assign(this, data);
    }
  }

  @property({ name: 'message', required: true })
  message: string = 'OK';

  @property.array(AnyType, { name: 'objectlist', required: false })
  objectlist: any[] = [];

  @property({ name: 'statusCode', required: true })
  statusCode: string = '200';
}