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

Simplified service paths format #223

Open
c0c0n3 opened this issue Apr 21, 2023 · 1 comment
Open

Simplified service paths format #223

c0c0n3 opened this issue Apr 21, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@c0c0n3
Copy link
Member

c0c0n3 commented Apr 21, 2023

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

@c0c0n3 c0c0n3 added the enhancement New feature or request label Apr 21, 2023
@c0c0n3
Copy link
Member Author

c0c0n3 commented Apr 24, 2023

Keep in mind that as @Cerfoglg pointed out, this isn't really an issue when retrieving service paths individually since there's only one children field in that case and nodes won't be repeated. See also: #221.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants