structurizr / dsl

Structurizr DSL
https://docs.structurizr.com/dsl
Apache License 2.0
1.41k stars 265 forks source link

how to use a child element of a ref in a relation? #73

Closed venthur closed 3 years ago

venthur commented 3 years ago

Sorry Simon for bugging you with so many requests!

I may have found an issue with ref:

workspace {
    !identifiers hierarchical

    model {
        foo = softwareSystem "Software System Foo"
        bar = softwareSystem "Software System Bar"

        ss = ref "SoftwareSystem://Software System Foo" {
            baz = container "Container Baz"
        }

        # (1) this works
        bar -> ss.baz "some relation"

        # (2) this does not work, but shoudn't it?
        foo.baz -> bar "some other relation"
    }

    views {
        systemLandscape {
            include *
            autolayout
        }

    }
}

If I modify an existing element by using ref and add a new child element, how do i refer to that child if I want to create a relation? Should foo.baz and ss.baz work? Apparently only ss.baz works.

I'm aware that ref is still considered experimental, but maybe this is a valid issue you might want to investigate.

Edit: I've removed my comments that suspected that !includes are somehow related.

venthur commented 3 years ago

I've investigated a bit deeper, maybe this is not an issue of included files but rather a bug when you try to reference 2nd-level items and below. This is the smallest example I could find that demonstrates the issue and does not require imports:

workspace {

    !identifiers hierarchical

    model {

        foo = softwareSystem "Software System Foo" {
            baz = container "Container Baz"
        }
        bar = softwareSystem "Software System Bar"

        baz2 = ref "Container://Software System Foo.Container Baz" {
            barf = component "barf"
        }

        bar -> baz2 "some relation"

    }

    views {
        systemLandscape {
            include *
            autoLayout
        }
    }
}

The error would be:

The destination element "baz2" does not exist at line 22: bar -> baz2 "some relation"

What also does not work

bar -> foo.baz.barf "some relation"
bar -> baz2.barf "some relation"

This however does work:

bar -> foo.baz2.barf "some relation"
venthur commented 3 years ago

The latest change that allows !refs to use identifiers instead of canonical names, solves the issue for me. I think this is really an improvement, thanks!

If people start to use !refs together with !includes, they will probably experience the issue with the order of definitions and relations. So you might want to keep that issue open until it is fixed or be very specific in the documentation about the limitations of the parser (i.e. circular imports and the order of definitions).

This issue here, however, can be closed.