Skip to content

Commit e0440dd

Browse files
Adds the ability to include single files as documentation (closes #303).
1 parent 1366d3d commit e0440dd

File tree

9 files changed

+48
-17
lines changed

9 files changed

+48
-17
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- structurizr-dsl: Adds support for element/relationship property expressions (https://github.com/structurizr/java/issues/297).
66
- structurizr-dsl: Adds a way to specify the implied relationships strategy by a fully qualified class name via `!impliedRelationships`.
7+
- structurizr-dsl: Adds the ability to include single files as documentation (https://github.com/structurizr/java/issues/303).
78

89
## 2.1.4 (18th June 2024)
910

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,13 @@ private void parse(DslContext context, Documentable documentable, File dslFile,
5555
throw new RuntimeException("Documentation path " + path + " does not exist");
5656
}
5757

58-
if (!path.isDirectory()) {
59-
throw new RuntimeException("Documentation path " + path + " is not a directory");
60-
}
61-
6258
try {
6359
Class documentationImporterClass = context.loadClass(fullyQualifiedClassName, dslFile);
6460
Constructor constructor = documentationImporterClass.getDeclaredConstructor();
6561
DocumentationImporter documentationImporter = (DocumentationImporter)constructor.newInstance();
6662
documentationImporter.importDocumentation(documentable, path);
6763

68-
if (!tokens.includes(FQN_INDEX)) {
64+
if (!tokens.includes(FQN_INDEX) && path.isDirectory()) {
6965
DefaultImageImporter imageImporter = new DefaultImageImporter();
7066
imageImporter.importDocumentation(documentable, path);
7167
}

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

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

33
import com.structurizr.Workspace;
4+
import com.structurizr.documentation.Section;
45
import com.structurizr.model.*;
56
import com.structurizr.view.*;
67
import org.junit.jupiter.api.Test;
@@ -12,6 +13,7 @@
1213
import java.nio.file.Files;
1314
import java.util.ArrayList;
1415
import java.util.Base64;
16+
import java.util.Collection;
1517
import java.util.List;
1618

1719
import static org.junit.jupiter.api.Assertions.*;
@@ -692,9 +694,34 @@ void test_docs() throws Exception {
692694
Container container = softwareSystem.getContainerWithName("Container");
693695
Component component = container.getComponentWithName("Component");
694696

695-
assertEquals(1, parser.getWorkspace().getDocumentation().getSections().size());
696-
assertEquals(1, softwareSystem.getDocumentation().getSections().size());
697-
assertEquals(1, container.getDocumentation().getSections().size());
697+
Collection<Section> sections = parser.getWorkspace().getDocumentation().getSections();
698+
assertEquals(1, sections.size());
699+
assertEquals("""
700+
## Workspace
701+
702+
Content...""", sections.iterator().next().getContent());
703+
704+
sections = softwareSystem.getDocumentation().getSections();
705+
assertEquals(1, sections.size());
706+
assertEquals("""
707+
## Software System
708+
709+
Content...""", sections.iterator().next().getContent());
710+
711+
sections = container.getDocumentation().getSections();
712+
assertEquals(1, sections.size());
713+
assertEquals("""
714+
## Container
715+
716+
Content...""", sections.iterator().next().getContent());
717+
718+
sections = component.getDocumentation().getSections();
719+
assertEquals(1, sections.size());
720+
assertEquals("""
721+
## Component
722+
723+
Content...""", sections.iterator().next().getContent());
724+
698725
assertEquals(1, component.getDocumentation().getSections().size());
699726
}
700727

structurizr-dsl/src/test/resources/dsl/docs/docs/01-context.md

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Software System
2+
3+
Content...
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Container
2+
3+
Content...
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Component
2+
3+
Content...
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Workspace
2+
3+
Content...

structurizr-dsl/src/test/resources/dsl/docs/workspace.dsl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
workspace {
22

3-
!docs docs com.structurizr.example.ExampleDocumentationImporter
3+
!docs docs/workspace com.structurizr.example.ExampleDocumentationImporter
44

55
model {
66
user = person "User"
77
softwareSystem = softwareSystem "Software System" {
8-
!docs docs
8+
!docs docs/softwaresystem
99

1010
container "Container" {
11-
!docs docs
11+
!docs docs/softwaresystem/container
1212

1313
component "Component" {
14-
!docs docs
14+
!docs docs/softwaresystem/container/component/1.md
1515
}
1616
}
1717
}

0 commit comments

Comments
 (0)