-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Hello there.
Describe the bug
There is an issue with sap.ui.model.json.TypedJSONModel if recursive types are used.
Let's say we have something like this:
import TypedJSONModel from "sap/ui/model/json/TypedJSONModel";
type OrderItems = {
OrderId: string;
Id: string;
to_Order?: Order;
};
type Order = {
Id: string;
to_OrderItems?: { results: OrderItems[] };
};
/**
* @namespace xxx
*/
export default class TestJSONModel extends TypedJSONModel<typeof TestJSONModel._mInitialData> {
private static readonly _mInitialData = {
Orders: [] as Order[]
};
test() {
// errors here
const value = this.getProperty("/Orders/0/to_OrderItems/results");
}
}We get errors:

Which does make sense, of course, but it makes this model unusable for types generated for OData Entities, because they can be indeed recursive.
The example above demonstrates that. So, we have an Order, which can have OrderItem[], and OrderItem may have Order. It goes into recursive and kills the types.
Expected behavior
There should be a possibility to use types, even if they are recursive.
I actually had developed typed JSONModel by myself couple of years ago, and I solved this issue by adding Depth, which sets the max number of inner properties to be accessible.
Let's say we have /Orders/0/to_OrderItems/results as in example above. The depth here would be 4.
/ -> Depth 0
/Orders -> Depth 1
/Orders/0 -> Depth 2
etc.
So I would propose to have that in the TypedJSONModel.
If there are better ideas - would be nice hear them out.