Loopback-next: defining a nested array model property using @property.array decorator crashes the app

Created on 26 Feb 2020  ·  7Comments  ·  Source: strongloop/loopback-next

Steps to reproduce

define a nested array model property like the following

import {Model, property} from '@loopback/repository';

class testModel extends Model {
  @property.array(Array)
  nestedArr: Array<Array<string>>;
}

Current Behavior

The app crashes with the error Cannot start the application. Error: "items" property must be present if "type" is an array

Expected Behavior

The nested array property should be defined without problems. Would be nice to also allow defining the type of the nested array for example @property.array(Array<string>).

Link to reproduction sandbox

Additional information

darwin x64 10.19.0
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
└── @loopback/[email protected]

Related Issues

_See Reporting Issues for more tips on writing good issues_

Acceptance Criteria

2020Q2 bug

All 7 comments

@alyhegazy , are you extending from another model, is Model a base class you have defined ?

can you try :

import {Entity, model, property} from '@loopback/repository';

@model()
class testModel extends Entity {
  @property.array(Array)
  nestedArr: Array<Array<string>>;
}

This seems to work for me.

@alyhegazy please ignore my previous comment, I get the same error.

@deepakrkris the problem is in the property.array() decorator. If you replace @property.array(Array) with @property.array(Object) for example it works fine.

@alyhegazy we are not supporting nested arrays

https://github.com/strongloop/loopback-next/blob/master/packages/repository-json-schema/src/build-schema.ts#L221

But this is not well documented as well as the validation code above misses returning an appropriate error.

@deepakrkris should I create a feature request for supporting it? As it's very likely to have nested arrays in a schema and it seems there's no way around it. What do you think?

@alyhegazy , looks like we can achieve supporting nested arrays using json schema spec directly in @param() decorator . I am going to work on an example for this. If you are able to contribute with an example faster, that would be great as well.

@deepakrkris I checked the acceptance criteria you proposed, they look great to me!

I like that you are including a task to improve the error message reported by LoopBack to make the problem easier to understand & troubleshoot for our users :+1:

Was this page helpful?
0 / 5 - 0 ratings