From d57e6aeefe806212a795e8b5cba3c58e03fa5604 Mon Sep 17 00:00:00 2001 From: Simon Brown <1009874+simonbrowndotje@users.noreply.github.com> Date: Sat, 5 Oct 2024 12:47:35 +0100 Subject: [PATCH] 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. --- .../com/structurizr/dsl/StructurizrDslParser.java | 5 ++++- .../test/java/com/structurizr/dsl/DslTests.java | 14 ++++++++++++++ .../dsl/relationship-without-identifier.dsl | 9 +++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 structurizr-dsl/src/test/resources/dsl/relationship-without-identifier.dsl diff --git a/structurizr-dsl/src/main/java/com/structurizr/dsl/StructurizrDslParser.java b/structurizr-dsl/src/main/java/com/structurizr/dsl/StructurizrDslParser.java index a09b0cd1..dc11d521 100644 --- a/structurizr-dsl/src/main/java/com/structurizr/dsl/StructurizrDslParser.java +++ b/structurizr-dsl/src/main/java/com/structurizr/dsl/StructurizrDslParser.java @@ -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)); + } } /** diff --git a/structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java b/structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java index 7ff0184a..41c50e88 100644 --- a/structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java +++ b/structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java @@ -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(); diff --git a/structurizr-dsl/src/test/resources/dsl/relationship-without-identifier.dsl b/structurizr-dsl/src/test/resources/dsl/relationship-without-identifier.dsl new file mode 100644 index 00000000..b07a9112 --- /dev/null +++ b/structurizr-dsl/src/test/resources/dsl/relationship-without-identifier.dsl @@ -0,0 +1,9 @@ +workspace { + + model { + a = softwareSystem "A" + b = softwareSystem "B" + a -> b + } + +} \ No newline at end of file