You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/customize/code/code-regions/java.mdx
+110-3Lines changed: 110 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -33,10 +33,21 @@ Java SDK classes can have two code regions:
33
33
-`// #region imports` - allows the addition of imports to an SDK file needed for
34
34
custom methods and properties. This region must be located at the top of the
35
35
file alongside generated imports.
36
-
-`// #region sdk-class-body` - allows the addition of custom methods and
36
+
-`// #region class-body` - allows the addition of custom methods and
37
37
properties to an SDK class. This region must be located in the body of a Java
38
38
SDK class alongside generated methods and properties.
39
39
40
+
### Model classes
41
+
42
+
Java model classes can also have custom code regions:
43
+
44
+
-`// #region imports` - allows the addition of imports to a model file needed for
45
+
custom methods and properties. This region must be located at the top of the
46
+
file alongside generated imports.
47
+
-`// #region class-body` - allows the addition of custom methods and
48
+
properties to a model class. This region must be located in the body of a Java
49
+
model class alongside generated methods and properties.
50
+
40
51
## Managing dependencies
41
52
42
53
When adding custom code that requires external packages, configure these dependencies in the `.speakeasy/gen.yaml` file to prevent them from being removed during SDK regeneration. Use the `additionalDependencies` configuration to specify package dependencies:
@@ -82,7 +93,7 @@ public class Todos implements
82
93
}
83
94
84
95
// !focus(1:11)
85
-
// #region sdk-class-body
96
+
// #region class-body
86
97
public String renderTodo(String id) throws Exception {
87
98
Todo todo = getOne(id).todo()
88
99
.orElseThrow(() -> new Exception("Todo not found"));
@@ -94,11 +105,107 @@ public class Todos implements
94
105
95
106
return renderer.render(parser.parse(markdown));
96
107
}
97
-
// #endregion sdk-class-body
108
+
// #endregion class-body
98
109
99
110
public Todo getOne(String id) throws Exception {
100
111
// Generated method implementation
101
112
...
102
113
}
103
114
}
104
115
```
116
+
117
+
## Model class example
118
+
119
+
You can also add custom methods to model classes. Here's an example of adding a `render()` method to a `Todo` model class:
0 commit comments