5
5
package com .palantir .code .ts .generator ;
6
6
7
7
import java .io .File ;
8
+ import java .lang .annotation .Annotation ;
8
9
import java .lang .reflect .Method ;
9
10
import java .lang .reflect .ParameterizedType ;
10
11
import java .lang .reflect .Type ;
15
16
import java .util .Map ;
16
17
import java .util .Set ;
17
18
19
+ import javax .annotation .CheckForNull ;
20
+ import javax .annotation .Nullable ;
21
+
18
22
import org .immutables .value .Value ;
19
23
20
24
import com .fasterxml .jackson .databind .annotation .JsonDeserialize ;
@@ -92,7 +96,7 @@ public boolean emitDuplicateJavaMethodNames() {
92
96
public boolean emitES6 () {
93
97
return false ;
94
98
}
95
-
99
+
96
100
/**
97
101
* A Java format string, expected to have exactly one %s where a generic should be placed.
98
102
* Specifies what return types should look like.
@@ -111,6 +115,15 @@ public Set<Class<?>> ignoredAnnotations() {
111
115
return new HashSet <>();
112
116
}
113
117
118
+ /**
119
+ * A list of annotations that will generate fields as optional in the typescript definitions.
120
+ */
121
+ @ Value .Default
122
+ @ SuppressWarnings ("unchecked" )
123
+ public List <Class <? extends Annotation >> optionalAnnotations () {
124
+ return Lists .newArrayList (CheckForNull .class , Nullable .class );
125
+ }
126
+
114
127
/**
115
128
* The Typescript module to prefix all generated code under, for example: "MyProject.GeneratedCode"
116
129
*/
@@ -201,6 +214,7 @@ public Settings getSettings() {
201
214
settings .sortDeclarations = true ;
202
215
settings .noFileComment = true ;
203
216
settings .jsonLibrary = JsonLibrary .jackson2 ;
217
+ settings .optionalAnnotations = optionalAnnotations ();
204
218
settings .outputKind = TypeScriptOutputKind .global ;
205
219
settings .outputFileType = TypeScriptFileType .implementationFile ;
206
220
settings .extensions = Lists .newArrayList (new EnumConstantsExtension ());
0 commit comments