namespace with slashes in the name

+1 vote
asked Dec 16, 2022 in Question / help by jpablo (120 points)

Hi, I'm interested in creating a class diagram with namespaces having slashes (instead of dots) in the name, something like this:

@startuml
set namespaceSeparator none
namespace "a.b.c" as a/b/c {
   class "Object" as js/Object#
}
@enduml

This is a syntax error due do the namespace having slashes ("a/b/c" instead of "a.b.c"). Is there a way to use slashes in the namespace name?

commented Jan 12, 2023 by BenceSzalai (200 points)

To me it doesn't look like an issue with the separators.

To test that try this one: same code but with default separators:

@startuml
namespace a.b.c {
   class js.Object#
}
@enduml

I think it doesn't do what you expect either. It declares a namespace called a.b.c and declares a namespace called js with Object# inside it.

There are two issues here:

  • You cannot use relative sub-path names inside a namespace when declaring elements. By this I mean class some/path/to/Name inside a namespace is not going to be understood as being inside the namespace but as a declaration with a fully qualified name, and as such the some/path/to part is not going to be prepended to the path of the namespace, it will be understood as stemming from the root. The workaround is easy: Once using packages, make them explicit at each level. This relates to the other issue:
  • PlantUML does not process namespace names for namespace separators to parse multiple levels of namespaces from a single namespace block and declaration. So namespace a.b.c { ... } is not going to declare a namespace called c inside one called b inside one called a, but it will declare a namespace called a.b.c. This is an issue reported here. The workaround is the same: declare each namespace level as a separate block.

See workaround in action here. Same with / as separator here. Notice how the separator has no effect on your issue. Only the way namespaces are nested do matter.

I also think adding an alias to a namespace the way you did has no purpose right now, as when doing "title" as alias it would mean to display the item as title but refer to it in the code as alias. However until the linked issue is fixed you will not be able to effectively declare multiple levels of namespaces in using a single namespace statement (i.e. no separators in the alias), so the namespace separators would never really appear on the drawing, only in your code, because when all those nested namespaces are drawn as nested boxes, the separator itself is represented as the boundary of the box and is not shown as any character, nor a dot nor slash or anything else.

2 Answers

+1 vote
answered Dec 16, 2022 by The-Lu (63,920 points)

Hello J., and all,

Here are some examples:

@startuml

set namespaceSeparator /

class "a.b.c" as a/b/c {
  class "Object" as js/Object#
}

@enduml

VS

@startuml

set namespaceSeparator /

package "a.b.c" as a/b/c {
  class "Object" as js/Object#
}

@enduml

VS

@startuml

set namespaceSeparator /

package a/b/c {
  class "Object" as js/Object#
}

@enduml

It seems there are some defect or issue....
Regards.
Th.

0 votes
answered Jan 10, 2023 by plantuml (294,960 points)

This has been improved in V1.2023.0, but I'm not sure this is completely fixed.

For example, you can have now:

@startuml
set namespaceSeparator /
class "Object" as js/Object
@enduml
commented Jan 11, 2023 by BenceSzalai (200 points)

What would the "Object" as part do in this case?

Afaics this means and results in the same:

@startuml
set namespaceSeparator /
class js/Object
@enduml
...