Description
Is your feature request related to a problem? Please describe.
The FIWARE service paths endpoint returns alot of extra fields besides the actual paths. In particular, for each path p
there's a children
field that contains the whole service path tree starting from the last node of p
. Perhaps this is more than clients actually need. (Also, the root path will already contain the whole tree anyway.) We could return just root-to-leaf paths without including children
fields.
Note. Under the bonnet service paths are represented with a class (ServicePath
) that's a tree-like structure to encode the concept of FIWARE entity hierarchy where each node holds the name of a path component.
Describe the solution you'd like
Change the returned data format from (using simplified YAML representation instead of actual JSON)
- path: /
id: 1
children:
- path: /a
id: 2
children:
- path: /a/b
id: 3
children: []
- path: /a/c
id: 4
children: []
- path: /d
id: 5
children:
- path: /d/e
id: 6
children:
- path: /d/e/f
id: 7
children: []
- path: /d/e/g
id: 8
children: []
- path: /d/h
id: 9
children: []
- path: /a
id: 2
children:
- path: /a/b
id: 3
children: []
- path: /a/c
id: 4
children: []
- path: /a/b
id: 3
children: []
- path: /a/c
id: 4
children: []
- path: /d
id: 5
# ...and so on
# ...it goes on for a while :-)
to something simpler e.g. just list root-to-leaf paths and their IDs
- path: /a/b
id: 3
- path: /a/c
id: 4
- path: /d/e/f
id: 7
- path: /d/e/g
id: 8
- path: /d/h
id: 9
Describe alternatives you've considered
Keep the current format and document the meaning of the children
fields.
Additional context
For the record, here's the algo we designed in yesterday's session to do the job. We specified it directly in Haskell because Haskell lets you easily express maths ideas in code. Copy-paste into an online compiler, e.g.
-- canonical recursive tree structure
data Tree = N Int [Tree]
-- path type alias for clarity (a path is a sequence of nodes)
type Path = [Int]
-- example tree
t = N 1
[ N 2 [N 3 [], N 4 []]
, N 5
[ N 6 [N 7 [], N 8 []]
, N 9 []
]
]
-- extract root-to-leaf paths
paths :: Tree -> [Path]
paths (N v []) = [[v]]
paths (N v ts) = map (v:) (concatMap paths ts)
-- print t's root-to-leaf paths
result = paths t
main = mapM_ (putStrLn . show) $ result
If you run it, you'll see this output
[1,2,3]
[1,2,4]
[1,5,6,7]
[1,5,6,8]
[1,5,9]
As expected, since the program actually embodies a "proof of correctness".