LiveRamp / reslang

A language for describing resource-oriented APIs & turning them into Swagger or resource diagrams. Oriented around the concepts we want to expose in the APIs.
Apache License 2.0
23 stars 7 forks source link

Preserve namespace when looking for parent of a subresource #87

Closed dimatkach closed 4 years ago

dimatkach commented 4 years ago

Fixes #86

When checking rules, and looking for parents of subresource, we loose the namespace info: subresource name is namespace.Foo::Bar, but parentName is just Foo, so it fails to be found because it was loaded as namespace.Foo.

Fixing this by extracting namespace from child's name, and prepending it to parent before ascending up the hierarchy.

(It might be better to just carry the namespace with the definition rather than doing the string surgery every time, but I decided against it because it widens the impact and the scope, and resource hierarchies aren't deep anyway, so this shouldn't hurt performance too much).

liveandrew commented 4 years ago

i'll have a look early next week when i'm, back from PTO!

Andrew

On Tue, Jul 28, 2020 at 8:18 PM dimatkach notifications@github.com wrote:

@dimatkach https://github.com/dimatkach requested your review on: #87 https://github.com/LiveRamp/reslang/pull/87 Preserve namespace when looking for parent of a subresource.

— You are receiving this because your review was requested. Reply to this email directly, view it on GitHub https://github.com/LiveRamp/reslang/pull/87#event-3596858105, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMCVMOSVPV3OGNMSZCZ3V3TR552FLANCNFSM4PLCULQQ .

dimatkach commented 4 years ago

Also noticed another similar but different problem:

// In ns1: 
    import ns2
    structure Foo {}
...
//In ns2:
    import ns1
    structure Bar { foo: ns1.Foo inline }

reslang ns1 will fail with ns1.Foo not found. This is because it loads the "mainNamespace" resources without the namespace prefix, but then when looking to expand ns1.Foo, it uses the qualified name, and fails.

I added a second commit to fix this as well.

liveandrew commented 4 years ago

hey dima - i think this is covered by the recent changes i added around correct namespacing, and recursive descent into sub directories of a module. please re-open if not