Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defining a nested array model property using @property.array decorator crashes the app #4754

Closed
3 tasks
alyhegazy opened this issue Feb 26, 2020 · 7 comments · Fixed by #5559
Closed
3 tasks
Assignees
Labels
Milestone

Comments

@alyhegazy
Copy link

alyhegazy commented Feb 26, 2020

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

@alyhegazy alyhegazy added the bug label Feb 26, 2020
@deepakrkris
Copy link
Contributor

@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.

@deepakrkris
Copy link
Contributor

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

@alyhegazy
Copy link
Author

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

@deepakrkris deepakrkris self-assigned this Feb 27, 2020
@deepakrkris
Copy link
Contributor

deepakrkris commented Feb 27, 2020

@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.

@alyhegazy
Copy link
Author

@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?

@deepakrkris
Copy link
Contributor

@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.

@bajtos
Copy link
Member

bajtos commented Feb 28, 2020

@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 👍

@dhmlau dhmlau added the 2020Q2 label Mar 29, 2020
@dhmlau dhmlau added this to the May 2020 milestone Apr 21, 2020
@jannyHou jannyHou self-assigned this May 25, 2020
@jannyHou jannyHou mentioned this issue May 25, 2020
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants