This repository was archived by the owner on Mar 28, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
main/java/com/structurizr/dsl Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99- structurizr-dsl: Adds ` supportingTypes implementation-suffix <suffix> ` .
1010- structurizr-dsl: Fixes https://github.com/structurizr/java/issues/346 (` // comment \ ` joins lines).
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.
12+ - 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 ` .
1213
1314## 3.0.0 (19th September 2024)
1415
Original file line number Diff line number Diff line change 1111 */
1212public class DslUtils {
1313
14- private static final String STRUCTURIZR_DSL_PROPERTY_NAME = "structurizr.dsl" ;
14+ static final String STRUCTURIZR_DSL_PROPERTY_NAME = "structurizr.dsl" ;
15+ static final String STRUCTURIZR_DSL_RETAIN_SOURCE_PROPERTY_NAME = "structurizr.dsl.source" ;
1516
1617 /**
1718 * Gets the DSL associated with a workspace.
@@ -21,13 +22,11 @@ public class DslUtils {
2122 */
2223 public static String getDsl (Workspace workspace ) {
2324 String base64 = workspace .getProperties ().get (STRUCTURIZR_DSL_PROPERTY_NAME );
24- String dsl = "" ;
25-
2625 if (!StringUtils .isNullOrEmpty (base64 )) {
27- dsl = new String (Base64 .getDecoder ().decode (base64 ));
26+ return new String (Base64 .getDecoder ().decode (base64 ));
2827 }
2928
30- return dsl ;
29+ return "" ;
3130 }
3231
3332 /**
@@ -37,12 +36,10 @@ public static String getDsl(Workspace workspace) {
3736 * @param dsl the DSL string
3837 */
3938 public static void setDsl (Workspace workspace , String dsl ) {
40- String base64 = "" ;
4139 if (!StringUtils .isNullOrEmpty (dsl )) {
42- base64 = Base64 .getEncoder ().encodeToString (dsl .getBytes (StandardCharsets .UTF_8 ));
40+ String base64 = Base64 .getEncoder ().encodeToString (dsl .getBytes (StandardCharsets .UTF_8 ));
41+ workspace .addProperty (STRUCTURIZR_DSL_PROPERTY_NAME , base64 );
4342 }
44-
45- workspace .addProperty (STRUCTURIZR_DSL_PROPERTY_NAME , base64 );
4643 }
4744
4845}
Original file line number Diff line number Diff line change @@ -101,7 +101,10 @@ public void setRestricted(boolean restricted) {
101101 */
102102 public Workspace getWorkspace () {
103103 if (workspace != null ) {
104- DslUtils .setDsl (workspace , getParsedDsl ());
104+ String value = workspace .getProperties ().get (DslUtils .STRUCTURIZR_DSL_RETAIN_SOURCE_PROPERTY_NAME );
105+ if (value == null || value .equalsIgnoreCase ("true" )) {
106+ DslUtils .setDsl (workspace , getParsedDsl ());
107+ }
105108 }
106109
107110 return workspace ;
Original file line number Diff line number Diff line change @@ -1377,4 +1377,42 @@ void test_ImageView_WhenParserIsInRestrictedMode() {
13771377 }
13781378 }
13791379
1380+ @ Test
1381+ void test_sourceIsRetained () throws Exception {
1382+ File parentDslFile = new File ("src/test/resources/dsl/source-parent.dsl" );
1383+ StructurizrDslParser parser = new StructurizrDslParser ();
1384+ parser .parse (parentDslFile );
1385+ Workspace workspace = parser .getWorkspace ();
1386+ assertEquals ("""
1387+ workspace {
1388+
1389+ model {
1390+ a = softwareSystem "A"
1391+ }
1392+
1393+ }""" , DslUtils .getDsl (workspace ));
1394+
1395+ File childDslFile = new File ("src/test/resources/dsl/source-child.dsl" );
1396+ parser = new StructurizrDslParser ();
1397+ parser .parse (childDslFile );
1398+ workspace = parser .getWorkspace ();
1399+ assertEquals ("""
1400+ workspace extends source-parent.dsl {
1401+
1402+ model {
1403+ b = softwareSystem "B"
1404+ }
1405+
1406+ }""" , DslUtils .getDsl (workspace ));
1407+ }
1408+
1409+ @ Test
1410+ void test_sourceIsNotRetained () throws Exception {
1411+ File parentDslFile = new File ("src/test/resources/dsl/source-not-retained.dsl" );
1412+ StructurizrDslParser parser = new StructurizrDslParser ();
1413+ parser .parse (parentDslFile );
1414+ Workspace workspace = parser .getWorkspace ();
1415+ assertNull (workspace .getProperties ().get (DslUtils .STRUCTURIZR_DSL_PROPERTY_NAME ));
1416+ }
1417+
13801418}
Original file line number Diff line number Diff line change 1+ workspace extends source-parent.dsl {
2+
3+ model {
4+ b = softwareSystem "B"
5+ }
6+
7+ }
Original file line number Diff line number Diff line change 1+ workspace {
2+
3+ properties {
4+ structurizr.dsl.source false
5+ }
6+
7+ model {
8+ a = softwareSystem "A"
9+ }
10+
11+ }
Original file line number Diff line number Diff line change 1+ workspace {
2+
3+ model {
4+ a = softwareSystem "A"
5+ }
6+
7+ }
You can’t perform that action at this time.
0 commit comments