Skip to content
This repository was archived by the owner on Mar 28, 2026. It is now read-only.

Commit b507b5d

Browse files
structurizr-dsl: Adds support for url, properties, and perspectives nested inside !elements and !relationships.
1 parent b412261 commit b507b5d

14 files changed

Lines changed: 219 additions & 117 deletions

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- structurizr-dsl: Anonymous identifiers for relationships (i.e. relationships not assigned to an identifier) are excluded from the model, and therefore also excluded from the serialised JSON.
1212
- structurizr-dsl: Adds a way to configure whether the DSL source is retained via a workspace property named `structurizr.dsl.source` - `true` (default) or `false`.
1313
- structurizr-dsl: Adds the ability to define a PlantUML/Mermaid image view that is an export of a workspace view.
14+
- structurizr-dsl: Adds support for `url`, `properties`, and `perspectives` nested inside `!elements` and `!relationships`.
1415

1516
## 3.0.0 (19th September 2024)
1617

structurizr-dsl/src/main/java/com/structurizr/dsl/ElementsDslContext.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ Set<ModelItem> getModelItems() {
2727

2828
@Override
2929
protected String[] getPermittedTokens() {
30-
return new String[0];
30+
return new String[] {
31+
StructurizrDslTokens.RELATIONSHIP_TOKEN,
32+
StructurizrDslTokens.TAG_TOKEN,
33+
StructurizrDslTokens.TAGS_TOKEN,
34+
StructurizrDslTokens.URL_TOKEN,
35+
StructurizrDslTokens.PROPERTIES_TOKEN,
36+
StructurizrDslTokens.PERSPECTIVES_TOKEN
37+
};
3138
}
3239

3340
}

