Skip to content

Commit bae91fc

Browse files
ccolgroveryanmcnamara
authored andcommitted
Expose optional annotations in TypescriptServiceGeneratorConfiguration (#45)
* Expose optional annotations in TypescriptServiceGeneratorConfiguration * Add default optional annotations
1 parent bfa9cd4 commit bae91fc

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

typescript-service-generator-core/src/main/java/com/palantir/code/ts/generator/TypescriptServiceGeneratorConfiguration.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package com.palantir.code.ts.generator;
66

77
import java.io.File;
8+
import java.lang.annotation.Annotation;
89
import java.lang.reflect.Method;
910
import java.lang.reflect.ParameterizedType;
1011
import java.lang.reflect.Type;
@@ -15,6 +16,9 @@
1516
import java.util.Map;
1617
import java.util.Set;
1718

19+
import javax.annotation.CheckForNull;
20+
import javax.annotation.Nullable;
21+
1822
import org.immutables.value.Value;
1923

2024
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -92,7 +96,7 @@ public boolean emitDuplicateJavaMethodNames() {
9296
public boolean emitES6() {
9397
return false;
9498
}
95-
99+
96100
/**
97101
* A Java format string, expected to have exactly one %s where a generic should be placed.
98102
* Specifies what return types should look like.
@@ -111,6 +115,15 @@ public Set<Class<?>> ignoredAnnotations() {
111115
return new HashSet<>();
112116
}
113117

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+
114127
/**
115128
* The Typescript module to prefix all generated code under, for example: "MyProject.GeneratedCode"
116129
*/
@@ -201,6 +214,7 @@ public Settings getSettings() {
201214
settings.sortDeclarations = true;
202215
settings.noFileComment = true;
203216
settings.jsonLibrary = JsonLibrary.jackson2;
217+
settings.optionalAnnotations = optionalAnnotations();
204218
settings.outputKind = TypeScriptOutputKind.global;
205219
settings.outputFileType = TypeScriptFileType.implementationFile;
206220
settings.extensions = Lists.newArrayList(new EnumConstantsExtension());

0 commit comments

Comments
 (0)