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>>;
}
The app crashes with the error Cannot start the application. Error: "items" property must be present if "type" is an array
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>).
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]
_See Reporting Issues for more tips on writing good issues_
@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
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!
- [ ] Update documentation to clarify that @property.array() decorator does not support nested arrays in model properties
- [ ] Fix validation code in https://github.com/strongloop/loopback-next/blob/master/packages/repository-json-schema/src/build-schema.ts#L221 to return appropriate error when seeing a nested array.
- [ ] Add example to achieve nested arrays with json schema directly using @param() decorator
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: