Skip to content

Commit

Permalink
Anonymous identifiers for relationships (i.e. relationships not assig…
Browse files Browse the repository at this point in the history
…ned to an identifier) are excluded from the model, and therefore also excluded from the serialised JSON.
  • Loading branch information
simonbrowndotje committed Oct 5, 2024
1 parent ba57795 commit d57e6ae
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,10 @@ void registerIdentifier(String identifier, Element element) {

void registerIdentifier(String identifier, Relationship relationship) {
identifiersRegister.register(identifier, relationship);
relationship.addProperty(STRUCTURIZR_DSL_IDENTIFIER_PROPERTY_NAME, identifiersRegister.findIdentifier(relationship));

if (!StringUtils.isNullOrEmpty(identifier)) {
relationship.addProperty(STRUCTURIZR_DSL_IDENTIFIER_PROPERTY_NAME, identifiersRegister.findIdentifier(relationship));
}
}

/**
Expand Down
14 changes: 14 additions & 0 deletions structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,20 @@ void test_identifiers() throws Exception {
assertNull(impliedRelationship.getProperties().get("structurizr.dsl.identifier"));
}

@Test
void test_relationshipWithoutIdentifier() throws Exception {
StructurizrDslParser parser = new StructurizrDslParser();
parser.parse(new File("src/test/resources/dsl/relationship-without-identifier.dsl"));

Workspace workspace = parser.getWorkspace();
IdentifiersRegister register = parser.getIdentifiersRegister();
assertEquals(1, workspace.getModel().getRelationships().size());
Relationship relationship = workspace.getModel().getRelationships().iterator().next();

assertTrue(register.findIdentifier(relationship).matches("[\\w]{8}-[\\w]{4}-[\\w]{4}-[\\w]{4}-[\\w]{12}"));
assertNull(relationship.getProperties().get("structurizr.dsl.identifier")); // identifier is not included in model
}

@Test
void test_imageViews_ViaFiles() throws Exception {
StructurizrDslParser parser = new StructurizrDslParser();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
workspace {

model {
a = softwareSystem "A"
b = softwareSystem "B"
a -> b
}

}

0 comments on commit d57e6ae

Please sign in to comment.