structurizr-dsl/src/main/java/com/structurizr/dsl/ModelItemParser.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ final class ModelItemParser extends AbstractParser {
88

99
private final static int URL_INDEX = 1;
1010

11-
private final static int PERSPECTIVE_NAME_INDEX = 0;
12-
private final static int PERSPECTIVE_DESCRIPTION_INDEX = 1;
13-
private final static int PERSPECTIVE_VALUE_INDEX = 2;
14-
1511
void parseTags(ModelItemDslContext context, Tokens tokens) {
1612
// tags <tags> [tags]
1713
if (!tokens.includes(TAGS_INDEX)) {
@@ -52,26 +48,4 @@ void parseUrl(ModelItemDslContext context, Tokens tokens) {
5248
context.getModelItem().setUrl(url);
5349
}
5450

55-
void parsePerspective(ModelItemPerspectivesDslContext context, Tokens tokens) {
56-
// <name> <description> [value]
57-
58-
if (tokens.hasMoreThan(PERSPECTIVE_VALUE_INDEX)) {
59-
throw new RuntimeException("Too many tokens, expected: <name> <description> [value]");
60-
}
61-
62-
if (!tokens.includes(PERSPECTIVE_DESCRIPTION_INDEX)) {
63-
throw new RuntimeException("Expected: <name> <description> [value]");
64-
}
65-
66-
String name = tokens.get(PERSPECTIVE_NAME_INDEX);
67-
String description = tokens.get(PERSPECTIVE_DESCRIPTION_INDEX);
68-
String value = "";
69-
70-
if (tokens.includes(PERSPECTIVE_VALUE_INDEX)) {
71-
value = tokens.get(PERSPECTIVE_VALUE_INDEX);
72-
}
73-
74-
context.getModelItem().addPerspective(name, description, value);
75-
}
76-
7751
}

structurizr-dsl/src/main/java/com/structurizr/dsl/ModelItemPerspectivesDslContext.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

structurizr-dsl/src/main/java/com/structurizr/dsl/ModelItemsParser.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
final class ModelItemsParser extends AbstractParser {
66

77
private final static int TAGS_INDEX = 1;
8+
private final static int URL_INDEX = 1;
89

910
void parseTags(ModelItemsDslContext context, Tokens tokens) {
1011
// tags <tags> [tags]
@@ -21,4 +22,20 @@ void parseTags(ModelItemsDslContext context, Tokens tokens) {
2122
}
2223
}
2324

25+
void parseUrl(ModelItemsDslContext context, Tokens tokens) {
26+
// url <url>
27+
if (tokens.hasMoreThan(URL_INDEX)) {
28+
throw new RuntimeException("Too many tokens, expected: url <url>");
29+
}
30+
31+
if (!tokens.includes(URL_INDEX)) {
32+
throw new RuntimeException("Expected: url <url>");
33+
}
34+
35+
String url = tokens.get(URL_INDEX);
36+
for (ModelItem modelItem : context.getModelItems()) {
37+
modelItem.setUrl(url);
38+
}
39+
}
40+
2441
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.structurizr.dsl;
2+
3+
import com.structurizr.model.ModelItem;
4+
5+
final class PerspectiveParser extends AbstractParser {
6+
7+
private final static int PERSPECTIVE_NAME_INDEX = 0;
8+
private final static int PERSPECTIVE_DESCRIPTION_INDEX = 1;
9+
private final static int PERSPECTIVE_VALUE_INDEX = 2;
10+
11+
void parse(PerspectivesDslContext context, Tokens tokens) {
12+
// <name> <description> [value]
13+
14+
if (tokens.hasMoreThan(PERSPECTIVE_VALUE_INDEX)) {
15+
throw new RuntimeException("Too many tokens, expected: <name> <description> [value]");
16+
}
17+
18+
if (!tokens.includes(PERSPECTIVE_DESCRIPTION_INDEX)) {
19+
throw new RuntimeException("Expected: <name> <description> [value]");
20+
}
21+
22+
String name = tokens.get(PERSPECTIVE_NAME_INDEX);
23+
String description = tokens.get(PERSPECTIVE_DESCRIPTION_INDEX);
24+
String value = "";
25+
26+
if (tokens.includes(PERSPECTIVE_VALUE_INDEX)) {
27+
value = tokens.get(PERSPECTIVE_VALUE_INDEX);
28+
}
29+
30+
for (ModelItem modelItem : context.getModelItems()) {
31+
modelItem.addPerspective(name, description, value);
32+
}
33+
}
34+
35+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.structurizr.dsl;
2+
3+
import com.structurizr.model.ModelItem;
4+
5+
import java.util.ArrayList;
6+
import java.util.Collection;
7+
8+
final class PerspectivesDslContext extends DslContext {
9+
10+
private final Collection<ModelItem> modelItems = new ArrayList<>();
11+
12+
PerspectivesDslContext(ModelItem modelItem) {
13+
this.modelItems.add(modelItem);
14+
}
15+
16+
PerspectivesDslContext(Collection<ModelItem> modelItems) {
17+
this.modelItems.addAll(modelItems);
18+
}
19+
20+
Collection<ModelItem> getModelItems() {
21+
return this.modelItems;
22+
}
23+
24+
@Override
25+
protected String[] getPermittedTokens() {
26+
return new String[0];
27+
}
28+
29+
}

structurizr-dsl/src/main/java/com/structurizr/dsl/PropertiesDslContext.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22

33
import com.structurizr.PropertyHolder;
44

5+
import java.util.ArrayList;
6+
import java.util.Collection;
7+
58
final class PropertiesDslContext extends DslContext {
69

7-
private PropertyHolder propertyHolder;
10+
private final Collection<PropertyHolder> propertyHolders = new ArrayList<>();
811

912
public PropertiesDslContext(PropertyHolder propertyHolder) {
10-
this.propertyHolder = propertyHolder;
13+
this.propertyHolders.add(propertyHolder);
14+
}
15+
16+
public PropertiesDslContext(Collection<PropertyHolder> propertyHolders) {
17+
this.propertyHolders.addAll(propertyHolders);
1118
}
1219

13-
PropertyHolder getPropertyHolder() {
14-
return this.propertyHolder;
20+
Collection<PropertyHolder> getPropertyHolders() {
21+
return this.propertyHolders;
1522
}
1623

1724
@Override

structurizr-dsl/src/main/java/com/structurizr/dsl/PropertyParser.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.structurizr.dsl;
22

3+
import com.structurizr.PropertyHolder;
4+
35
final class PropertyParser extends AbstractParser {
46

57
private final static int PROPERTY_NAME_INDEX = 0;
@@ -19,7 +21,9 @@ void parse(PropertiesDslContext context, Tokens tokens) {
1921
String name = tokens.get(PROPERTY_NAME_INDEX);
2022
String value = tokens.get(PROPERTY_VALUE_INDEX);
2123

22-
context.getPropertyHolder().addProperty(name, value);
24+
for (PropertyHolder propertyHolder : context.getPropertyHolders()) {
25+
propertyHolder.addProperty(name, value);
26+
}
2327
}
2428

2529
}

structurizr-dsl/src/main/java/com/structurizr/dsl/RelationshipsDslContext.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ Set<ModelItem> getModelItems() {
2626

2727
@Override
2828
protected String[] getPermittedTokens() {
29-
return new String[0];
29+
return new String[] {
30+
StructurizrDslTokens.TAG_TOKEN,
31+
StructurizrDslTokens.TAGS_TOKEN,
32+
StructurizrDslTokens.URL_TOKEN,
33+
StructurizrDslTokens.PROPERTIES_TOKEN,
34+
StructurizrDslTokens.PERSPECTIVES_TOKEN
35+
};
3036
}
3137

3238
}

0 commit comments

Comments
 (0)