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

Commit d57e6ae

Browse files
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.
1 parent ba57795 commit d57e6ae

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,10 @@ void registerIdentifier(String identifier, Element element) {
11811181

11821182
void registerIdentifier(String identifier, Relationship relationship) {
11831183
identifiersRegister.register(identifier, relationship);
1184-
relationship.addProperty(STRUCTURIZR_DSL_IDENTIFIER_PROPERTY_NAME, identifiersRegister.findIdentifier(relationship));
1184+
1185+
if (!StringUtils.isNullOrEmpty(identifier)) {
1186+
relationship.addProperty(STRUCTURIZR_DSL_IDENTIFIER_PROPERTY_NAME, identifiersRegister.findIdentifier(relationship));
1187+
}
11851188
}
11861189

11871190
/**

structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,20 @@ void test_identifiers() throws Exception {
10071007
assertNull(impliedRelationship.getProperties().get("structurizr.dsl.identifier"));
10081008
}
10091009

1010+
@Test
1011+
void test_relationshipWithoutIdentifier() throws Exception {
1012+
StructurizrDslParser parser = new StructurizrDslParser();
1013+
parser.parse(new File("src/test/resources/dsl/relationship-without-identifier.dsl"));
1014+
1015+
Workspace workspace = parser.getWorkspace();
1016+
IdentifiersRegister register = parser.getIdentifiersRegister();
1017+
assertEquals(1, workspace.getModel().getRelationships().size());
1018+
Relationship relationship = workspace.getModel().getRelationships().iterator().next();
1019+
1020+
assertTrue(register.findIdentifier(relationship).matches("[\\w]{8}-[\\w]{4}-[\\w]{4}-[\\w]{4}-[\\w]{12}"));
1021+
assertNull(relationship.getProperties().get("structurizr.dsl.identifier")); // identifier is not included in model
1022+
}
1023+
10101024
@Test
10111025
void test_imageViews_ViaFiles() throws Exception {
10121026
StructurizrDslParser parser = new StructurizrDslParser();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
workspace {
2+
3+
model {
4+
a = softwareSystem "A"
5+
b = softwareSystem "B"
6+
a -> b
7+
}
8+
9+
}

0 commit comments

Comments
 (0)